@@ -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