• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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 #ifndef TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_METRICS_WRAPPER_H_
16 #define TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_METRICS_WRAPPER_H_
17 
18 #include <memory>
19 #include <string>
20 
21 // Place `<locale>` before <Python.h> to avoid build failures in macOS.
22 #include <locale>
23 
24 // The empty line above is on purpose as otherwise clang-format will
25 // automatically move <Python.h> before <locale>.
26 #include <Python.h>
27 
28 // We forward declare TFLite classes here to avoid exposing them to SWIG.
29 namespace tensorflow {
30 namespace monitoring {
31 class MetricsExporter;
32 }  // namespace monitoring
33 }  // namespace tensorflow
34 
35 namespace tflite {
36 namespace metrics_wrapper {
37 
38 class MetricsWrapper {
39  public:
40   using MetricsExporter = tensorflow::monitoring::MetricsExporter;
41   // SWIG caller takes ownership of pointer.
42   static MetricsWrapper* CreateMetricsWrapper(const std::string& session_id);
43 
44   ~MetricsWrapper();
45 
46   // Export metrics with Streamz.
47   PyObject* ExportMetrics();
48 
49  private:
50   explicit MetricsWrapper(std::unique_ptr<MetricsExporter> exporter);
51 
52   const std::unique_ptr<MetricsExporter> exporter_;
53 };
54 
55 }  // namespace metrics_wrapper
56 }  // namespace tflite
57 
58 #endif  // TENSORFLOW_LITE_PYTHON_INTERPRETER_WRAPPER_METRICS_WRAPPER_H_
59