Skip to content

Commit fe91307

Browse files
authored
UI: ETM: session track for etm (#2712)
Adds a track to the UI that plots the current ETM session number on the timeline.
1 parent 0af09e2 commit fe91307

File tree

3 files changed

+76
-3
lines changed

3 files changed

+76
-3
lines changed

src/trace_processor/importers/etm/etm_v4_stream.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "perfetto/ext/base/status_macros.h"
2727
#include "perfetto/trace_processor/trace_blob.h"
2828
#include "perfetto/trace_processor/trace_blob_view.h"
29+
#include "src/trace_processor/importers/common/event_tracker.h"
30+
#include "src/trace_processor/importers/common/track_tracker.h"
31+
#include "src/trace_processor/importers/common/tracks.h"
32+
#include "src/trace_processor/importers/common/tracks_common.h"
2933
#include "src/trace_processor/importers/etm/etm_v4_stream_demultiplexer.h"
3034
#include "src/trace_processor/importers/etm/frame_decoder.h"
3135
#include "src/trace_processor/importers/etm/opencsd.h"
@@ -139,9 +143,21 @@ base::Status EtmV4Stream::OnItraceStartRecord(
139143
void EtmV4Stream::StartSession(std::optional<int64_t> start_ts) {
140144
PERFETTO_CHECK(stream_active_);
141145
PERFETTO_CHECK(!session_.has_value());
142-
session_.emplace(context_->storage->mutable_etm_v4_session_table()
143-
->Insert({config_id_, start_ts})
144-
.id);
146+
auto session_id = context_->storage->mutable_etm_v4_session_table()
147+
->Insert({config_id_, start_ts})
148+
.id;
149+
session_.emplace(session_id);
150+
151+
if (start_ts) {
152+
static constexpr auto kETMSessionBlueprint =
153+
tracks::CounterBlueprint("etm_session", tracks::UnknownUnitBlueprint(),
154+
tracks::DimensionBlueprints(),
155+
tracks::StaticNameBlueprint("ETMSession"));
156+
TrackId track_id =
157+
context_->track_tracker->InternTrack(kETMSessionBlueprint);
158+
context_->event_tracker->PushCounter(
159+
start_ts.value(), static_cast<double>(session_id.value), track_id);
160+
}
145161
}
146162

147163
void EtmV4Stream::AddChunk(TraceBlobView chunk) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (C) 2025 The Android Open Source Project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import {Trace} from '../../public/trace';
16+
import {PerfettoPlugin} from '../../public/plugin';
17+
18+
import {createQueryCounterTrack} from '../../components/tracks/query_counter_track';
19+
import {TrackNode} from '../../public/workspace';
20+
21+
export default class implements PerfettoPlugin {
22+
static readonly id = 'org.chromium.ETM';
23+
24+
async onTraceLoad(trace: Trace) {
25+
const title = 'ETM Session ID';
26+
const uri = `${trace.pluginId}#ETMSessionID`;
27+
const query =
28+
'select ts, value from counter inner join ' +
29+
'counter_track on counter_track.id = counter.track_id ' +
30+
'where name = "ETMSession"';
31+
32+
const renderer = await createQueryCounterTrack({
33+
trace,
34+
uri,
35+
data: {
36+
sqlSource: query,
37+
},
38+
});
39+
40+
trace.tracks.registerTrack({
41+
uri,
42+
renderer,
43+
description: 'Track to show current ETM session on timeline',
44+
});
45+
46+
const group = new TrackNode({
47+
name: 'ETM',
48+
isSummary: true,
49+
});
50+
51+
const trackNode = new TrackNode({uri, name: title});
52+
group.addChildInOrder(trackNode);
53+
trace.workspace.addChildInOrder(group);
54+
}
55+
}

0 commit comments

Comments
 (0)