xref: /aosp_15_r20/external/tensorflow/tensorflow/python/profiler/internal/profiler_pywrap_impl.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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_PYTHON_PROFILER_INTERNAL_PROFILER_PYWRAP_IMPL_H_
16 #define TENSORFLOW_PYTHON_PROFILER_INTERNAL_PROFILER_PYWRAP_IMPL_H_
17 
18 #include <string>
19 #include <variant>
20 
21 #include "absl/container/flat_hash_map.h"
22 #include "absl/types/variant.h"
23 #include "tensorflow/core/platform/status.h"
24 #include "tensorflow/core/profiler/lib/profiler_session.h"
25 
26 namespace tensorflow {
27 namespace profiler {
28 namespace pywrap {
29 
30 tensorflow::Status Trace(
31     const char* service_addr, const char* logdir, const char* worker_list,
32     bool include_dataset_ops, int duration_ms, int num_tracing_attempts,
33     const absl::flat_hash_map<std::string, std::variant<int, std::string>>&
34         options);
35 
36 tensorflow::Status Monitor(const char* service_addr, int duration_ms,
37                            int monitoring_level, bool display_timestamp,
38                            tensorflow::string* result);
39 
40 class ProfilerSessionWrapper {
41  public:
42   tensorflow::Status Start(
43       const char* logdir,
44       const absl::flat_hash_map<std::string, std::variant<int, std::string>>&
45           options);
46   tensorflow::Status Stop(tensorflow::string* result);
47   tensorflow::Status ExportToTensorBoard();
48 
49  private:
50   std::unique_ptr<tensorflow::ProfilerSession> session_;
51   tensorflow::string logdir_;
52 };
53 
54 }  // namespace pywrap
55 }  // namespace profiler
56 }  // namespace tensorflow
57 
58 #endif  // TENSORFLOW_PYTHON_PROFILER_INTERNAL_PROFILER_PYWRAP_IMPL_H_
59