-
Notifications
You must be signed in to change notification settings - Fork 879
Microprofiler can now output logs for benchmarks in the csv format. #1290
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
Conversation
#endif | ||
} | ||
|
||
int MicroProfiler::FindExistingOrNextPosition(const char* tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we have some comments on what this function does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion Pauline! Adding a descriptive comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
high level comment is that it might be worth implementing a generic Map class that is embedded friendly and then use that to perform the computation that we are doing to get to the total ticks per tag.
// Prints the profiling information of each of the tags in CSV (Comma | ||
// Separated Value) form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should expand this description.
Something like:
// Prints total ticks for each unique tag in CSV format.
//
// Output will have one row for each unique tag along with the total ticks summed across all events with that particular tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for the suggestion!
@@ -72,6 +76,14 @@ class MicroProfiler { | |||
uint32_t end_ticks_[kMaxEvents]; | |||
int num_events_ = 0; | |||
|
|||
struct ticks_per_tag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename: TicksPerTag
https://google.github.io/styleguide/cppguide.html#Type_Names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the link! Really helpful.
const char* tag; | ||
uint32_t ticks; | ||
}; | ||
ticks_per_tag total_ticks_per_tag[kMaxEvents]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment that in practice the number of unique tags will be less than the number of events but it is theoretically possible for each event to be unique and hence we allow for the TicksPerTag array to have kMaxEvents entrires.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the suggestion!
}; | ||
ticks_per_tag total_ticks_per_tag[kMaxEvents]; | ||
|
||
int FindExistingOrNextPosition(const char* tagName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a comment about what this function does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the suggestion!
}; | ||
ticks_per_tag total_ticks_per_tag[kMaxEvents]; | ||
|
||
int FindExistingOrNextPosition(const char* tagName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tagName -> tag_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the suggestion!
void MicroProfiler::LogTicksPerTagCsv() { | ||
#if !defined(TF_LITE_STRIP_ERROR_STRINGS) | ||
MicroPrintf( | ||
"\"Unique Ops in the Graph\",\"Total Ticks (all instances of the Op)\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: technically may not be Ops. It could be any event that we profile with the MicroProfiler.
Unique Tag, Total ticks across all events with that tag.
#if !defined(TF_LITE_STRIP_ERROR_STRINGS) | ||
MicroPrintf( | ||
"\"Unique Ops in the Graph\",\"Total Ticks (all instances of the Op)\""); | ||
int totalTicks = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total_ticks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thank you for the suggestion!
} | ||
MicroPrintf("%s,%d", ticksPerTag.tag, ticksPerTag.ticks); | ||
} | ||
MicroPrintf("total,%d", totalTicks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to not strictly be a part of the csv format. I would say skip from the current function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I was thinking to print the total count as well as I have seen that this is required for the calculation but if you think that is not required, I can remove it. I can probably change it to "total number of ticks" or something like that to make it more meaningful.
#endif | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: let's use // for the comment style for consistency.
https://google.github.io/styleguide/cppguide.html#Comment_Style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion.
const char* currentTagName_t = each_tag_entry.tag; | ||
const char* newTagName_t = tag_name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_tag_name
new_tag_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
bool matched = true; | ||
while ((*currentTagName_t != '\0') && (*newTagName_t != '\0')) { | ||
if (((*currentTagName_t) == (*newTagName_t))) { | ||
++currentTagName_t; | ||
++newTagName_t; | ||
} else { | ||
matched = false; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use strcmp instead of this custom loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not aware of if strcmp is available in tflm Thank you for the suggestion.
// hence we allow total_ticks_per_tag to have kMaxEvents entries. | ||
TicksPerTag total_ticks_per_tag[kMaxEvents]; | ||
|
||
int FindExistingOrNextPosition(const char* tagName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Missed the header file last time.
if (tags_[i] == nullptr) { | ||
MicroPrintf("Event does not have a tag name."); | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this happen? seems like this should be a DCHECK and not an error that we want to print and continue on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a DCHECK. Thank you for the suggestion.
if (position == -1) { | ||
MicroPrintf("Number of tags exceeds the memory allocation."); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, this should not happen, right? We explicitly se the total number of unique tags to be equal to the total number of permitted events.
DCHECK seems more appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I was probably overthinking. Added DCHECK.
BUG=240626703