change trace json format parsing

This commit is contained in:
Sergei Trifonov 2022-06-10 21:06:17 +02:00
parent 139f6035c4
commit 52dc54f0da

View File

@ -70,7 +70,21 @@
}
}
function strColor(str) {
function parseClickHouseTrace(json) {
let min_time_us = Number.MAX_VALUE;
for (let i = 0; i < json.data.length; i++) {
let span = json.data[i];
min_time_us = Math.min(min_time_us, +span.start_time_us);
}
let max_time_ms = 0;
function convertTime(us) {
let value = (us - min_time_us) / 1000;
max_time_ms = Math.max(max_time_ms, value);
return value;
}
function strHash(str) {
var hash = 0;
if (str.length === 0)
return hash;
@ -80,45 +94,22 @@
}
if (hash < 0)
hash = -hash;
let rainbow = (hash % 128) / 128;
return d3.interpolateRainbow(rainbow);
};
function parseClickHouseTrace(json) {
let min_time_us = Number.MAX_VALUE;
for (let i = 0; i < json.data.length; i++) {
let item = json.data[i];
for (let j = 0; j < item.spans.length; j++) {
let span = item.spans[j];
min_time_us = Math.min(min_time_us, span.start_time_us);
}
}
let minT = 0;
let maxT = 0;
function convertTime(us) {
let value = (us - min_time_us) / 1000;
maxT = Math.max(maxT, value);
return value;
return hash;
}
let result = [];
for (let i = 0; i < json.data.length; i++) {
let item = json.data[i];
for (let j = 0; j < item.spans.length; j++) {
let span = item.spans[j];
let span = json.data[i];
result.push({
t1: convertTime(span.start_time_us),
t2: convertTime(span.finish_time_us),
band: "thread" + item.group.thread_id,
color: strColor(span.operation_name),
t1: convertTime(+span.start_time_us),
t2: convertTime(+span.finish_time_us),
band: Object.values(span.group).join(' '),
color: d3.interpolateRainbow((strHash(span.color) % 256) / 256),
text: span.operation_name
});
}
}
chart.timeDomain([minT, maxT]);
chart.timeDomain([0, max_time_ms]);
return result;
}