xref: /aosp_15_r20/external/tensorflow/tensorflow/lite/delegates/telemetry.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/lite/delegates/telemetry.h"
17 
18 #include "tensorflow/lite/c/common.h"
19 #include "tensorflow/lite/core/api/profiler.h"
20 
21 namespace tflite {
22 namespace delegates {
23 
24 // TODO(b/153131797): Add an IFTTT here once we have a profiler to interpret
25 // these events, so that the two components don't go out of sync.
26 
ReportDelegateSettings(TfLiteContext * context,TfLiteDelegate * delegate,const TFLiteSettings & settings)27 TfLiteStatus ReportDelegateSettings(TfLiteContext* context,
28                                     TfLiteDelegate* delegate,
29                                     const TFLiteSettings& settings) {
30   auto* profiler = reinterpret_cast<Profiler*>(context->profiler);
31   const int64_t event_metadata1 = reinterpret_cast<int64_t>(delegate);
32   const int64_t event_metadata2 = reinterpret_cast<int64_t>(&settings);
33   TFLITE_ADD_RUNTIME_INSTRUMENTATION_EVENT(profiler, kDelegateSettingsTag,
34                                            event_metadata1, event_metadata2);
35   return kTfLiteOk;
36 }
37 
ReportDelegateStatus(TfLiteContext * context,TfLiteDelegate * delegate,const DelegateStatus & status)38 TfLiteStatus ReportDelegateStatus(TfLiteContext* context,
39                                   TfLiteDelegate* delegate,
40                                   const DelegateStatus& status) {
41   auto* profiler = reinterpret_cast<Profiler*>(context->profiler);
42   TFLITE_ADD_RUNTIME_INSTRUMENTATION_EVENT(profiler, kDelegateStatusTag,
43                                            status.full_status(),
44                                            static_cast<int64_t>(kTfLiteOk));
45   return kTfLiteOk;
46 }
47 
48 }  // namespace delegates
49 }  // namespace tflite
50