1/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_LITE_TENSORFLOW_PROFILER_LOGGER_H_
17#define TENSORFLOW_LITE_TENSORFLOW_PROFILER_LOGGER_H_
18
19#include <cstdint>
20#include <string>
21
22#include "tensorflow/lite/core/macros.h"
23
24struct TfLiteTensor;
25
26namespace tensorflow {
27namespace profiler {
28class TraceMe;
29} // namespace profiler
30} // namespace tensorflow
31
32namespace tflite {
33// Records an op preparation with `op_name` and `node_index`.
34TFLITE_ATTRIBUTE_WEAK void OnTfLiteOpPrepare(const char* op_name,
35 int subgraph_index,
36 int node_index);
37
38// Returns a `TraceMe` pointer to record a subgraph invocation with
39// `subgraph_name` and `subgraph_index`.
40TFLITE_ATTRIBUTE_WEAK tensorflow::profiler::TraceMe* OnTfLiteSubgraphInvoke(
41 const char* subgraph_name, int subgraph_index);
42
43// Records an end of the subgraph invocation with the given `TraceMe` pointer.
44TFLITE_ATTRIBUTE_WEAK void OnTfLiteSubgraphInvokeEnd(
45 tensorflow::profiler::TraceMe* trace_me);
46
47// Returns a `TraceMe` pointer to record an op invocation with `op_name` and
48// `node_index`.
49TFLITE_ATTRIBUTE_WEAK tensorflow::profiler::TraceMe* OnTfLiteOpInvoke(
50 const char* op_name, int subgraph_index, int node_index);
51
52// Records an end of the op invocation with the given `TraceMe` pointer.
53TFLITE_ATTRIBUTE_WEAK void OnTfLiteOpInvokeEnd(
54 tensorflow::profiler::TraceMe* trace_me);
55
56// Records an event of `num_bytes` of memory allocated for `tensor`.
57TFLITE_ATTRIBUTE_WEAK void OnTfLiteTensorAlloc(TfLiteTensor* tensor,
58 size_t num_bytes);
59
60// Records an event of memory deallocated for `tensor`.
61TFLITE_ATTRIBUTE_WEAK void OnTfLiteTensorDealloc(TfLiteTensor* tensor);
62
63// Records an event of `num_bytes` of memory allocated for arena.
64TFLITE_ATTRIBUTE_WEAK void OnTfLiteArenaAlloc(int subgraph_index, int arena_id,
65 size_t num_bytes);
66
67// Records an event of `num_bytes` of memory deallocated for arena.
68TFLITE_ATTRIBUTE_WEAK void OnTfLiteArenaDealloc(int subgraph_index,
69 int arena_id, size_t num_bytes);
70
71} // namespace tflite
72
73#endif // TENSORFLOW_LITE_TENSORFLOW_PROFILER_LOGGER_H_
74