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

Export gpu zones to csv file #975

Merged
merged 3 commits into from
Jan 23, 2025
Merged
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
74 changes: 71 additions & 3 deletions csvexport/src/csvexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void print_usage_exit(int e)
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");
fprintf(stderr, " -u, --unwrap Report each zone event\n");
fprintf(stderr, " -u, --unwrap Report each cpu zone event\n");
fprintf(stderr, " -g, --gpu Report each gpu zone event\n" );
fprintf(stderr, " -m, --messages Report only messages\n");
fprintf(stderr, " -p, --plot Report plot data (only with -u)\n");

Expand All @@ -42,6 +43,7 @@ struct Args {
bool case_sensitive;
bool self_time;
bool unwrap;
bool show_gpu;
bool unwrapMessages;
bool plot;
};
Expand All @@ -53,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, false, false };

struct option long_opts[] = {
{ "help", no_argument, NULL, 'h' },
Expand All @@ -62,13 +64,14 @@ Args parse_args(int argc, char** argv)
{ "case", no_argument, NULL, 'c' },
{ "self", no_argument, NULL, 'e' },
{ "unwrap", no_argument, NULL, 'u' },
{ "gpu", no_argument, NULL, 'g' },
{ "messages", no_argument, NULL, 'm' },
{ "plot", no_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 }
};

int c;
while ((c = getopt_long(argc, argv, "hf:s:ceump", long_opts, NULL)) != -1)
while ((c = getopt_long(argc, argv, "hf:s:ceugmp", long_opts, NULL)) != -1)
{
switch (c)
{
Expand All @@ -90,6 +93,9 @@ Args parse_args(int argc, char** argv)
case 'u':
args.unwrap = true;
break;
case 'g':
args.show_gpu = true;
break;
case 'm':
args.unwrapMessages = true;
break;
Expand Down Expand Up @@ -247,6 +253,68 @@ int main(int argc, char** argv)
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}

if (args.show_gpu)
{
auto& gpu_slz = worker.GetGpuSourceLocationZones();
tracy::Vector<decltype( gpu_slz.begin() )> gpu_slz_selected;
gpu_slz_selected.reserve( gpu_slz.size() );

uint32_t total_cnt = 0;
for (auto it = gpu_slz.begin(); it != gpu_slz.end(); ++it)
{
if (it->second.total != 0)
{
++total_cnt;
if (args.filter[0] == '\0')
{
gpu_slz_selected.push_back_no_space_check( it );
}
else
{
auto name = get_name( it->first, worker );
if (is_substring( args.filter, name, args.case_sensitive))
{
gpu_slz_selected.push_back_no_space_check( it );
}
}
}
}

std::vector<const char*> columns;
columns = {"name", "src_file", "Time from start of program", "GPU execution time"};

std::string header = join(columns, args.separator);
printf("%s\n", header.data());

const auto last_time = worker.GetLastTime();
for (auto& it : gpu_slz_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 );

const auto& zone_data = it->second;
for (const auto& zone_thread_data : zone_data.zones)
{
tracy::GpuEvent* gpu_event = zone_thread_data.Zone();
const auto start = gpu_event->GpuStart();
const auto end = gpu_event->GpuEnd();

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

auto timespan = end - start;
values[3] = std::to_string( timespan );

std::string row = join( values, args.separator );
printf( "%s\n", row.data() );
}
}
return 0;
}

auto& slz = worker.GetSourceLocationZones();
tracy::Vector<decltype(slz.begin())> slz_selected;
slz_selected.reserve(slz.size());
Expand Down
Loading