Skip to content

Commit 63ec5e2

Browse files
committed
Auto merge of #12420 - Angelin01:timings-show-version, r=weihanglo
Display crate version on timings graph ### What does this PR try to resolve? Fixes #7384 The solution here is the simplest one: since duplicate crates with different versions can cause confusion, we always output the version. ### How should we test and review this PR? Build any create using the `--timings` option: ``` cargo build --timings ``` and verify the resulting HTML file. ### Additional information The formatting is consistent with how the crates are displayed in the terminal output for Cargo and also on the table below the graph. Initially, [this comment](#7384 (comment)) suggested said formatting for ease of searching, but I do believe the browser can't search in the graph itself. Sample console output: ``` Compiling lazycell v1.3.0 Compiling unicode-xid v0.2.4 Compiling unicode-width v0.1.10 Compiling glob v0.3.1 Compiling curl-sys v0.4.65+curl-8.2.1 Compiling curl v0.4.44 Compiling git2 v0.17.2 ``` Sample rendered HTML output: ![image](https://github.com/rust-lang/cargo/assets/17818024/23aae84e-5107-4352-8d0f-ecdfcac59187) ### Possible issues and future work A possible issue in this solution is that the output becomes too noisy. Other possible solutions: - Only display the version if there are two "units" with the same name. One possible implementation is to count the names, aggregate them in a simple map and look it up during rendering. - Create a small selection to select the disambiguate method between "Never", "Always" and "Only duplicates". This may be overkill.
2 parents 9a7c1fe + 28674b9 commit 63ec5e2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/cargo/core/compiler/timings.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ function render_pipeline_graph() {
7575
ctx.translate(X_LINE, MARGIN);
7676

7777
// Compute x,y coordinate of each block.
78+
// We also populate a map with the count of each unit name to disambiguate if necessary
79+
const unitCount = new Map();
7880
UNIT_COORDS = {};
7981
for (i=0; i<units.length; i++) {
8082
let unit = units[i];
@@ -86,6 +88,9 @@ function render_pipeline_graph() {
8688
}
8789
let width = Math.max(px_per_sec * unit.duration, 1.0);
8890
UNIT_COORDS[unit.i] = {x, y, width, rmeta_x};
91+
92+
const count = unitCount.get(unit.name) || 0;
93+
unitCount.set(unit.name, count + 1);
8994
}
9095

9196
// Draw the blocks.
@@ -111,7 +116,10 @@ function render_pipeline_graph() {
111116
ctx.textAlign = 'start';
112117
ctx.textBaseline = 'middle';
113118
ctx.font = '14px sans-serif';
114-
const label = `${unit.name}${unit.target} ${unit.duration}s`;
119+
120+
const labelName = (unitCount.get(unit.name) || 0) > 1 ? `${unit.name} (v${unit.version})${unit.target}` : `${unit.name}${unit.target}`;
121+
const label = `${labelName}: ${unit.duration}s`;
122+
115123
const text_info = ctx.measureText(label);
116124
const label_x = Math.min(x + 5.0, canvas_width - text_info.width - X_LINE);
117125
ctx.fillText(label, label_x, y + BOX_HEIGHT / 2);

0 commit comments

Comments
 (0)