Skip to content

Commit 04c4126

Browse files
bmass02copybara-github
authored andcommitted
Add PID qualification to TraceMeProducer/Consumers to differentiate between processes profiled together.
PiperOrigin-RevId: 824554472
1 parent 62db3b3 commit 04c4126

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tsl/profiler/lib/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ cc_library(
358358
":traceme_encode",
359359
"@com_google_absl//absl/strings",
360360
"@com_google_absl//absl/types:optional",
361+
"@xla//xla/tsl/platform:env",
361362
"@xla//xla/tsl/platform:types",
362363
],
363364
)

tsl/profiler/lib/connected_traceme.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ limitations under the License.
1515
#ifndef TENSORFLOW_TSL_PROFILER_LIB_CONNECTED_TRACEME_H_
1616
#define TENSORFLOW_TSL_PROFILER_LIB_CONNECTED_TRACEME_H_
1717

18+
#include <cstdint>
1819
#include <optional>
1920
#include <string>
2021
#include <utility>
2122

2223
#include "absl/strings/string_view.h"
2324
#include "absl/types/optional.h"
25+
#include "xla/tsl/platform/env.h"
2426
#include "xla/tsl/platform/types.h"
2527
#include "tsl/profiler/lib/context_types.h"
2628
#include "tsl/profiler/lib/traceme.h"
@@ -82,12 +84,16 @@ class TraceMeProducer : public TraceMe {
8284
explicit TraceMeProducer(NameT&& name,
8385
ContextType context_type = ContextType::kGeneric,
8486
std::optional<uint64> context_id = std::nullopt,
85-
int level = tsl::profiler::TraceMeLevel::kCritical)
87+
int level = tsl::profiler::TraceMeLevel::kCritical,
88+
std::optional<int32_t> pid = std::nullopt)
8689
: TraceMe(std::forward<NameT>(name), level),
8790
context_id_(context_id.has_value() ? context_id.value()
8891
: TraceMe::NewActivityId()) {
8992
AppendMetadata([&] {
90-
return TraceMeEncode({{"_pt", context_type}, {"_p", context_id_}});
93+
return TraceMeEncode(
94+
{{"_pt", context_type},
95+
{"_p", context_id_},
96+
{"_ppid", pid.value_or(tsl::Env::Default()->GetProcessId())}});
9197
});
9298
}
9399

@@ -101,10 +107,14 @@ class TraceMeConsumer : public TraceMe {
101107
public:
102108
template <typename NameT>
103109
TraceMeConsumer(NameT&& name, ContextType context_type, uint64 context_id,
104-
int level = tsl::profiler::TraceMeLevel::kCritical)
110+
int level = tsl::profiler::TraceMeLevel::kCritical,
111+
std::optional<uint64> pid = std::nullopt)
105112
: TraceMe(std::forward<NameT>(name), level) {
106113
AppendMetadata([&] {
107-
return TraceMeEncode({{"_ct", context_type}, {"_c", context_id}});
114+
return TraceMeEncode(
115+
{{"_ct", context_type},
116+
{"_c", context_id},
117+
{"_cpid", pid.value_or(tsl::Env::Default()->GetProcessId())}});
108118
});
109119
}
110120

0 commit comments

Comments
 (0)