Skip to content

Commit 8966f2a

Browse files
youchunnicopybara-github
authored andcommitted
Provide the option to opt-out from source_location in TraceMeEncode
PiperOrigin-RevId: 906528703
1 parent 4951218 commit 8966f2a

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

tsl/profiler/lib/BUILD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ cc_library(
2828
visibility = ["//visibility:public"],
2929
)
3030

31+
cc_library(
32+
name = "traceme_global_flags",
33+
srcs = ["traceme_global_flags.cc"],
34+
hdrs = ["traceme_global_flags.h"],
35+
copts = tf_profiler_copts(),
36+
visibility = ["//visibility:public"],
37+
deps = [
38+
"@xla//xla/tsl/platform:macros",
39+
],
40+
alwayslink = True,
41+
)
42+
3143
filegroup(
3244
name = "mobile_srcs_no_runtime",
3345
srcs = [
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright 2026 The OpenXLA Authors.
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 "tsl/profiler/lib/traceme_global_flags.h"
17+
18+
#include <atomic>
19+
20+
namespace tsl {
21+
namespace profiler {
22+
23+
#ifdef _WIN32
24+
#define DECL_DLL_EXPORT __declspec(dllexport)
25+
#else
26+
#define DECL_DLL_EXPORT
27+
#endif
28+
// DLL imported variables cannot be initialized on Windows. This file is
29+
// included only on DLL exports.
30+
DECL_DLL_EXPORT std::atomic<bool> g_enable_source_location(true);
31+
32+
} // namespace profiler
33+
} // namespace tsl
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright 2026 The OpenXLA Authors.
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+
#ifndef TENSORFLOW_TSL_PROFILER_LIB_TRACEME_GLOBAL_FLAGS_H_
17+
#define TENSORFLOW_TSL_PROFILER_LIB_TRACEME_GLOBAL_FLAGS_H_
18+
19+
#include <stddef.h>
20+
#include <stdint.h>
21+
22+
#include <atomic>
23+
24+
#include "xla/tsl/platform/macros.h"
25+
26+
// Flags that are global to the TraceMe implementation, which may be shared by
27+
// TraceMe and TraceMeRecorder.
28+
namespace tsl {
29+
namespace profiler {
30+
31+
TF_EXPORT extern std::atomic<bool> g_enable_source_location;
32+
33+
class TraceMeGlobalFlags {
34+
public:
35+
// Returns whether source location is enabled.
36+
static bool IsSourceLocationEnabled() {
37+
return g_enable_source_location.load(std::memory_order_relaxed);
38+
}
39+
};
40+
41+
} // namespace profiler
42+
} // namespace tsl
43+
44+
#endif // TENSORFLOW_TSL_PROFILER_LIB_TRACEME_GLOBAL_FLAGS_H_

0 commit comments

Comments
 (0)