Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 18 additions & 1 deletion tsl/profiler/lib/profiler_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,27 @@ void RegisterProfilerFactory(ProfilerFactory factory) {

std::vector<std::unique_ptr<profiler::ProfilerInterface>> CreateProfilers(
const tensorflow::ProfileOptions& options) {
// Create a copy of options to modify if circular buffer is enabled.
tensorflow::ProfileOptions options_to_use = options;
bool circular_buffer_enabled = false;

// Check if tpu_circular_buffer_tracing is enabled in advanced configuration.
auto it =
options.advanced_configuration().find("tpu_circular_buffer_tracing");
if (it != options.advanced_configuration().end()) {
circular_buffer_enabled = it->second.bool_value();
}

if (circular_buffer_enabled) {
// Disable other tracers by zeroing their levels in the local options copy.
options_to_use.set_host_tracer_level(0);
options_to_use.set_python_tracer_level(0);
}

std::vector<std::unique_ptr<profiler::ProfilerInterface>> result;
absl::MutexLock lock(mu);
for (const auto& factory : *GetFactories()) {
auto profiler = factory(options);
auto profiler = factory(options_to_use);
// A factory might return nullptr based on options.
if (profiler == nullptr) continue;
result.emplace_back(
Expand Down
9 changes: 9 additions & 0 deletions tsl/profiler/protobuf/profiler_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ service ProfilerService {
rpc Terminate(TerminateRequest) returns (TerminateResponse) {}
// Collects profiling data and returns user-friendly metrics.
rpc Monitor(MonitorRequest) returns (MonitorResponse) {}
// Starts a continuous profiling session.
rpc StartContinuousProfiling(ProfileRequest)
returns (ContinuousProfilingResponse) {}
// Gets a snapshot of an ongoing profiling session.
rpc GetSnapshot(GetSnapshotRequest) returns (ProfileResponse) {}
}

message ToolRequestOptions {
Expand Down Expand Up @@ -99,6 +104,10 @@ message TerminateRequest {

message TerminateResponse {}

message GetSnapshotRequest {}

message ContinuousProfilingResponse {}

// Next-ID: 4
message MonitorRequest {
// Duration for which to profile between each update.
Expand Down
Loading