Skip to content

Commit

Permalink
Merge "Show slices from atom_counters_slices in the UX." into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon MacMullen authored and Gerrit Code Review committed Oct 24, 2024
2 parents 23f82f5 + 0296ee4 commit b374ca7
Showing 1 changed file with 74 additions and 1 deletion.
75 changes: 74 additions & 1 deletion ui/src/plugins/dev.perfetto.AndroidLongBatteryTracing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,78 @@ class AndroidLongBatteryTracing implements PerfettoPlugin {
}
}

async addAtomSlices(ctx: Trace): Promise<void> {
const e = ctx.engine;

try {
await e.query(
`INCLUDE PERFETTO MODULE
google3.wireless.android.telemetry.trace_extractor.modules.atom_counters_slices`,
);
} catch (e) {
return;
}

const sliceTracks = await e.query(
`select distinct ui_group, ui_name, atom, field
from atom_slices
where ui_name is not null
order by 1, 2, 3, 4`,
);
const slicesIt = sliceTracks.iter({
atom: 'str',
ui_group: 'str',
ui_name: 'str',
field: 'str',
});

const tracks = new Map<
string,
{
ui_group: string;
ui_name: string;
}
>();
const fields = new Map<string, string[]>();
for (; slicesIt.valid(); slicesIt.next()) {
const atom = slicesIt.atom;
let args = fields.get(atom);
if (args === undefined) {
args = [];
fields.set(atom, args);
}
args.push(slicesIt.field);
tracks.set(atom, {
ui_group: slicesIt.ui_group,
ui_name: slicesIt.ui_name,
});
}

for (const [atom, args] of fields) {
function safeArg(arg: string) {
return arg.replaceAll(/[[\]]/g, '').replaceAll(/\./g, '_');
}

// We need to make arg names compatible with SQL here because they pass through several
// layers of SQL without being quoted in "".
function argSql(arg: string) {
return `max(case when field = '${arg}' then ifnull(string_value, int_value) end)
as ${safeArg(arg)}`;
}

this.addSliceTrack(
ctx,
tracks.get(atom)!.ui_name,
`select ts, dur, slice_name as name, ${args.map((a) => argSql(a)).join(', ')}
from atom_slices
where atom = '${atom}'
group by ts, dur, name`,
tracks.get(atom)!.ui_group,
args.map((a) => safeArg(a)),
);
}
}

async addNetworkSummary(ctx: Trace, features: Set<string>): Promise<void> {
if (!features.has('net.modem') && !features.has('net.wifi')) {
return;
Expand Down Expand Up @@ -1823,13 +1895,14 @@ class AndroidLongBatteryTracing implements PerfettoPlugin {

await ctx.engine.query(PACKAGE_LOOKUP);
await this.addNetworkSummary(ctx, features);
await this.addBluetooth(ctx, features);
await this.addAtomCounters(ctx);
await this.addAtomSlices(ctx);
await this.addModemDetail(ctx, features);
await this.addKernelWakelocks(ctx, features);
await this.addWakeups(ctx, features);
await this.addDeviceState(ctx, features);
await this.addHighCpu(ctx, features);
await this.addBluetooth(ctx, features);
await this.addContainedTraces(ctx, containedTraces);
}

Expand Down

0 comments on commit b374ca7

Please sign in to comment.