1<!-- mdformat off(b/169948621#comment2) -->
2
3<!--
4Semi-automated TOC generation with instructions from
5https://github.com/ekalinin/github-markdown-toc#auto-insert-and-update-toc
6-->
7
8<!--ts-->
9   * [Profiling](#profiling)
10      * [API](#api)
11      * [Per-Op Profiling](#per-op-profiling)
12      * [Subroutine Profiling](#subroutine-profiling)
13
14<!-- Added by: njeff, at: Wed 04 Nov 2020 04:35:07 PM PST -->
15
16<!--te-->
17
18# Profiling
19
20This doc outlines how to use the TFLite Micro profiler to gather information
21about per-op invoke duration and to use the profiler to identify bottlenecks
22from within operator kernels and other TFLite Micro routines.
23
24## API
25
26The MicroInterpreter class constructor contains and optional profiler argument.
27This profiler must be an instance of the tflite::Profiler class, and should
28implement the BeginEvent and EndEvent methods. There is a default implementation
29in tensorflow/lite/micro/micro_profiler.cc which can be used for most purposes.
30
31## Per-Op Profiling
32
33There is a feature in the MicroInterpreter to enable per-op profiling. To enable
34this, provide a MicroProfiler to the MicroInterpreter's constructor then build
35with a non-release build to disable the NDEBUG define surrounding the
36ScopedOperatorProfile within the MicroInterpreter.
37
38## Subroutine Profiling
39
40In order to further dig into performance of specific routines, the MicroProfiler
41can be used directly from the TFLiteContext or a new MicroProfiler can be
42created if the TFLiteContext is not available where the profiling needs to
43happen. The MicroProfiler's BeginEvent and EndEvent can be called directly, or
44wrapped using a [ScopedProfile](../../lite/core/api/profiler.h).
45