Skip to content

Commit 1891593

Browse files
committed
Generalize section rendering in pipeline graph
1 parent 8cacc02 commit 1891593

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/cargo/core/compiler/timings.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const BG_COLOR = getCssColor('--background');
6666
const CANVAS_BG = getCssColor('--canvas-background');
6767
const AXES_COLOR = getCssColor('--canvas-axes');
6868
const GRID_COLOR = getCssColor('--canvas-grid');
69-
const BLOCK_COLOR = getCssColor('--canvas-block');
69+
const CODEGEN_COLOR = getCssColor('--canvas-codegen');
7070
const CUSTOM_BUILD_COLOR = getCssColor('--canvas-custom-build');
7171
const NOT_CUSTOM_BUILD_COLOR = getCssColor('--canvas-not-custom-build');
7272
const DEP_LINE_COLOR = getCssColor('--canvas-dep-line');
@@ -134,12 +134,17 @@ function render_pipeline_graph() {
134134
let unit = units[i];
135135
let y = i * Y_TICK_DIST + 1;
136136
let x = px_per_sec * unit.start;
137-
let rmeta_x = null;
137+
138+
const sections = [];
138139
if (unit.rmeta_time != null) {
139-
rmeta_x = x + px_per_sec * unit.rmeta_time;
140+
sections.push({
141+
name: "codegen",
142+
start: x + px_per_sec * unit.rmeta_time,
143+
width: (unit.duration - unit.rmeta_time) * px_per_sec
144+
});
140145
}
141146
let width = Math.max(px_per_sec * unit.duration, 1.0);
142-
UNIT_COORDS[unit.i] = {x, y, width, rmeta_x};
147+
UNIT_COORDS[unit.i] = {x, y, width, sections};
143148

144149
const count = unitCount.get(unit.name) || 0;
145150
unitCount.set(unit.name, count + 1);
@@ -148,7 +153,7 @@ function render_pipeline_graph() {
148153
// Draw the blocks.
149154
for (i=0; i<units.length; i++) {
150155
let unit = units[i];
151-
let {x, y, width, rmeta_x} = UNIT_COORDS[unit.i];
156+
let {x, y, width, sections} = UNIT_COORDS[unit.i];
152157

153158
HIT_BOXES.push({x: X_LINE+x, y:MARGIN+y, x2: X_LINE+x+width, y2: MARGIN+y+BOX_HEIGHT, i: unit.i});
154159

@@ -157,12 +162,11 @@ function render_pipeline_graph() {
157162
roundedRect(ctx, x, y, width, BOX_HEIGHT, RADIUS);
158163
ctx.fill();
159164

160-
if (unit.rmeta_time != null) {
161-
ctx.beginPath();
162-
ctx.fillStyle = BLOCK_COLOR;
163-
let ctime = unit.duration - unit.rmeta_time;
164-
roundedRect(ctx, rmeta_x, y, px_per_sec * ctime, BOX_HEIGHT, RADIUS);
165-
ctx.fill();
165+
for (const section of sections) {
166+
ctx.beginPath();
167+
ctx.fillStyle = get_section_color(section.name);
168+
roundedRect(ctx, section.start, y, section.width, BOX_HEIGHT, RADIUS);
169+
ctx.fill();
166170
}
167171
ctx.fillStyle = TEXT_COLOR;
168172
ctx.textAlign = 'start';
@@ -180,6 +184,16 @@ function render_pipeline_graph() {
180184
ctx.restore();
181185
}
182186

187+
// Determine the color of a section block based on the section name.
188+
function get_section_color(name) {
189+
if (name === "codegen") {
190+
return CODEGEN_COLOR;
191+
} else {
192+
// We do not know what section this is, so just use the default color
193+
return NOT_CUSTOM_BUILD_COLOR;
194+
}
195+
}
196+
183197
// Draws lines from the given unit to the units it unlocks.
184198
function draw_dep_lines(ctx, unit_idx, highlighted) {
185199
const unit = UNIT_DATA[unit_idx];

src/cargo/core/compiler/timings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ static HTML_TMPL: &str = r#"
870870
--canvas-background: #f7f7f7;
871871
--canvas-axes: #303030;
872872
--canvas-grid: #e6e6e6;
873-
--canvas-block: #aa95e8;
873+
--canvas-codegen: #aa95e8;
874874
--canvas-custom-build: #f0b165;
875875
--canvas-not-custom-build: #95cce8;
876876
--canvas-dep-line: #ddd;

0 commit comments

Comments
 (0)