xref: /aosp_15_r20/external/tensorflow/tensorflow/core/profiler/utils/xplane_test_utils.h (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 #ifndef TENSORFLOW_CORE_PROFILER_UTILS_XPLANE_TEST_UTILS_H_
16 #define TENSORFLOW_CORE_PROFILER_UTILS_XPLANE_TEST_UTILS_H_
17 
18 #include <initializer_list>
19 
20 #include "absl/strings/string_view.h"
21 #include "absl/types/variant.h"
22 #include "tensorflow/core/platform/types.h"
23 #include "tensorflow/core/profiler/utils/xplane_builder.h"
24 #include "tensorflow/core/profiler/utils/xplane_schema.h"
25 
26 namespace tensorflow {
27 namespace profiler {
28 
29 using XStatValue = absl::variant<int64_t, uint64, absl::string_view>;
30 
31 XPlane* GetOrCreateHostXPlane(XSpace* space);
32 
33 XPlane* GetOrCreateGpuXPlane(XSpace* space, int32_t device_ordinal);
34 
35 XPlane* GetOrCreateTpuXPlane(XSpace* space, int32_t device_ordinal,
36                              absl::string_view device_type);
37 
38 void CreateXEvent(
39     XPlaneBuilder* plane_builder, XLineBuilder* line_builder,
40     absl::string_view event_name, int64_t offset_ps, int64_t duration_ps,
41     std::initializer_list<std::pair<StatType, XStatValue>> stats = {});
42 
43 void CreateXEvent(
44     XPlaneBuilder* plane_builder, XLineBuilder* line_builder,
45     HostEventType event_type, int64_t offset_ps, int64_t duration_ps,
46     std::initializer_list<std::pair<StatType, XStatValue>> stats = {});
47 
48 void CreateTfFunctionCallEvent(XPlaneBuilder* plane_builder,
49                                XLineBuilder* line_builder,
50                                absl::string_view function_name,
51                                int64_t offset_ps, int64_t duration_ps,
52                                absl::string_view execution_mode,
53                                int64_t tracing_count = -1);
54 }  // namespace profiler
55 }  // namespace tensorflow
56 
57 #endif  // TENSORFLOW_CORE_PROFILER_UTILS_XPLANE_TEST_UTILS_H_
58