Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions tsl/profiler/lib/traceme.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ class TraceMe {
TraceMeRecorder::CheckFilter(filter_mask))) {
name_.Emplace(std::forward<NameGeneratorT>(name_generator)());
start_time_ = GetCurrentTimeNanos();
} else {
#ifndef NDEBUG
// Always invoke the name generator on debug builds to catch bugs in name
// generators that would otherwise only be caught when tracing is enabled.
std::forward<NameGeneratorT>(name_generator)();
#endif
}
#endif
}
Expand Down Expand Up @@ -212,12 +218,16 @@ class TraceMe {
std::enable_if_t<std::is_invocable_v<MetadataGeneratorT>, bool> = true>
void AppendMetadata(MetadataGeneratorT&& metadata_generator) {
#if !defined(IS_MOBILE_PLATFORM)
if (TF_PREDICT_FALSE(start_time_ != kUntracedActivity)) {
if (TF_PREDICT_TRUE(TraceMeRecorder::Active())) {
traceme_internal::AppendMetadata(
&name_.value,
std::forward<MetadataGeneratorT>(metadata_generator)());
}
if (TF_PREDICT_FALSE(start_time_ != kUntracedActivity) &&
TF_PREDICT_TRUE(TraceMeRecorder::Active())) {
traceme_internal::AppendMetadata(
&name_.value, std::forward<MetadataGeneratorT>(metadata_generator)());
} else {
#ifndef NDEBUG
// Always invoke the name generator on debug builds to catch bugs in name
// generators that would otherwise only be caught when tracing is enabled.
std::forward<MetadataGeneratorT>(metadata_generator)();
#endif
}
#endif
}
Expand All @@ -239,6 +249,12 @@ class TraceMe {
TraceMeRecorder::Record({std::forward<NameGeneratorT>(name_generator)(),
GetCurrentTimeNanos(), -activity_id});
return activity_id;
} else {
#ifndef NDEBUG
// Always invoke the name generator on debug builds to catch bugs in name
// generators that would otherwise only be caught when tracing is enabled.
std::forward<NameGeneratorT>(name_generator)();
#endif
}
#endif
return kUntracedActivity;
Expand Down Expand Up @@ -300,6 +316,12 @@ class TraceMe {
int64_t now = GetCurrentTimeNanos();
TraceMeRecorder::Record({std::forward<NameGeneratorT>(name_generator)(),
/*start_time=*/now, /*end_time=*/now});
} else {
#ifndef NDEBUG
// Always invoke the name generator on debug builds to catch bugs in name
// generators that would otherwise only be caught when tracing is enabled.
std::forward<NameGeneratorT>(name_generator)();
#endif
}
#endif
}
Expand Down
Loading