let colors = {}; function get_color(stage_name) { if (stage_name in config.predefined_colors) { return config.predefined_colors[stage_name]; } if (stage_name in colors) { return colors[stage_name]; } const r = Math.floor(Math.random() * 155); const g = Math.floor(Math.random() * 155); const b = Math.floor(Math.random() * 155); colors[stage_name] = [ 100 + r, 100 + g, 100 + b ]; return colors[stage_name]; } function generate(trace_id) { const result = { 'count': 0, }; const positions = []; const sizes = []; const colors = []; let instructions = []; if (trace_id in traces) { instructions = traces[trace_id]; } console.log(instructions); let y = 0; for (const instruction of instructions) { for (let i = 0; i < instruction.lanes['0'].length; ++i) { const stage = instruction.lanes['0'][i]; let stage_cycles; if (i < instruction.lanes['0'].length - 1) { const next_stage = instruction.lanes['0'][i + 1]; stage_cycles = next_stage.c - stage.c; } else { stage_cycles = instruction.retcyc - stage.c; } let [r, g, b] = get_color(stage.name); if (!instruction.retired) { r = Math.max(50, r - 50); g = Math.max(50, g - 50); b = Math.max(50, b - 50); } sizes.push(stage_cycles * config.w, 1 * config.h); positions.push(config.w * stage.c, config.h * y); colors.push(r, g, b, 255); result.count++; if (config.limit > 0 && result.count >= config.limit) { break; } } ++y; } result.pos = new Float32Array(positions); result.size = new Float32Array(sizes); result.color = new Uint8Array(colors); return result; }