Skip to content

Commit

Permalink
Merge "Add classloading insights to the Perfetto app startup plugin."…
Browse files Browse the repository at this point in the history
… into main
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Feb 18, 2025
2 parents 707752f + 3ce9244 commit 4ce2473
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,29 @@ SELECT slice_id, slice_name, slice_ts, slice_dur, thread_name, tid, arg_set_id
FROM android_thread_slices_for_all_startups
WHERE startup_id = $startup_id AND slice_name GLOB $slice_name;

-- A Perfetto view that lists matching slices for class loading during app startup.
CREATE PERFETTO VIEW android_class_loading_for_startup(
-- Id of the slice.
slice_id JOINID(slice.id),
-- Startup id.
startup_id LONG,
-- Name of the slice.
slice_name STRING,
-- Timestamp of start of the slice.
slice_ts TIMESTAMP,
-- Duration of the slice.
slice_dur DURATION,
-- Name of the thread with the slice.
thread_name STRING,
-- Tid of the thread with the slice.
tid LONG,
-- Arg set id.
arg_set_id ARGSETID
) AS
SELECT slice_id, startup_id, slice_name, slice_ts, slice_dur, thread_name, tid, arg_set_id
FROM android_thread_slices_for_all_startups
WHERE slice_name GLOB "L*;";

-- Returns binder transaction slices for a given startup id with duration over threshold.
CREATE PERFETTO FUNCTION android_binder_transaction_slices_for_startup(
-- Startup id.
Expand Down
34 changes: 34 additions & 0 deletions ui/src/plugins/dev.perfetto.AndroidStartup/optimizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function optimizationsTrack(
trace: Trace,
): Promise<TrackNode | undefined> {
const startups: Array<Startup> = [];
const classLoadingTracks: Array<Promise<TrackNode>> = [];

// Find app startups
let result = await trace.engine.query(
Expand Down Expand Up @@ -95,6 +96,8 @@ export async function optimizationsTrack(
}
}
}
const childTrack = classLoadingTrack(trace, startup);
classLoadingTracks.push(childTrack);
}

// Create the optimizations track and also avoid re-querying for the data we already have.
Expand Down Expand Up @@ -125,6 +128,37 @@ export async function optimizationsTrack(
title,
track,
});
const trackNode = new TrackNode({title, uri});
for await (const classLoadingTrack of classLoadingTracks) {
trackNode.addChildLast(classLoadingTrack);
}
return trackNode;
}

async function classLoadingTrack(
trace: Trace,
startup: Startup,
): Promise<TrackNode> {
const sqlSource = `
SELECT slice_ts as ts, slice_dur as dur, slice_name AS name FROM
android_class_loading_for_startup
WHERE startup_id = ${startup.id}
`;
const uri = `/android_startups/${startup.id}/classloading`;
const title = `Classloading for (${startup.package})`;
const track = await createQuerySliceTrack({
trace: trace,
uri: uri,
data: {
sqlSource: sqlSource,
columns: ['ts', 'dur', 'name'],
},
});
trace.tracks.registerTrack({
uri,
title,
track,
});
return new TrackNode({title, uri});
}

Expand Down

0 comments on commit 4ce2473

Please sign in to comment.