Skip to content

Commit

Permalink
ui: Use dataset for CPU slice aggregations
Browse files Browse the repository at this point in the history
Change-Id: I0bc128249bcf3e242213ae06710471fd94dd8a63
  • Loading branch information
stevegolton committed Dec 24, 2024
1 parent 7382b86 commit a9b2459
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {exists} from '../../base/utils';
import {ColumnDef, Sorting} from '../../public/aggregation';
import {AreaSelection} from '../../public/selection';
import {Engine} from '../../trace_processor/engine';
import {CPU_SLICE_TRACK_KIND} from '../../public/track_kinds';
import {AreaSelectionAggregator} from '../../public/selection';
import {Dataset} from '../../trace_processor/dataset';
import {LONG, NUM} from '../../trace_processor/query_result';

export class CpuSliceByProcessSelectionAggregator
implements AreaSelectionAggregator
{
readonly id = 'cpu_by_process_aggregation';
readonly trackKind = CPU_SLICE_TRACK_KIND;
readonly schema = {
dur: LONG,
ts: LONG,
utid: NUM,
} as const;

async createAggregateView(engine: Engine, area: AreaSelection) {
const selectedCpus: number[] = [];
for (const trackInfo of area.tracks) {
if (trackInfo?.tags?.kind === CPU_SLICE_TRACK_KIND) {
exists(trackInfo.tags.cpu) && selectedCpus.push(trackInfo.tags.cpu);
}
}
if (selectedCpus.length === 0) return false;
async createAggregateView(
engine: Engine,
area: AreaSelection,
dataset?: Dataset,
) {
if (!dataset) return false;

await engine.query(`
create or replace perfetto table ${this.id} as
Expand All @@ -41,14 +46,12 @@ export class CpuSliceByProcessSelectionAggregator
sum(dur) AS total_dur,
sum(dur) / count() as avg_dur,
count() as occurrences
from sched
from (${dataset.query()})
join thread USING (utid)
join process USING (upid)
where
cpu in (${selectedCpus})
and ts + dur > ${area.start}
ts + dur > ${area.start}
and ts < ${area.end}
and utid != 0
group by upid
`);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {exists} from '../../base/utils';
import {ColumnDef, Sorting} from '../../public/aggregation';
import {AreaSelection} from '../../public/selection';
import {CPU_SLICE_TRACK_KIND} from '../../public/track_kinds';
import {Engine} from '../../trace_processor/engine';
import {AreaSelectionAggregator} from '../../public/selection';
import {LONG, NUM} from '../../trace_processor/query_result';
import {Dataset} from '../../trace_processor/dataset';

export class CpuSliceSelectionAggregator implements AreaSelectionAggregator {
readonly id = 'cpu_aggregation';
readonly trackKind = CPU_SLICE_TRACK_KIND;
readonly schema = {
dur: LONG,
ts: LONG,
utid: NUM,
} as const;

async createAggregateView(engine: Engine, area: AreaSelection) {
const selectedCpus: number[] = [];
for (const trackInfo of area.tracks) {
if (trackInfo?.tags?.kind === CPU_SLICE_TRACK_KIND) {
exists(trackInfo.tags.cpu) && selectedCpus.push(trackInfo.tags.cpu);
}
}
if (selectedCpus.length === 0) return false;
async createAggregateView(
engine: Engine,
area: AreaSelection,
dataset?: Dataset,
) {
if (!dataset) return false;

await engine.query(`
create or replace perfetto table ${this.id} as
Expand All @@ -43,11 +48,10 @@ export class CpuSliceSelectionAggregator implements AreaSelectionAggregator {
count() as occurrences
from process
join thread using (upid)
join sched using (utid)
where cpu in (${selectedCpus})
and sched.ts + sched.dur > ${area.start}
join (${dataset.query()}) as sched using (utid)
where
sched.ts + sched.dur > ${area.start}
and sched.ts < ${area.end}
and utid != 0
group by utid
`);
return true;
Expand Down
7 changes: 6 additions & 1 deletion ui/src/plugins/dev.perfetto.CpuSlices/cpu_slice_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ export class CpuSliceTrack implements Track {

getDataset(): Dataset | undefined {
return new SourceDataset({
src: 'select id, ts, dur, cpu from sched where utid != 0',
// TODO(stevegolton): Once we allow datasets to have more than one filter,
// move this where clause to a dataset filter and change this src to
// 'sched'.
src: 'select id, ts, dur, cpu, utid from sched where utid != 0',
schema: {
id: NUM,
ts: LONG,
dur: LONG,
cpu: NUM,
utid: NUM,
},
filter: {
col: 'cpu',
Expand Down

0 comments on commit a9b2459

Please sign in to comment.