From 67ef2cb03493eec3515bbb56f889c21c91e3a76b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 20 Sep 2019 16:06:56 -0700 Subject: [PATCH] Fix some rendering issues with -Ztimings. - Cap the max width to 4096. This is still quite large, but should help for some large graphs failing to display for using too much memory. - Don't allow labels to overflow past the right side of the graph. - Fix issue for very fast builds causing an error because there aren't enough CPU_USAGE entries. - Fix bug where `split_ticks` would enter an infinite loop (caused by small scale values). Added a counter to abort in case there are any other bugs. --- src/cargo/core/compiler/timings.js | 68 ++++++++++++++++++------------ 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/cargo/core/compiler/timings.js b/src/cargo/core/compiler/timings.js index 24f4bae5a7e..ba04945263f 100644 --- a/src/cargo/core/compiler/timings.js +++ b/src/cargo/core/compiler/timings.js @@ -44,11 +44,10 @@ function render_pipeline_graph() { const units = UNIT_DATA.filter(unit => unit.duration >= min_time); const graph_height = Y_TICK_DIST * units.length; - const {ctx, width, height} = draw_graph_axes('pipeline-graph', graph_height); + const {ctx, graph_width, width, height, px_per_sec} = draw_graph_axes('pipeline-graph', graph_height); const container = document.getElementById('pipeline-container'); container.style.width = width; container.style.height = height; - const PX_PER_SEC = document.getElementById('scale').valueAsNumber; // Canvas for hover highlights. This is a separate layer to improve performance. const linectx = setup_canvas('pipeline-graph-lines', width, height); @@ -79,12 +78,12 @@ function render_pipeline_graph() { for (i=0; i 1) { + ctx.beginPath(); + ctx.fillStyle = cpuFillStyle; + let bottomLeft = coord(CPU_USAGE[0][0], 0); + ctx.moveTo(bottomLeft.x, bottomLeft.y); + for (let i=0; i < CPU_USAGE.length; i++) { + let [time, usage] = CPU_USAGE[i]; + let {x, y} = coord(time, usage / 100.0 * max_v); + ctx.lineTo(x, y); + } + let bottomRight = coord(CPU_USAGE[CPU_USAGE.length - 1][0], 0); + ctx.lineTo(bottomRight.x, bottomRight.y); + ctx.fill(); } - let bottomRight = coord(CPU_USAGE[CPU_USAGE.length - 1][0], 0); - ctx.lineTo(bottomRight.x, bottomRight.y); - ctx.fill(); function draw_line(style, key) { let first = CONCURRENCY_DATA[0]; @@ -231,7 +235,7 @@ function render_timing_graph() { // Draw a legend. ctx.restore(); ctx.save(); - ctx.translate(graph_width-150, MARGIN); + ctx.translate(width-200, MARGIN); // background ctx.fillStyle = '#fff'; ctx.strokeStyle = '#000'; @@ -289,9 +293,14 @@ function setup_canvas(id, width, height) { } function draw_graph_axes(id, graph_height) { - const PX_PER_SEC = document.getElementById('scale').valueAsNumber; - const graph_width = PX_PER_SEC * DURATION; - const width = graph_width + X_LINE + 30; + const scale = document.getElementById('scale').valueAsNumber; + // Cap the size of the graph. It is hard to view if it is too large, and + // browsers may not render a large graph because it takes too much memory. + // 4096 is still ridiculously large, and probably won't render on mobile + // browsers, but should be ok for many desktop environments. + const graph_width = Math.min(scale * DURATION, 4096); + const px_per_sec = Math.floor(graph_width / DURATION); + const width = Math.max(graph_width + X_LINE + 30, X_LINE + 250); const height = graph_height + MARGIN + Y_LINE; let ctx = setup_canvas(id, width, height); ctx.fillStyle = '#f7f7f7'; @@ -309,10 +318,9 @@ function draw_graph_axes(id, graph_height) { ctx.stroke(); // Draw X tick marks. - const tick_width = graph_width - 10; - const [step, top] = split_ticks(DURATION, tick_width / MIN_TICK_DIST); + const [step, top] = split_ticks(DURATION, graph_width / MIN_TICK_DIST); const num_ticks = top / step; - const tick_dist = tick_width / num_ticks; + const tick_dist = graph_width / num_ticks; ctx.fillStyle = '#303030'; for (let n=0; n 100) { + throw Error("tick loop too long"); + } + count += 1; let top = round_up(n, step); if (top <= max_ticks * step) { return [step, top];