Skip to content

Commit 7f51681

Browse files
authored
Increase kMaxEvents and error out when it's exceeded (#1835)
The current behavior silently resets and overwrites the internal list, this PR changes it to error out instead. BUG=b/264555999
1 parent ca680a2 commit 7f51681

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

tensorflow/lite/micro/docs/profiling.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ from within operator kernels and other TFLite Micro routines.
2323

2424
## API
2525

26-
The MicroInterpreter class constructor contains and optional profiler argument.
26+
The MicroInterpreter class constructor contains an optional profiler argument.
2727
This profiler must be an instance of the tflite::Profiler class, and should
2828
implement the BeginEvent and EndEvent methods. There is a default implementation
2929
in tensorflow/lite/micro/micro_profiler.cc which can be used for most purposes.
3030

31+
The best practice for profiling across multiple invocations is to reset or call
32+
`ClearEvents()` in between invocations.
33+
3134
## Per-Op Profiling
3235

3336
There is a feature in the MicroInterpreter to enable per-op profiling. To enable

tensorflow/lite/micro/micro_profiler.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ namespace tflite {
2626

2727
uint32_t MicroProfiler::BeginEvent(const char* tag) {
2828
if (num_events_ == kMaxEvents) {
29-
num_events_ = 0;
29+
MicroPrintf(
30+
"MicroProfiler errored out because total number of events exceeded the "
31+
"maximum of %d.",
32+
kMaxEvents);
33+
TFLITE_ASSERT_FALSE;
3034
}
3135

3236
tags_[num_events_] = tag;

tensorflow/lite/micro/micro_profiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MicroProfiler : public MicroProfilerInterface {
6969
// Maximum number of events that this class can keep track of. If we call
7070
// AddEvent more than kMaxEvents number of times, then the oldest event's
7171
// profiling information will be overwritten.
72-
static constexpr int kMaxEvents = 1024;
72+
static constexpr int kMaxEvents = 4096;
7373

7474
const char* tags_[kMaxEvents];
7575
uint32_t start_ticks_[kMaxEvents];

0 commit comments

Comments
 (0)