Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {
} from '../../components/aggregation_adapter';
import {AreaSelection} from '../../public/selection';
import {Engine} from '../../trace_processor/engine';
import {LONG, NUM, STR_NULL} from '../../trace_processor/query_result';
import {
LONG,
NUM,
NUM_NULL,
STR_NULL,
} from '../../trace_processor/query_result';
import {createPerfettoTable} from '../../trace_processor/sql_utils';

export class SliceSelectionAggregator implements Aggregator {
readonly id = 'slice_aggregation';
Expand All @@ -32,6 +38,7 @@ export class SliceSelectionAggregator implements Aggregator {
name: STR_NULL,
ts: LONG,
dur: LONG,
parent_id: NUM_NULL,
});

if (!dataset) return undefined;
Expand All @@ -44,14 +51,32 @@ export class SliceSelectionAggregator implements Aggregator {
area.start,
area.end,
);

// Build a table containing the sums of all child slices for each parent
// slice. We can subtract this later from the parent's wall duration to
// calculate the parent's self time.
await using childSliceSelfTime = await createPerfettoTable({
engine,
as: `
SELECT
parent_id AS id,
SUM(dur) AS child_dur
FROM (${iiTable.name})
WHERE parent_id IS NOT NULL
GROUP BY parent_id
`,
Comment thread
stevegolton marked this conversation as resolved.
Resolved
});

await engine.query(`
create or replace perfetto table ${this.id} as
select
name,
sum(dur) AS total_dur,
sum(dur)/count() as avg_dur,
count() as occurrences
count() as occurrences,
SUM(dur - COALESCE(child_dur, 0)) AS total_self_dur
from (${iiTable.name})
LEFT JOIN ${childSliceSelfTime.name} USING(id)
group by name
`);

Expand Down Expand Up @@ -82,6 +107,12 @@ export class SliceSelectionAggregator implements Aggregator {
columnId: 'total_dur',
sum: true,
},
{
title: 'Self duration',
formatHint: 'DURATION_NS',
columnId: 'total_self_dur',
sum: true,
},
{
title: 'Avg Wall duration',
formatHint: 'DURATION_NS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const schema = {
category: STR_NULL,
correlation_id: STR_NULL,
arg_set_id: NUM_NULL,
parent_id: NUM_NULL,
};

export async function createTraceProcessorSliceTrack({
Expand Down Expand Up @@ -117,7 +118,8 @@ async function getDataset(engine: Engine, trackIds: ReadonlyArray<number>) {
track_id,
category,
extract_arg(arg_set_id, 'correlation_id') as correlation_id,
arg_set_id
arg_set_id,
parent_id
from slice
`,
filter: {
Expand Down Expand Up @@ -154,7 +156,8 @@ async function getDataset(engine: Engine, trackIds: ReadonlyArray<number>) {
track_id,
category,
extract_arg(arg_set_id, 'correlation_id') as correlation_id,
arg_set_id
arg_set_id,
parent_id
from slice
join ${tableName} d using (id)
`,
Expand Down