Skip to content

Commit

Permalink
Isolate flushing instructions for metrics
Browse files Browse the repository at this point in the history
Isolated flushing instructions into a wrapping function. The file descriptor used for flushing is the one that is globally defined and not the one stored in the context_entry_t object as it is always the one that is defined globally that is used. If using a globally defined file descriptor is problematic (however it is the norm in the libtracer_tool.so library in ROCTracer) rather than passing it through arguments, the wrapping flushing function can be modified to take a void pointer. The file descriptor can then be passed through this pointer and be used in the default flushing function.
  • Loading branch information
yoann-heitz committed Sep 22, 2021
1 parent 125e1b1 commit 2b0aab5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions test/tool/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,21 @@ unsigned align_size(unsigned size, unsigned alignment) {
return ((size + alignment - 1) & ~(alignment - 1));
}

void metric_flush_cb(const char *name, uint64_t result){
fprintf(result_file_handle, " %s ", name);
fprintf(result_file_handle, "(%lu)\n", result);
}
// Output profiling results for input features
void output_results(const context_entry_t* entry, const char* label) {
FILE* file = entry->file_handle;
const rocprofiler_feature_t* features = entry->features;
const unsigned feature_count = entry->feature_count;

for (unsigned i = 0; i < feature_count; ++i) {
const rocprofiler_feature_t* p = &features[i];
fprintf(file, " %s ", p->name);
switch (p->data.kind) {
// Output metrics results
case ROCPROFILER_DATA_KIND_INT64:
fprintf(file, "(%lu)\n", p->data.result_int64);
metric_flush_cb(p->name, p->data.result_int64);
break;
default:
fprintf(stderr, "RPL-tool: undefined data kind(%u)\n", p->data.kind);
Expand Down

0 comments on commit 2b0aab5

Please sign in to comment.