-
Notifications
You must be signed in to change notification settings - Fork 811
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
Profiler improvements #2724
base: main
Are you sure you want to change the base?
Profiler improvements #2724
Conversation
// sections. This can be used in conjunction with running the relevant micro | ||
// benchmark to evaluate end-to-end performance. | ||
template <int MAX_EVENTS> |
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 should be template <int MAX_EVENTS = 4096>
so that all existing applications using the profiler do not need to be changed.
case MicroProfilerLogFormat::Csv: | ||
MicroPrintf("\"Event\",\"Tag\",\"Ms\",\"Ticks\""); | ||
for (int i = 0; i < num_events_; ++i) { | ||
#if defined(HEXAGON) || defined(CMSIS_NN) | ||
int ticks = end_ticks_[i] - start_ticks_[i]; | ||
MicroPrintf("%d,%s,%u,%d", i, tags_[i], TicksToMs(ticks), ticks); | ||
#else | ||
uint32_t ticks = end_ticks_[i] - start_ticks_[i]; | ||
uint64_t us = TicksToUs(ticks); | ||
MicroPrintf("%d,%s,%" PRIu64 ".%" PRIu64 ",%" PRIu32, i, tags_[i], | ||
us / 1000, us % 1000, ticks); | ||
#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.
Changing the CSV format probably won't pass review, as it most likely breaks countless internal Google, and external third-party scripts.
const char* tag; | ||
uint32_t ticks; | ||
uint32_t tag_count; |
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.
Only used by the "human readable" log format.
void SortTagGroups() { | ||
for (int i = 0; i < num_tag_groups_ - 1; ++i) { | ||
for (int j = i + 1; j < num_tag_groups_; ++j) { | ||
if (tag_groups_[j].ticks > tag_groups_[i].ticks) { | ||
TagGroup temp_tag_group = tag_groups_[i]; | ||
tag_groups_[i] = tag_groups_[j]; | ||
tag_groups_[j] = temp_tag_group; | ||
} | ||
} | ||
} | ||
} |
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.
Please use standard C++ library algorithms (as long as they don't require memory allocation). Here std::sort
should be used.
virtual uint32_t BeginEvent(const char* tag) override; | ||
uint32_t BeginEvent(const char* 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.
This is an override of the abstract base class, and should remain as such.
virtual void EndEvent(uint32_t event_handle) override; | ||
void EndEvent(uint32_t event_handle) { |
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 is an override of the abstract base class, and should remain as such.
|
||
// Prints the profiling information of each of the events in human readable | ||
// form. | ||
void Log() const; | ||
void Log(MicroProfilerLogFormat format) const { |
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.
Should have a default argument of MicroProfilerLogFormt::Csv
so that all existing applications continue to compile without modification.
This PR adds a few improvements to the
MicroProfiler
class.bug=#2725
First, I made it a template so that it's possible to adjust the maximum number of events the profiler can handle via a template parameter.
The motivation for this change is to save memory. #1835 increased the maximum number of events from 1024 to 4096, which is a huge waste of RAM. The
MicroProfiler
class has these buffers:We need 20 bytes per event, so an instance of
MicroProfiler
uses 80 KB of RAM, even if the model you're profiling has only a few nodes.This PR also adds the following enum to specify the logging format and remove some duplicated code and clean the API.
I replaced
LogTicksPerTagCsv()
withLogGrouped()
, which does essentially the same thing, but also prints in a human readable format which looks like this:Finally I also added
TicksToUs()
to micro_time.h for convenience.