Skip to content

Commit

Permalink
Disambiguate duplicate unit names using versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelin01 committed Jul 31, 2023
1 parent 7669a7c commit da0fab3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/cargo/core/compiler/timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ function render_pipeline_graph() {
ctx.translate(X_LINE, MARGIN);

// Compute x,y coordinate of each block.
// We also populate a map with the count of each unit name to disambiguate if necessary
const unitCount = new Map();
UNIT_COORDS = {};
for (i=0; i<units.length; i++) {
let unit = units[i];
Expand All @@ -86,6 +88,10 @@ function render_pipeline_graph() {
}
let width = Math.max(px_per_sec * unit.duration, 1.0);
UNIT_COORDS[unit.i] = {x, y, width, rmeta_x};

const tag = `${unit.name}${unit.target}`;
const count = unitCount.get(tag) || 0;
unitCount.set(tag, count + 1);
}

// Draw the blocks.
Expand All @@ -111,7 +117,11 @@ function render_pipeline_graph() {
ctx.textAlign = 'start';
ctx.textBaseline = 'middle';
ctx.font = '14px sans-serif';
const label = `${unit.name} v${unit.version}${unit.target} ${unit.duration}s`;

const tag = `${unit.name}${unit.target}`;
const labelName = (unitCount.get(tag) || 0) > 1 ? `${unit.name} v${unit.version}${unit.target}` : tag;
const label = `${labelName} ${unit.duration}s`;

const text_info = ctx.measureText(label);
const label_x = Math.min(x + 5.0, canvas_width - text_info.width - X_LINE);
ctx.fillText(label, label_x, y + BOX_HEIGHT / 2);
Expand Down

0 comments on commit da0fab3

Please sign in to comment.