|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "edge-impulse-sdk/tensorflow/lite/micro/micro_profiler.h" |
|
|
|
|
|
#include <cstdint> |
|
|
|
|
|
#include "edge-impulse-sdk/tensorflow/lite/kernels/internal/compatibility.h" |
|
|
#include "edge-impulse-sdk/tensorflow/lite/micro/micro_error_reporter.h" |
|
|
#include "edge-impulse-sdk/tensorflow/lite/micro/micro_time.h" |
|
|
|
|
|
namespace tflite { |
|
|
|
|
|
uint32_t MicroProfiler::BeginEvent(const char* tag) { |
|
|
if (num_events_ == kMaxEvents) { |
|
|
num_events_ = 0; |
|
|
} |
|
|
|
|
|
tags_[num_events_] = tag; |
|
|
start_ticks_[num_events_] = GetCurrentTimeTicks(); |
|
|
end_ticks_[num_events_] = start_ticks_[num_events_] - 1; |
|
|
return num_events_++; |
|
|
} |
|
|
|
|
|
void MicroProfiler::EndEvent(uint32_t event_handle) { |
|
|
TFLITE_DCHECK(event_handle < kMaxEvents); |
|
|
end_ticks_[event_handle] = GetCurrentTimeTicks(); |
|
|
} |
|
|
|
|
|
int32_t MicroProfiler::GetTotalTicks() const { |
|
|
int32_t ticks = 0; |
|
|
for (int i = 0; i < num_events_; ++i) { |
|
|
ticks += end_ticks_[i] - start_ticks_[i]; |
|
|
} |
|
|
return ticks; |
|
|
} |
|
|
|
|
|
void MicroProfiler::Log() const { |
|
|
#if !defined(TF_LITE_STRIP_ERROR_STRINGS) |
|
|
for (int i = 0; i < num_events_; ++i) { |
|
|
int32_t ticks = end_ticks_[i] - start_ticks_[i]; |
|
|
MicroPrintf("%s took %d ticks (%d ms).", tags_[i], ticks, TicksToMs(ticks)); |
|
|
} |
|
|
#endif |
|
|
} |
|
|
|
|
|
} |
|
|
|