1 | /* Copyright 2019 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 <string> |
17 | |
18 | #include "pybind11/pybind11.h" |
19 | #include "tensorflow/core/framework/types.h" |
20 | #include "tensorflow/core/profiler/internal/print_model_analysis.h" |
21 | |
22 | namespace py = pybind11; |
23 | |
24 | PYBIND11_MODULE(_pywrap_tfprof, m) { |
25 | m.def("PrintModelAnalysis" , |
26 | [](const std::string* graph, const std::string* run_meta, |
27 | const std::string* op_log, const std::string* command, |
28 | const std::string* options) { |
29 | std::string temp = tensorflow::tfprof::PrintModelAnalysis( |
30 | graph, run_meta, op_log, command, options); |
31 | return py::bytes(temp); |
32 | }); |
33 | m.def("NewProfiler" , &tensorflow::tfprof::NewProfiler); |
34 | m.def("ProfilerFromFile" , &tensorflow::tfprof::ProfilerFromFile); |
35 | m.def("DeleteProfiler" , &tensorflow::tfprof::DeleteProfiler); |
36 | m.def("AddStep" , &tensorflow::tfprof::AddStep); |
37 | m.def("SerializeToString" , []() { |
38 | std::string temp = tensorflow::tfprof::SerializeToString(); |
39 | return py::bytes(temp); |
40 | }); |
41 | m.def("WriteProfile" , &tensorflow::tfprof::WriteProfile); |
42 | m.def("Profile" , [](const std::string* command, const std::string* options) { |
43 | std::string temp = tensorflow::tfprof::Profile(command, options); |
44 | return py::bytes(temp); |
45 | }); |
46 | } |
47 | |