Skip to content

Commit

Permalink
Merge "ui: Make the overview timeline fast again" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
primiano authored and Gerrit Code Review committed Nov 27, 2023
2 parents 30f23f7 + 065ea24 commit fa9c2df
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions ui/src/controller/trace_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,39 +780,43 @@ export class TraceController extends Controller<States> {

private async loadTimelineOverview(trace: Span<time, duration>) {
clearOverviewData();

const engine = assertExists<Engine>(this.engine);
const stepSize = Duration.max(1n, trace.duration / 100n);
let hasSchedOverview = false;
for (let start = trace.start; start < trace.end;
start = Time.add(start, stepSize)) {
const progress = start - trace.start;
const ratio = Number(progress) / Number(trace.duration);
this.updateStatus(
'Loading overview ' +
`${Math.round(ratio * 100)}%`);
const end = Time.add(start, stepSize);

// Sched overview.
const schedResult = await engine.query(
`select cast(sum(dur) as float)/${
stepSize} as load, cpu from sched ` +
`where ts >= ${start} and ts < ${end} and utid != 0 ` +
'group by cpu order by cpu');
const schedData: {[key: string]: QuantizedLoad} = {};
const it = schedResult.iter({load: NUM, cpu: NUM});
for (; it.valid(); it.next()) {
const load = it.load;
const cpu = it.cpu;
schedData[cpu] = {start, end, load};
hasSchedOverview = true;
}
publishOverviewData(schedData);
}

const hasSchedSql = 'select ts from sched limit 1';
const hasSchedOverview = (await engine.query(hasSchedSql)).numRows() > 0;
if (hasSchedOverview) {
const stepPromises = [];
for (let start = trace.start; start < trace.end;
start = Time.add(start, stepSize)) {
const progress = start - trace.start;
const ratio = Number(progress) / Number(trace.duration);
this.updateStatus(
'Loading overview ' +
`${Math.round(ratio * 100)}%`);
const end = Time.add(start, stepSize);
// The (async() => {})() queues all the 100 async promises in one batch.
// Without that, we would wait for each step to be rendered before
// kicking off the next one. That would interleave an animation frame
// between each step, slowing down significantly the overall process.
stepPromises.push((async () => {
const schedResult = await engine.query(
`select cast(sum(dur) as float)/${
stepSize} as load, cpu from sched ` +
`where ts >= ${start} and ts < ${end} and utid != 0 ` +
'group by cpu order by cpu');
const schedData: {[key: string]: QuantizedLoad} = {};
const it = schedResult.iter({load: NUM, cpu: NUM});
for (; it.valid(); it.next()) {
const load = it.load;
const cpu = it.cpu;
schedData[cpu] = {start, end, load};
}
publishOverviewData(schedData);
})());
} // for(start = ...)
await Promise.all(stepPromises);
return;
}
} // if (hasSchedOverview)

// Slices overview.
const sliceResult = await engine.query(`select
Expand Down

0 comments on commit fa9c2df

Please sign in to comment.