Skip to content

Commit a268fc0

Browse files
loislocopybara-github
authored andcommitted
[XLA:GPU] Add more Traceme for the compilation steps
with more TraceMe statements we could see the compilation process in more details. PiperOrigin-RevId: 757439912
1 parent 448efb8 commit a268fc0

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

tsl/profiler/lib/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ cc_library(
270270
":traceme_encode",
271271
"//tsl/platform",
272272
"@com_google_absl//absl/strings",
273+
"@com_google_absl//absl/types:source_location",
273274
"@xla//xla/tsl/platform:logging",
274275
"@xla//xla/tsl/platform:macros",
275276
"@xla//xla/tsl/platform:types",

tsl/profiler/lib/traceme.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ limitations under the License.
2323
#include <type_traits>
2424
#include <utility>
2525

26+
#include "absl/strings/str_cat.h"
2627
#include "absl/strings/string_view.h"
28+
#include "absl/types/source_location.h"
2729
#include "xla/tsl/platform/logging.h"
2830
#include "xla/tsl/platform/macros.h"
2931
#include "xla/tsl/profiler/utils/no_init.h"
@@ -94,13 +96,20 @@ class TraceMe {
9496
// - Can be a value in enum TraceMeLevel.
9597
// Users are welcome to use level > 3 in their code, if they wish to filter
9698
// out their host traces based on verbosity.
97-
explicit TraceMe(absl::string_view name, int level = 1,
98-
uint64_t filter_mask = kTraceMeDefaultFilterMask) {
99+
explicit TraceMe(
100+
absl::string_view name, int level = 1,
101+
uint64_t filter_mask = kTraceMeDefaultFilterMask,
102+
absl::SourceLocation source_location = absl::SourceLocation::current()) {
99103
DCHECK_GE(level, 1);
100104
#if !defined(IS_MOBILE_PLATFORM)
101105
if (TF_PREDICT_FALSE(TraceMeRecorder::Active(level) &&
102106
TraceMeRecorder::CheckFilter(filter_mask))) {
103107
name_.Emplace(std::string(name));
108+
traceme_internal::AppendMetadata(
109+
&name_.value,
110+
TraceMeEncode({{"source_location",
111+
absl::StrCat(source_location.file_name(), ":",
112+
source_location.line())}}));
104113
start_time_ = GetCurrentTimeNanos();
105114
}
106115
#endif
@@ -123,9 +132,11 @@ class TraceMe {
123132

124133
// This overload is necessary to make TraceMe's with string literals work.
125134
// Otherwise, the name_generator template would be used.
126-
explicit TraceMe(const char* raw, int level = 1,
127-
uint64_t filter_mask = kTraceMeDefaultFilterMask)
128-
: TraceMe(absl::string_view(raw), level, filter_mask) {}
135+
explicit TraceMe(
136+
const char* raw, int level = 1,
137+
uint64_t filter_mask = kTraceMeDefaultFilterMask,
138+
absl::SourceLocation source_location = absl::SourceLocation::current())
139+
: TraceMe(absl::string_view(raw), level, filter_mask, source_location) {}
129140

130141
// This overload only generates the name (and possibly metadata) if tracing is
131142
// enabled. Useful for avoiding expensive operations (e.g., string
@@ -146,13 +157,19 @@ class TraceMe {
146157
// });
147158
template <typename NameGeneratorT,
148159
std::enable_if_t<std::is_invocable_v<NameGeneratorT>, bool> = true>
149-
explicit TraceMe(NameGeneratorT&& name_generator, int level = 1,
150-
uint64_t filter_mask = kTraceMeDefaultFilterMask) {
160+
explicit TraceMe(
161+
NameGeneratorT&& name_generator, int level = 1,
162+
uint64_t filter_mask = kTraceMeDefaultFilterMask,
163+
absl::SourceLocation source_location = absl::SourceLocation::current()) {
151164
DCHECK_GE(level, 1);
152165
#if !defined(IS_MOBILE_PLATFORM)
153166
if (TF_PREDICT_FALSE(TraceMeRecorder::Active(level) &&
154167
TraceMeRecorder::CheckFilter(filter_mask))) {
155168
name_.Emplace(std::forward<NameGeneratorT>(name_generator)());
169+
AppendMetadata([&]() {
170+
return TraceMeEncode(
171+
{{"source_location", source_location.file_name()}});
172+
});
156173
start_time_ = GetCurrentTimeNanos();
157174
}
158175
#endif

0 commit comments

Comments
 (0)