mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-14 18:32:29 +00:00
119 lines
4.2 KiB
HTML
119 lines
4.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Trace Gantt</title>
|
|
<link rel="stylesheet" href="css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="css/d3-gantt.css">
|
|
</head>
|
|
<body>
|
|
<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
|
|
<script language="javascript" type="text/javascript" src="js/bootstrap.min.js"></script>
|
|
<script language="javascript" type="text/javascript" src="js/d3.v4.min.js"></script>
|
|
<script language="javascript" type="text/javascript" src="js/d3-tip-0.8.0-alpha.1.js"></script>
|
|
<script language="javascript" type="text/javascript" src="js/d3-gantt.js"></script>
|
|
<div id="placeholder" class="chart-placeholder"></div>
|
|
</body>
|
|
</html>
|
|
|
|
<script language="javascript">
|
|
var example_json = [
|
|
{ t1: 100, t2: 200, band: "band1", color: "#888", text: "text1" },
|
|
{ t1: 300, t2: 400, band: "band2", color: "#ff8", text: "text2" },
|
|
{ t1: 100, t2: 400, band: "band3", color: "#888", text: "some very long text with a lot of letters in it" },
|
|
{ t1: 300, t2: 400, band: "band1", color: "#8ff", text: "some_very_long_identifier_with_a_lot_of_letters_in_it" },
|
|
{ t1: 500, t2: 800, band: "band2", color: "#f8f", text: "test\nif\nnew\nline\nworks\nhere?" }
|
|
];
|
|
|
|
var chart = d3.gantt()
|
|
.height(window.innerHeight - $("#placeholder")[0].getBoundingClientRect().y - window.scrollY)
|
|
.selector("#placeholder");
|
|
|
|
var data = null;
|
|
|
|
// Error message popup
|
|
$("<div id='errmsg'></div>").css({
|
|
position: "absolute",
|
|
display: "none",
|
|
border: "1px solid #faa",
|
|
padding: "2px",
|
|
"background-color": "#fcc",
|
|
opacity: 0.80
|
|
}).appendTo("body");
|
|
|
|
function fetchData(dataurl, parser = x => x) {
|
|
function onDataReceived(json, textStatus, xhr) {
|
|
$("#errmsg").hide();
|
|
data = parser(json);
|
|
chart(data);
|
|
}
|
|
|
|
function onDataError(xhr, error) {
|
|
console.log(arguments);
|
|
$("#errmsg").text("Fetch data error: " + error + (xhr.status == 200? xhr.responseText: ""))
|
|
.css({bottom: "5px", left: "25%", width: "50%"})
|
|
.fadeIn(200);
|
|
}
|
|
|
|
if (dataurl) {
|
|
$.ajax({
|
|
url: dataurl,
|
|
type: "GET",
|
|
dataType: "json",
|
|
success: function (json, textStatus, xhr) { onDataReceived(json, textStatus, xhr); },
|
|
error: onDataError
|
|
});
|
|
} else {
|
|
onDataReceived(example_json, "textStatus", "xhr");
|
|
}
|
|
}
|
|
|
|
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;
|
|
for (let i = 0; i < str.length; i++) {
|
|
hash = ((hash << 5) - hash) + str.charCodeAt(i);
|
|
hash |= 0; // Convert to 32bit integer
|
|
}
|
|
if (hash < 0)
|
|
hash = -hash;
|
|
return hash;
|
|
}
|
|
|
|
let result = [];
|
|
for (let i = 0; i < json.data.length; i++) {
|
|
let span = json.data[i];
|
|
result.push({
|
|
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([0, max_time_ms]);
|
|
return result;
|
|
}
|
|
|
|
fetchData(); // do not fetch, just draw example_json w/o parsing
|
|
//fetchData("your-traces.json" , parseClickHouseTrace);
|
|
</script>
|