Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTDevice profiling support #9

Open
wants to merge 1 commit into
base: synced_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion capture/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ set(PROGRAM_FILES
)

add_executable(${PROJECT_NAME} ${PROGRAM_FILES} ${COMMON_FILES} ${SERVER_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt)
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt pthread)
set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
2 changes: 1 addition & 1 deletion csvexport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ set(PROGRAM_FILES
)

add_executable(${PROJECT_NAME} ${PROGRAM_FILES} ${COMMON_FILES} ${SERVER_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt)
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyGetOpt pthread)
set_property(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
172 changes: 161 additions & 11 deletions csvexport/src/csvexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ void print_usage_exit(int e)
fprintf(stderr, "\n");
fprintf(stderr, " -h, --help Print usage\n");
fprintf(stderr, " -f, --filter arg Filter zone names (default: "")\n");
fprintf(stderr, " -x arg List of special functions delimited by comma (default: "")\n");
fprintf(stderr, " -p arg Parent to find for special functions (default: "")\n");
fprintf(stderr, " -s, --sep arg CSV separator (default: ,)\n");
fprintf(stderr, " -c, --case Case sensitive filtering\n");
fprintf(stderr, " -e, --self Get self times\n");
Expand All @@ -38,6 +40,8 @@ struct Args {
const char* filter;
const char* separator;
const char* trace_file;
const char* special_functions;
const char* special_parent_function;
bool case_sensitive;
bool self_time;
bool unwrap;
Expand All @@ -51,7 +55,7 @@ Args parse_args(int argc, char** argv)
print_usage_exit(1);
}

Args args = { "", ",", "", false, false, false, false };
Args args = { "", ",", "", "", "", false, false, false, false };

struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' },
Expand All @@ -61,11 +65,13 @@ Args parse_args(int argc, char** argv)
{ "self", no_argument, NULL, 'e' },
{ "unwrap", no_argument, NULL, 'u' },
{ "messages", no_argument, NULL, 'm' },
{ "special_functions", no_argument, NULL, 'x' },
{ "special_parent_function", no_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 }
};

int c;
while ((c = getopt_long(argc, argv, "hf:s:ceum", long_opts, NULL)) != -1)
while ((c = getopt_long(argc, argv, "hf:p:x:s:ceum", long_opts, NULL)) != -1)
{
switch (c)
{
Expand All @@ -78,6 +84,12 @@ Args parse_args(int argc, char** argv)
case 's':
args.separator = optarg;
break;
case 'p':
args.special_parent_function = optarg;
break;
case 'x':
args.special_functions = optarg;
break;
case 'c':
args.case_sensitive = true;
break;
Expand Down Expand Up @@ -151,6 +163,60 @@ std::string join(const T& v, const char* sep) {
return s.str();
}

//From TracyView_Utility.cpp
const tracy::ZoneEvent* GetZoneParent(const tracy::Worker& worker, const tracy::ZoneEvent& zone, uint64_t tid )
{
const auto& thread = worker.GetThreadData(tid);
if( thread == nullptr )
{
return nullptr;
}
const tracy::ZoneEvent* parent = nullptr;
const tracy::Vector<tracy::short_ptr<tracy::ZoneEvent>>* timeline = &thread->timeline;
if( timeline == nullptr || timeline->empty() ) return nullptr;
for(;;)
{
if( timeline->is_magic() )
{
auto vec = (tracy::Vector<tracy::ZoneEvent>*)timeline;
auto it = std::upper_bound( vec->begin(), vec->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r.Start(); } );
if( it != vec->begin() ) --it;
if( zone.IsEndValid() && it->Start() > zone.End() ) break;
if( it == &zone ) return parent;
if( !it->HasChildren() ) break;
parent = it;
timeline = &worker.GetZoneChildren( parent->Child() );
}
else
{
auto it = std::upper_bound( timeline->begin(), timeline->end(), zone.Start(), [] ( const auto& l, const auto& r ) { return l < r->Start(); } );
if( it != timeline->begin() ) --it;
if( zone.IsEndValid() && (*it)->Start() > zone.End() ) break;
if( *it == &zone ) return parent;
if( !(*it)->HasChildren() ) break;
parent = *it;
timeline = &worker.GetZoneChildren( parent->Child() );
}
}
return nullptr;
}

const tracy::ZoneEvent* GetSpecialParent(const tracy::Worker& worker, const tracy::ZoneEvent& zone_event, uint64_t tid, std::string& functionName)
{
const auto parent_zone_event = GetZoneParent(worker, zone_event, tid);
if (parent_zone_event != nullptr)
{
std::string parent_zone_name = get_name(parent_zone_event->SrcLoc(), worker);
std::string parent_zone_text = "";
if (parent_zone_name.find(functionName) != std::string::npos)
{
return parent_zone_event;
}
return GetSpecialParent(worker, *parent_zone_event, tid, functionName);
}
return nullptr;
}

// From TracyView.cpp
int64_t GetZoneChildTimeFast(
const tracy::Worker& worker,
Expand Down Expand Up @@ -204,10 +270,10 @@ int main(int argc, char** argv)

auto worker = tracy::Worker(*f);

if (args.unwrapMessages)
if (args.unwrapMessages)
{
const auto& msgs = worker.GetMessages();

if (msgs.size() > 0)
{
std::vector<const char*> columnsForMessages;
Expand All @@ -232,7 +298,7 @@ int main(int argc, char** argv)
{
printf("There are currently no messages!\n");
}

return 0;
}

Expand All @@ -242,8 +308,11 @@ int main(int argc, char** argv)
}

auto& slz = worker.GetSourceLocationZones();
auto& slzg = worker.GetGpuSourceLocationZones();
tracy::Vector<decltype(slz.begin())> slz_selected;
tracy::Vector<decltype(slzg.begin())> slzg_selected;
slz_selected.reserve(slz.size());
slzg_selected.reserve(slzg.size());

uint32_t total_cnt = 0;
for(auto it = slz.begin(); it != slz.end(); ++it)
Expand All @@ -266,11 +335,27 @@ int main(int argc, char** argv)
}
}

std::vector<const char*> columns;
std::vector<std::string> specialFunctions = {};
std::string specialParent = args.special_parent_function;
if (specialParent.size() > 0)
{
size_t pos = 0;
std::string token;
std::string delimiter = ",";
std::string functionsStr = args.special_functions;
while ((pos = functionsStr.find(delimiter)) != std::string::npos) {
token = functionsStr.substr(0, pos);
specialFunctions.push_back(token);
functionsStr.erase(0, pos + delimiter.length());
}
specialFunctions.push_back(functionsStr);
}

std::vector<std::string> columns;
if (args.unwrap)
{
columns = {
"name", "src_file", "src_line", "ns_since_start", "exec_time_ns", "thread"
"name", "src_file", "src_line", "zone_name", "zone_text", "ns_since_start", "exec_time_ns", "thread", "special_parent_text"
};
}
else
Expand Down Expand Up @@ -298,22 +383,53 @@ int main(int argc, char** argv)

if (args.unwrap)
{
int i = 0;
for (const auto& zone_thread_data : zone_data.zones) {
const auto zone_event = zone_thread_data.Zone();
const auto tId = zone_thread_data.Thread();

if (worker.HasZoneExtra(*zone_event))
{
auto extra = worker.GetZoneExtra(*zone_event);
if (extra.name.Active())
{
values[3] = worker.GetString(extra.name);
}
if (extra.text.Active())
{
values[4] = "\"" + (std::string)worker.GetString(extra.text) + "\"";
}
}

const auto start = zone_event->Start();
const auto end = zone_event->End();

values[3] = std::to_string(start);
values[5] = std::to_string(start);

auto timespan = end - start;
if (args.self_time) {
timespan -= GetZoneChildTimeFast(worker, *zone_event);
}
values[4] = std::to_string(timespan);
values[5] = std::to_string(tId);
values[6] = std::to_string(timespan);
values[7] = std::to_string(tId);

for (auto& function: specialFunctions)
{
if (function == values[0])
{
const auto special_parent_zone_event = GetSpecialParent(worker, *zone_event, worker.DecompressThread(tId), specialParent);
if (special_parent_zone_event != nullptr)
{
if (worker.HasZoneExtra(*special_parent_zone_event))
{
auto extra = worker.GetZoneExtra(*special_parent_zone_event);
if (extra.text.Active())
{
values[8] = worker.GetString(extra.text);
}
}
}
}
}
std::string row = join(values, args.separator);
printf("%s\n", row.data());
}
Expand Down Expand Up @@ -349,5 +465,39 @@ int main(int argc, char** argv)
}
}

for(auto& it : slzg_selected)
{
std::vector<std::string> values(columns.size());

values[0] = get_name(it->first, worker);

const auto& srcloc = worker.GetSourceLocation(it->first);
values[1] = worker.GetString(srcloc.file);
values[2] = std::to_string(srcloc.line);

const auto& zone_data = it->second;

if (args.unwrap)
{
int i = 0;
for (const auto& zone_thread_data : zone_data.zones) {
const auto zone_event = zone_thread_data.Zone();
const auto tId = zone_thread_data.Thread();

const auto start = zone_event->GpuStart();
const auto end = zone_event->GpuEnd();

values[5] = std::to_string(start);

auto timespan = end - start;

values[6] = std::to_string(timespan);
values[7] = std::to_string(tId);

std::string row = join(values, args.separator);
printf("%s\n", row.data());
}
}
}
return 0;
}
3 changes: 2 additions & 1 deletion profiler/src/profiler/TracyView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ constexpr const char* GpuContextNames[] = {
"Vulkan",
"OpenCL",
"Direct3D 12",
"Direct3D 11"
"Direct3D 11",
"TT Device"
};

struct MemoryPage;
Expand Down
41 changes: 24 additions & 17 deletions profiler/src/profiler/TracyView_GpuTimeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "TracyPrint.hpp"
#include "TracyTimelineContext.hpp"
#include "TracyView.hpp"
#include "../public/common/TracyTTDeviceData.hpp"

namespace tracy
{
Expand Down Expand Up @@ -32,10 +33,22 @@ bool View::DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offs

const auto singleThread = gpu.threadData.size() == 1;
int depth = 0;
constexpr int threadNameSize = 30;
char buf[threadNameSize];

Vector<uint64_t> tds;
for( auto& td : gpu.threadData )
{
auto& tl = td.second.timeline;
tds.push_back(td.first);
}
std::sort (tds.begin(), tds.end());

for( auto& tn : tds)
{
auto & td = gpu.threadData.at(tn);
TTDeviceEvent event = TTDeviceEvent (tn);
snprintf(buf, threadNameSize, "%s", riscName[event.risc].c_str());
auto& tl = td.timeline;
assert( !tl.empty() );
if( tl.is_magic() )
{
Expand All @@ -44,17 +57,14 @@ bool View::DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offs
{
const auto begin = tlm.front().GpuStart();
const auto drift = GpuDrift( &gpu );
if( !singleThread ) offset += sstep;
offset += sstep;
const auto partDepth = DispatchGpuZoneLevel( tl, hover, pxns, int64_t( nspx ), wpos, offset, 0, gpu.thread, yMin, yMax, begin, drift );
if( partDepth != 0 )
{
if( !singleThread )
{
ImGui::PushFont( m_smallFont );
DrawTextContrast( draw, wpos + ImVec2( ty, offset-1-sstep ), 0xFFFFAAAA, m_worker.GetThreadName( td.first ) );
DrawLine( draw, dpos + ImVec2( 0, offset+sty-sstep ), dpos + ImVec2( w, offset+sty-sstep ), 0x22FFAAAA );
ImGui::PopFont();
}
ImGui::PushFont( m_smallFont );
DrawTextContrast( draw, wpos + ImVec2( ty, offset-1-sstep ), 0xFFFFAAAA, buf );
DrawLine( draw, dpos + ImVec2( 0, offset+sty-sstep ), dpos + ImVec2( w, offset+sty-sstep ), 0x22FFAAAA );
ImGui::PopFont();

offset += ostep * partDepth;
depth += partDepth;
Expand All @@ -71,17 +81,14 @@ bool View::DrawGpu( const TimelineContext& ctx, const GpuCtxData& gpu, int& offs
{
const auto begin = tl.front()->GpuStart();
const auto drift = GpuDrift( &gpu );
if( !singleThread ) offset += sstep;
offset += sstep;
const auto partDepth = DispatchGpuZoneLevel( tl, hover, pxns, int64_t( nspx ), wpos, offset, 0, gpu.thread, yMin, yMax, begin, drift );
if( partDepth != 0 )
{
if( !singleThread )
{
ImGui::PushFont( m_smallFont );
DrawTextContrast( draw, wpos + ImVec2( ty, offset-1-sstep ), 0xFFFFAAAA, m_worker.GetThreadName( td.first ) );
DrawLine( draw, dpos + ImVec2( 0, offset+sty-sstep ), dpos + ImVec2( w, offset+sty-sstep ), 0x22FFAAAA );
ImGui::PopFont();
}
ImGui::PushFont( m_smallFont );
DrawTextContrast( draw, wpos + ImVec2( ty, offset-1-sstep ), 0xFFFFAAAA, buf );
DrawLine( draw, dpos + ImVec2( 0, offset+sty-sstep ), dpos + ImVec2( w, offset+sty-sstep ), 0x22FFAAAA );
ImGui::PopFont();

offset += ostep * partDepth;
depth += partDepth;
Expand Down
Loading