-
Notifications
You must be signed in to change notification settings - Fork 880
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
Changes from 4 commits
67d57de
e59bceb
f04b0ec
decb722
483a5a4
09736e6
2100f8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,65 @@ void MicroProfiler::LogCsv() const { | |
#endif | ||
} | ||
|
||
void MicroProfiler::LogTicksPerTagCsv() { | ||
#if !defined(TF_LITE_STRIP_ERROR_STRINGS) | ||
MicroPrintf( | ||
"\"Unique Tag\",\"Total ticks across all events with that tag.\""); | ||
int total_ticks = 0; | ||
for (int i = 0; i < num_events_; ++i) { | ||
uint32_t ticks = end_ticks_[i] - start_ticks_[i]; | ||
int position = FindExistingOrNextPosition(tags_[i]); | ||
total_ticks_per_tag[position].tag = tags_[i]; | ||
total_ticks_per_tag[position].ticks = | ||
total_ticks_per_tag[position].ticks + ticks; | ||
total_ticks += ticks; | ||
} | ||
|
||
for (int i = 0; i < num_events_; ++i) { | ||
TicksPerTag each_tag_entry = total_ticks_per_tag[i]; | ||
if (each_tag_entry.tag == nullptr) { | ||
break; | ||
} | ||
MicroPrintf("%s,%d", each_tag_entry.tag, each_tag_entry.ticks); | ||
} | ||
MicroPrintf("total,%d", total_ticks); | ||
#endif | ||
} | ||
|
||
/** | ||
* This method finds a particular array element in the total_ticks_per_tag array | ||
* with the matching tag_name passed in the method. If it can find a | ||
* matching array element that has the same tag_name, then it will return the | ||
* position of the matching element. But if it unable to find a matching element | ||
* with the given tag_name, it will return the next available empty postion | ||
* from the array. | ||
*/ | ||
int MicroProfiler::FindExistingOrNextPosition(const char* tag_name) { | ||
int pos = 0; | ||
for (; pos < num_events_; pos++) { | ||
TicksPerTag each_tag_entry = total_ticks_per_tag[pos]; | ||
if (each_tag_entry.tag == nullptr) { | ||
return pos; | ||
} else { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. current_tag_name There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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. |
||
} | ||
|
||
if (matched) { | ||
return pos; | ||
} | ||
} | ||
} | ||
return pos; | ||
} | ||
|
||
} // namespace tflite |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,11 @@ class MicroProfiler { | |
// Separated Value) form. | ||
void LogCsv() const; | ||
|
||
// 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. | ||
void LogTicksPerTagCsv(); | ||
|
||
private: | ||
// Maximum number of events that this class can keep track of. If we call | ||
// AddEvent more than kMaxEvents number of times, then the oldest event's | ||
|
@@ -72,6 +77,17 @@ class MicroProfiler { | |
uint32_t end_ticks_[kMaxEvents]; | ||
int num_events_ = 0; | ||
|
||
struct TicksPerTag { | ||
const char* tag; | ||
uint32_t ticks; | ||
}; | ||
// In practice, the number of tags will be much lower than the number of | ||
// events. But it is theoretically possible that each event to be unique and | ||
// 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you for the suggestion! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. Thank you for the suggestion! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. Missed the header file last time. |
||
|
||
TF_LITE_REMOVE_VIRTUAL_DELETE; | ||
}; | ||
|
||
|
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.