1/* Copyright 2020 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#include "tensorflow/lite/delegates/telemetry.h"
17
18#include "tensorflow/lite/c/common.h"
19#include "tensorflow/lite/core/api/profiler.h"
20
21namespace tflite {
22namespace 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
27TfLiteStatus 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
38TfLiteStatus 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