Skip to content

Commit a31e1b4

Browse files
sannidhyachauhancopybara-github
authored andcommitted
Enable circular buffer tracing for TPU
PiperOrigin-RevId: 854050523
1 parent 81dd30a commit a31e1b4

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

xprof/pywrap/profiler_plugin_impl.cc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ limitations under the License.
1818
#include <memory>
1919
#include <optional>
2020
#include <string>
21+
#include <type_traits>
2122
#include <utility>
23+
#include <variant>
2224
#include <vector>
2325

2426
#include "absl/base/call_once.h"
@@ -122,14 +124,33 @@ absl::Status StartContinuousProfiling(const char* service_addr,
122124
LOG(INFO) << "StartContinuousProfiling";
123125
TF_RETURN_IF_ERROR(tsl::profiler::ValidateHostPortPair(service_addr));
124126
tensorflow::RemoteProfilerSessionManagerOptions options;
127+
ToolOptions mutable_tool_options = tool_options;
128+
mutable_tool_options["tpu_circular_buffer_tracing"] = true;
129+
mutable_tool_options["host_tracer_level"] = 0;
130+
mutable_tool_options["python_tracer_level"] = 0;
131+
for (const auto& [key, value] : mutable_tool_options) {
132+
std::visit(
133+
[&](const auto& arg) {
134+
using T = std::decay_t<decltype(arg)>;
135+
if constexpr (std::is_same_v<T, std::string> ||
136+
std::is_same_v<T, int64_t> || std::is_same_v<T, bool> ||
137+
std::is_same_v<T, double>) {
138+
LOG(INFO) << "ToolOption: " << key << " = " << arg;
139+
} else {
140+
LOG(INFO) << "ToolOption: " << key
141+
<< " = (vector elements not printed)";
142+
}
143+
},
144+
value);
145+
}
125146
bool is_cloud_tpu_session;
126147
// Even though the duration is set to 2 seconds, the profiling will continue
127148
// until GetSnapshot is called, it is only done since
128149
// GetRemoteSessionManagerOptionsLocked requires a duration.
129150
const int32_t kContinuousProfilingdurationMs = 2000;
130151
options = tsl::profiler::GetRemoteSessionManagerOptionsLocked(
131-
service_addr, "", "", false, kContinuousProfilingdurationMs, tool_options,
132-
&is_cloud_tpu_session);
152+
service_addr, "", "", false, kContinuousProfilingdurationMs,
153+
mutable_tool_options, &is_cloud_tpu_session);
133154
return tsl::profiler::StartContinuousProfiling(service_addr, options);
134155
}
135156

0 commit comments

Comments
 (0)