Skip to content

Commit

Permalink
Merge "ui: Switch to a more "OO" implementation for Dataset" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
stevegolton authored and Gerrit Code Review committed Nov 18, 2024
2 parents db8ab06 + 4bd51f1 commit 46b6a1f
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 323 deletions.
8 changes: 4 additions & 4 deletions ui/src/frontend/base_slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {AsyncDisposableStack} from '../base/disposable_stack';
import {TrackMouseEvent, TrackRenderContext} from '../public/track';
import {Point2D, VerticalBounds} from '../base/geom';
import {Trace} from '../public/trace';
import {Ds} from '../trace_processor/dataset';
import {SourceDataset, Dataset} from '../trace_processor/dataset';

// The common class that underpins all tracks drawing slices.

Expand Down Expand Up @@ -974,15 +974,15 @@ export abstract class BaseSliceTrack<
return {ts: Time.fromRaw(row.ts), dur: Duration.fromRaw(row.dur)};
}

getDataset(): Ds.Dataset | undefined {
return {
getDataset(): Dataset | undefined {
return new SourceDataset({
src: this.getSqlSource(),
schema: {
id: NUM,
ts: LONG,
dur: LONG,
},
};
});
}
}

Expand Down
8 changes: 4 additions & 4 deletions ui/src/frontend/named_slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {NewTrackArgs} from './track';
import {renderDuration} from './widgets/duration';
import {TraceImpl} from '../core/trace_impl';
import {assertIsInstance} from '../base/logging';
import {Ds} from '../trace_processor/dataset';
import {SourceDataset, Dataset} from '../trace_processor/dataset';

export const NAMED_ROW = {
// Base columns (tsq, ts, dur, id, depth).
Expand Down Expand Up @@ -82,15 +82,15 @@ export abstract class NamedSliceTrack<
return new ThreadSliceDetailsPanel(assertIsInstance(this.trace, TraceImpl));
}

override getDataset(): Ds.Dataset | undefined {
return {
override getDataset(): Dataset | undefined {
return new SourceDataset({
src: this.getSqlSource(),
schema: {
id: NUM,
name: STR,
ts: LONG,
dur: LONG,
},
};
});
}
}
8 changes: 4 additions & 4 deletions ui/src/plugins/dev.perfetto.AsyncSlices/async_slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

import {BigintMath as BIMath} from '../../base/bigint_math';
import {clamp} from '../../base/math_utils';
import {Ds} from '../../trace_processor/dataset';
import {NAMED_ROW, NamedSliceTrack} from '../../frontend/named_slice_track';
import {SLICE_LAYOUT_FIT_CONTENT_DEFAULTS} from '../../frontend/slice_layout';
import {NewTrackArgs} from '../../frontend/track';
import {TrackEventDetails} from '../../public/selection';
import {Slice} from '../../public/track';
import {SourceDataset, Dataset} from '../../trace_processor/dataset';
import {
LONG,
LONG_NULL,
Expand Down Expand Up @@ -112,8 +112,8 @@ export class AsyncSliceTrack extends NamedSliceTrack<Slice, ThreadSliceRow> {
};
}

override getDataset(): Ds.Dataset {
return {
override getDataset(): Dataset {
return new SourceDataset({
src: `slice`,
filter: {
col: 'track_id',
Expand All @@ -126,6 +126,6 @@ export class AsyncSliceTrack extends NamedSliceTrack<Slice, ThreadSliceRow> {
dur: LONG,
parent_id: NUM_NULL,
},
};
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {ColumnDef, Sorting} from '../../public/aggregation';
import {AreaSelection} from '../../public/selection';
import {Engine} from '../../trace_processor/engine';
import {AreaSelectionAggregator} from '../../public/selection';
import {Ds} from '../../trace_processor/dataset';
import {UnionDataset} from '../../trace_processor/dataset';
import {LONG, NUM, STR} from '../../trace_processor/query_result';

export class SliceSelectionAggregator implements AreaSelectionAggregator {
Expand All @@ -30,21 +30,21 @@ export class SliceSelectionAggregator implements AreaSelectionAggregator {
dur: LONG,
};
const validDatasets = area.tracks
.map((t) => t.track.getDataset?.())
.filter((d) => d !== undefined)
.filter((d) => Ds.doesImplement(d, desiredSchema));
.map((track) => track.track.getDataset?.())
.filter((ds) => ds !== undefined)
.filter((ds) => ds.implements(desiredSchema));
if (validDatasets.length === 0) {
return false;
}
const optimizedDataset = Ds.optimize({union: validDatasets});
const unionDataset = new UnionDataset(validDatasets);
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
from (${Ds.query(optimizedDataset)})
from (${unionDataset.optimize().query()})
where
ts + dur > ${area.start}
and ts < ${area.end}
Expand Down
8 changes: 4 additions & 4 deletions ui/src/plugins/dev.perfetto.Ftrace/ftrace_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {LONG, NUM, STR} from '../../trace_processor/query_result';
import {FtraceFilter} from './common';
import {Monitor} from '../../base/monitor';
import {TrackRenderContext} from '../../public/track';
import {Ds} from '../../trace_processor/dataset';
import {SourceDataset, Dataset} from '../../trace_processor/dataset';

const MARGIN = 2;
const RECT_HEIGHT = 18;
Expand Down Expand Up @@ -57,8 +57,8 @@ export class FtraceRawTrack implements Track {
this.monitor = new Monitor([() => store.state]);
}

getDataset(): Ds.Dataset {
return {
getDataset(): Dataset {
return new SourceDataset({
// 'ftrace_event' doesn't have a dur column, but injecting dur=0 (all
// ftrace events are effectively 'instant') allows us to participate in
// generic slice aggregations
Expand All @@ -73,7 +73,7 @@ export class FtraceRawTrack implements Track {
col: 'cpu',
eq: this.cpu,
},
};
});
}

async onUpdate({
Expand Down
4 changes: 2 additions & 2 deletions ui/src/public/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {HighPrecisionTimeSpan} from '../base/high_precision_time_span';
import {ColorScheme} from './color_scheme';
import {TrackEventDetailsPanel} from './details_panel';
import {TrackEventDetails, TrackEventSelection} from './selection';
import {Ds} from '../trace_processor/dataset';
import {Dataset} from '../trace_processor/dataset';

export interface TrackManager {
/**
Expand Down Expand Up @@ -179,7 +179,7 @@ export interface Track {
* Optional: Returns a dataset that represents the events displayed on this
* track.
*/
getDataset?(): Ds.Dataset | undefined;
getDataset?(): Dataset | undefined;

/**
* Optional: Get details of a track event given by eventId on this track.
Expand Down
Loading

0 comments on commit 46b6a1f

Please sign in to comment.