diff --git a/src/cargo/core/compiler/timings.js b/src/cargo/core/compiler/timings.js index 24f4bae5a7e..170827363a2 100644 --- a/src/cargo/core/compiler/timings.js +++ b/src/cargo/core/compiler/timings.js @@ -44,15 +44,14 @@ 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, canvas_width, canvas_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; + container.style.width = canvas_width; + container.style.height = canvas_height; // Canvas for hover highlights. This is a separate layer to improve performance. - const linectx = setup_canvas('pipeline-graph-lines', width, height); - linectx.clearRect(0, 0, width, height); + const linectx = setup_canvas('pipeline-graph-lines', canvas_width, canvas_height); + linectx.clearRect(0, 0, canvas_width, canvas_height); // Draw Y tick marks. for (let n=1; n 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(canvas_width-200, MARGIN); // background ctx.fillStyle = '#fff'; ctx.strokeStyle = '#000'; @@ -289,13 +293,18 @@ 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 height = graph_height + MARGIN + Y_LINE; - let ctx = setup_canvas(id, width, height); + 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 canvas_width = Math.max(graph_width + X_LINE + 30, X_LINE + 250); + const canvas_height = graph_height + MARGIN + Y_LINE; + let ctx = setup_canvas(id, canvas_width, canvas_height); ctx.fillStyle = '#f7f7f7'; - ctx.fillRect(0, 0, width, height); + ctx.fillRect(0, 0, canvas_width, canvas_height); ctx.lineWidth = 2; ctx.font = '16px sans-serif'; @@ -309,19 +318,18 @@ 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];