var canvas;
var ctx;
var tooltip;
var min_scale;
var scale;
var offset_x = 0;
var offset_y = 0;
var size_y;
var dragging = false;
var previous_x = 0;
var previous_y = 0;
var bar_height = 15;
var line_height = bar_height + 2;
var thread_separation = 6;
var thread_font_size = 12;
var thread_font = thread_font_size + "px Arial";
var bar_font_size = 10;
var bar_font = bar_font_size + "px Arial";
var end_cycle = 0;
function drawChart()
{
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth = 1;
var y = offset_y;
for (var t = 0; t < threads.length; t++)
{
// Check if thread has samples
var thread = threads[t];
if (thread.start.length == 0)
continue;
// Draw thread name
y += thread_font_size;
ctx.font = thread_font;
ctx.fillStyle = "#000000";
ctx.fillText(thread.thread_name, 0, y);
y += thread_separation;
// Draw outlines for each bar of samples
ctx.fillStyle = "#c0c0c0";
for (var d = 0; d <= thread.max_depth; d++)
ctx.fillRect(0, y + d * line_height, canvas.width, bar_height);
// Draw samples
ctx.font = bar_font;
for (var s = 0; s < thread.start.length; s++)
{
// Cull bar
var rx = scale * (offset_x + thread.start[s]);
if (rx > canvas.width) // right of canvas
break;
var rw = scale * thread.cycles[s];
if (rw < 0.5) // less than half pixel, skip
continue;
if (rx + rw < 0) // left of canvas
continue;
// Draw bar
var ry = y + line_height * thread.depth[s];
ctx.fillStyle = thread.color[s];
ctx.fillRect(rx, ry, rw, bar_height);
ctx.strokeStyle = thread.darkened_color[s];
ctx.strokeRect(rx, ry, rw, bar_height);
// Get index in aggregated list
var a = thread.aggregator[s];
// Draw text
if (rw > aggregated.name_width[a])
{
ctx.fillStyle = "#000000";
ctx.fillText(aggregated.name[a], rx + (rw - aggregated.name_width[a]) / 2, ry + bar_height - 4);
}
}
// Next line
y += line_height * (1 + thread.max_depth) + thread_separation;
}
// Update size
size_y = y - offset_y;
}
function drawTooltip(mouse_x, mouse_y)
{
var y = offset_y;
for (var t = 0; t < threads.length; t++)
{
// Check if thread has samples
var thread = threads[t];
if (thread.start.length == 0)
continue;
// Thead name
y += thread_font_size + thread_separation;
// Draw samples
for (var s = 0; s < thread.start.length; s++)
{
// Cull bar
var rx = scale * (offset_x + thread.start[s]);
if (rx > mouse_x)
break;
var rw = scale * thread.cycles[s];
if (rx + rw < mouse_x)
continue;
var ry = y + line_height * thread.depth[s];
if (mouse_y >= ry && mouse_y < ry + bar_height)
{
// Get index into aggregated list
var a = thread.aggregator[s];
// Found bar, fill in tooltip
tooltip.style.left = (canvas.offsetLeft + mouse_x) + "px";
tooltip.style.top = (canvas.offsetTop + mouse_y) + "px";
tooltip.style.visibility = "visible";
tooltip.innerHTML = aggregated.name[a] + "
"
+ "
Time: | " + (1000000 * thread.cycles[s] / cycles_per_second).toFixed(2) + " µs |
Start: | " + (1000000 * thread.start[s] / cycles_per_second).toFixed(2) + " µs |
End: | " + (1000000 * (thread.start[s] + thread.cycles[s]) / cycles_per_second).toFixed(2) + " µs |
Avg. Time: | " + (1000000 * aggregated.cycles_per_frame[a] / cycles_per_second / aggregated.calls[a]).toFixed(2) + " µs |
Min Time: | " + (1000000 * aggregated.min_cycles[a] / cycles_per_second).toFixed(2) + " µs |
Max Time: | " + (1000000 * aggregated.max_cycles[a] / cycles_per_second).toFixed(2) + " µs |
Time / Frame: | " + (1000000 * aggregated.cycles_per_frame[a] / cycles_per_second).toFixed(2) + " µs |
Calls: | " + aggregated.calls[a] + " |