Skip to content

Commit

Permalink
Merge "ui: make ftrace track 10x faster" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
primiano authored and Gerrit Code Review committed Nov 15, 2024
2 parents 7fd6cc4 + 6aa8ad4 commit 0fd224e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ef239fe1e10e3b830f7adf9b5b8f96a52c69a50e6d879cfb5a873cd26caab769
ae6623f3d00536a815ad76c40c5933845a436e6e8acee6349d0e925c06d0b6b0
49 changes: 21 additions & 28 deletions ui/src/plugins/dev.perfetto.Ftrace/ftrace_track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ import {TrackRenderContext} from '../../public/track';

const MARGIN = 2;
const RECT_HEIGHT = 18;
const RECT_WIDTH = 8;
const TRACK_HEIGHT = RECT_HEIGHT + 2 * MARGIN;

export interface Data extends TrackData {
timestamps: BigInt64Array;
names: string[];
interface Data extends TrackData {
events: Array<{
timestamp: time;
color: string;
}>;
}

export interface Config {
Expand Down Expand Up @@ -92,21 +95,22 @@ export class FtraceRawTrack implements Track {
order by tsQuant limit ${LIMIT};`);

const rowCount = queryRes.numRows();
const result: Data = {

const it = queryRes.iter({tsQuant: LONG, name: STR});
const events = [];
for (let row = 0; it.valid(); it.next(), row++) {
events.push({
timestamp: Time.fromRaw(it.tsQuant),
color: colorForFtrace(it.name).base.cssString,
});
}
return {
start,
end,
resolution,
length: rowCount,
timestamps: new BigInt64Array(rowCount),
names: [],
events,
};

const it = queryRes.iter({tsQuant: LONG, name: STR});
for (let row = 0; it.valid(); it.next(), row++) {
result.timestamps[row] = it.tsQuant;
result.names[row] = it.name;
}
return result;
}

render({ctx, size, timescale}: TrackRenderContext): void {
Expand All @@ -125,21 +129,10 @@ export class FtraceRawTrack implements Track {
dataStartPx,
dataEndPx,
);

const diamondSideLen = RECT_HEIGHT / Math.sqrt(2);

for (let i = 0; i < data.timestamps.length; i++) {
const name = data.names[i];
ctx.fillStyle = colorForFtrace(name).base.cssString;
const timestamp = Time.fromRaw(data.timestamps[i]);
const xPos = Math.floor(timescale.timeToPx(timestamp));

// Draw a diamond over the event
ctx.save();
ctx.translate(xPos, MARGIN);
ctx.rotate(Math.PI / 4);
ctx.fillRect(0, 0, diamondSideLen, diamondSideLen);
ctx.restore();
for (const e of data.events) {
ctx.fillStyle = e.color;
const xPos = Math.floor(timescale.timeToPx(e.timestamp));
ctx.fillRect(xPos - RECT_WIDTH / 2, MARGIN, RECT_WIDTH, RECT_HEIGHT);
}
}
}

0 comments on commit 0fd224e

Please sign in to comment.