Skip to content

Commit c520ad3

Browse files
Sai Ganesh Muthuramancopybara-github
authored andcommitted
Enable scroll and zoom out in Trace Viewer V2 when loading deep-linked traces.
PiperOrigin-RevId: 918243950
1 parent 490fde1 commit c520ad3

4 files changed

Lines changed: 42 additions & 0 deletions

File tree

frontend/app/components/trace_viewer_v2/trace_helper/trace_pb_event_parser.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ ParsedTraceEvents ParseCompressedTraceEvents(
5757
ProcessAsyncEvents(response, result);
5858
ProcessCounterEvents(response, result);
5959

60+
if (response.has_full_timespan_start_ps() &&
61+
response.has_full_timespan_end_ps()) {
62+
const Milliseconds start_ms = response.full_timespan_start_ps() / 1e9;
63+
const Milliseconds end_ms = response.full_timespan_end_ps() / 1e9;
64+
if (start_ms <= end_ms) {
65+
result.full_timespan = std::make_pair(start_ms, end_ms);
66+
}
67+
}
68+
6069
if (!visible_range_from_url.isNull() &&
6170
!visible_range_from_url.isUndefined() &&
6271
visible_range_from_url["length"].as<int>() == 2) {

plugin/xprof/protobuf/trace_data_response.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,7 @@ message TraceDataResponse {
8484
repeated string interned_strings = 5;
8585
// Details for the trace (e.g., flags for the frontend).
8686
repeated DetailItem details = 6;
87+
// The full timespan of the trace (start time and end time in picoseconds).
88+
optional uint64 full_timespan_start_ps = 7;
89+
optional uint64 full_timespan_end_ps = 8;
8790
}

xprof/convert/trace_viewer/delta_series/trace_data_to_compressed_delta_series_proto.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ absl::Status DeltaSeriesProtoConverter::GenerateResponse(
134134
d->set_value(detail.second);
135135
}
136136

137+
if (trace_->has_min_timestamp_ps()) {
138+
response->set_full_timespan_start_ps(trace_->min_timestamp_ps());
139+
}
140+
if (trace_->has_max_timestamp_ps()) {
141+
response->set_full_timespan_end_ps(trace_->max_timestamp_ps());
142+
}
143+
137144
using TidOrName = std::variant<uint64_t, absl::string_view>;
138145

139146
container.ForAllTracks([this, response](uint32_t pid, TidOrName tid_or_name,

xprof/convert/trace_viewer/delta_series/trace_data_to_compressed_delta_series_proto_test.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace tensorflow {
1515
namespace profiler {
1616
namespace {
1717

18+
using ::testing::Eq;
1819
using ::testing::EqualsProto;
1920
using ::testing::proto::Partially;
2021

@@ -416,6 +417,28 @@ TEST(DeltaSeriesProtoConverterTest, PopulatesDetails) {
416417
)pb")));
417418
}
418419

420+
TEST(DeltaSeriesProtoConverterTest, PopulatesFullTimespan) {
421+
Trace trace;
422+
trace.set_min_timestamp_ps(12345000);
423+
trace.set_max_timestamp_ps(67890000);
424+
TestTraceEventsContainer container(trace);
425+
426+
ASSERT_OK_AND_ASSIGN(std::string compressed_result,
427+
ConvertTraceDataToCompressedDeltaSeriesProto(
428+
DeltaSeriesProtoConversionOptions{}, container));
429+
430+
ASSERT_OK_AND_ASSIGN(std::string decompressed,
431+
ZstdCompression::Decompress(compressed_result));
432+
433+
xprof::TraceDataResponse response;
434+
ASSERT_TRUE(response.ParseFromString(decompressed));
435+
436+
EXPECT_TRUE(response.has_full_timespan_start_ps());
437+
EXPECT_THAT(response.full_timespan_start_ps(), Eq(12345000));
438+
EXPECT_TRUE(response.has_full_timespan_end_ps());
439+
EXPECT_THAT(response.full_timespan_end_ps(), Eq(67890000));
440+
}
441+
419442
} // namespace
420443
} // namespace profiler
421444
} // namespace tensorflow

0 commit comments

Comments
 (0)