2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2019-02-06 18:08:26 -05:00
|
|
|
// How much to multiply time values in order to process log graphs properly.
|
|
|
|
const TimeScaleFactor = 10000;
|
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
export async function getJson(path) {
|
|
|
|
return (await fetch(path)).json();
|
|
|
|
}
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2018-10-11 16:55:22 -04:00
|
|
|
function getBenchmarkVarieties(data, benchmarkName) {
|
|
|
|
// Look at last sha hash.
|
|
|
|
const last = data[data.length - 1];
|
|
|
|
return Object.keys(last[benchmarkName]);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createColumns(data, benchmarkName) {
|
|
|
|
const varieties = getBenchmarkVarieties(data, benchmarkName);
|
|
|
|
return varieties.map(variety => [
|
|
|
|
variety,
|
2018-09-21 12:06:59 -04:00
|
|
|
...data.map(d => {
|
2018-10-11 16:55:22 -04:00
|
|
|
if (d[benchmarkName] != null) {
|
|
|
|
if (d[benchmarkName][variety] != null) {
|
|
|
|
const v = d[benchmarkName][variety];
|
|
|
|
if (benchmarkName == "benchmark") {
|
|
|
|
const meanValue = v ? v.mean : 0;
|
|
|
|
return meanValue || null;
|
|
|
|
} else {
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2018-09-21 12:06:59 -04:00
|
|
|
})
|
|
|
|
]);
|
2018-09-24 11:31:14 -04:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:55:22 -04:00
|
|
|
export function createExecTimeColumns(data) {
|
|
|
|
return createColumns(data, "benchmark");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createThroughputColumns(data) {
|
|
|
|
return createColumns(data, "throughput");
|
|
|
|
}
|
|
|
|
|
2018-10-15 16:44:35 -04:00
|
|
|
export function createReqPerSecColumns(data) {
|
|
|
|
return createColumns(data, "req_per_sec");
|
|
|
|
}
|
|
|
|
|
2019-03-24 23:36:27 -04:00
|
|
|
export function createMaxLatencyColumns(data) {
|
|
|
|
return createColumns(data, "max_latency");
|
|
|
|
}
|
|
|
|
|
2019-04-16 13:57:05 -04:00
|
|
|
export function createMaxMemoryColumns(data) {
|
|
|
|
return createColumns(data, "max_memory");
|
|
|
|
}
|
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
export function createBinarySizeColumns(data) {
|
2018-10-06 22:21:51 -04:00
|
|
|
const propName = "binary_size";
|
|
|
|
const binarySizeNames = Object.keys(data[data.length - 1][propName]);
|
2018-09-25 20:08:09 -04:00
|
|
|
return binarySizeNames.map(name => [
|
|
|
|
name,
|
|
|
|
...data.map(d => {
|
|
|
|
const binarySizeData = d["binary_size"];
|
|
|
|
switch (typeof binarySizeData) {
|
|
|
|
case "number": // legacy implementation
|
|
|
|
return name === "deno" ? binarySizeData : 0;
|
|
|
|
default:
|
|
|
|
if (!binarySizeData) {
|
2018-10-03 05:21:26 -04:00
|
|
|
return null;
|
2018-09-25 20:08:09 -04:00
|
|
|
}
|
2018-10-03 05:21:26 -04:00
|
|
|
return binarySizeData[name] || null;
|
2018-09-25 20:08:09 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
]);
|
2018-09-24 11:31:14 -04:00
|
|
|
}
|
|
|
|
|
2018-09-24 18:12:52 -04:00
|
|
|
export function createThreadCountColumns(data) {
|
2018-10-06 22:21:51 -04:00
|
|
|
const propName = "thread_count";
|
|
|
|
const threadCountNames = Object.keys(data[data.length - 1][propName]);
|
2018-09-24 18:12:52 -04:00
|
|
|
return threadCountNames.map(name => [
|
|
|
|
name,
|
|
|
|
...data.map(d => {
|
2018-10-06 22:21:51 -04:00
|
|
|
const threadCountData = d[propName];
|
2018-09-24 18:12:52 -04:00
|
|
|
if (!threadCountData) {
|
2018-10-03 05:21:26 -04:00
|
|
|
return null;
|
2018-09-24 18:12:52 -04:00
|
|
|
}
|
2018-10-03 05:21:26 -04:00
|
|
|
return threadCountData[name] || null;
|
2018-09-24 18:12:52 -04:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-09-24 23:58:18 -04:00
|
|
|
export function createSyscallCountColumns(data) {
|
2018-10-06 22:21:51 -04:00
|
|
|
const propName = "syscall_count";
|
|
|
|
const syscallCountNames = Object.keys(data[data.length - 1][propName]);
|
2018-09-24 23:58:18 -04:00
|
|
|
return syscallCountNames.map(name => [
|
|
|
|
name,
|
|
|
|
...data.map(d => {
|
2018-10-06 22:21:51 -04:00
|
|
|
const syscallCountData = d[propName];
|
2018-09-24 23:58:18 -04:00
|
|
|
if (!syscallCountData) {
|
2018-10-03 05:21:26 -04:00
|
|
|
return null;
|
2018-09-24 23:58:18 -04:00
|
|
|
}
|
2018-10-03 05:21:26 -04:00
|
|
|
return syscallCountData[name] || null;
|
2018-09-24 23:58:18 -04:00
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-09-24 11:31:14 -04:00
|
|
|
export function createSha1List(data) {
|
|
|
|
return data.map(d => d.sha1);
|
|
|
|
}
|
|
|
|
|
2018-10-24 10:04:33 -04:00
|
|
|
export function formatMB(bytes) {
|
2019-01-30 14:01:13 -05:00
|
|
|
return (bytes / (1024 * 1024)).toFixed(2);
|
2018-10-24 10:04:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function formatReqSec(reqPerSec) {
|
|
|
|
return reqPerSec / 1000;
|
2018-09-24 11:31:14 -04:00
|
|
|
}
|
2018-09-21 12:06:59 -04:00
|
|
|
|
2018-10-20 03:56:24 -04:00
|
|
|
/**
|
|
|
|
* @param {string} id The id of dom element
|
2018-10-20 12:43:40 -04:00
|
|
|
* @param {string[]} categories categories for x-axis values
|
2018-10-20 03:56:24 -04:00
|
|
|
* @param {any[][]} columns The columns data
|
2018-10-20 12:43:40 -04:00
|
|
|
* @param {function} onclick action on clicking nodes of chart
|
|
|
|
* @param {string} yLabel label of y axis
|
|
|
|
* @param {function} yTickFormat formatter of y axis ticks
|
2018-10-20 03:56:24 -04:00
|
|
|
*/
|
2018-10-24 10:04:33 -04:00
|
|
|
function generate(
|
2018-10-20 12:43:40 -04:00
|
|
|
id,
|
|
|
|
categories,
|
|
|
|
columns,
|
|
|
|
onclick,
|
|
|
|
yLabel = "",
|
|
|
|
yTickFormat = null
|
|
|
|
) {
|
2018-10-24 10:04:33 -04:00
|
|
|
const yAxis = {
|
|
|
|
padding: { bottom: 0 },
|
2019-02-11 17:41:13 -05:00
|
|
|
min: 0,
|
2018-10-20 12:43:40 -04:00
|
|
|
label: yLabel
|
|
|
|
};
|
|
|
|
if (yTickFormat) {
|
2018-10-24 10:04:33 -04:00
|
|
|
yAxis.tick = {
|
2018-10-20 12:43:40 -04:00
|
|
|
format: yTickFormat
|
|
|
|
};
|
2019-02-06 18:08:26 -05:00
|
|
|
if (yTickFormat == logScale) {
|
2019-02-11 17:41:13 -05:00
|
|
|
delete yAxis.min;
|
2019-02-06 18:08:26 -05:00
|
|
|
for (let col of columns) {
|
|
|
|
for (let i = 1; i < col.length; i++) {
|
|
|
|
if (col[i] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
col[i] = Math.log10(col[i] * TimeScaleFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-20 12:43:40 -04:00
|
|
|
}
|
|
|
|
|
2018-10-24 15:26:21 -04:00
|
|
|
// @ts-ignore
|
2018-10-18 06:23:26 -04:00
|
|
|
c3.generate({
|
|
|
|
bindto: id,
|
|
|
|
data: {
|
|
|
|
columns,
|
|
|
|
onclick
|
|
|
|
},
|
|
|
|
axis: {
|
2018-10-24 10:04:33 -04:00
|
|
|
x: {
|
|
|
|
type: "category",
|
|
|
|
show: false,
|
|
|
|
categories
|
|
|
|
},
|
|
|
|
y: yAxis
|
2018-10-18 06:23:26 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-06 18:08:26 -05:00
|
|
|
function logScale(t) {
|
|
|
|
return (Math.pow(10, t) / TimeScaleFactor).toFixed(4);
|
|
|
|
}
|
|
|
|
|
2018-10-24 10:04:33 -04:00
|
|
|
function formatSecsAsMins(t) {
|
|
|
|
// TODO use d3.round()
|
2018-09-26 20:26:34 -04:00
|
|
|
const a = t % 60;
|
|
|
|
const min = Math.floor(t / 60);
|
2018-10-24 10:04:33 -04:00
|
|
|
return a < 30 ? min : min + 1;
|
2018-09-26 20:26:34 -04:00
|
|
|
}
|
|
|
|
|
2018-10-20 03:56:24 -04:00
|
|
|
/**
|
|
|
|
* @param dataUrl The url of benchramk data json.
|
|
|
|
*/
|
|
|
|
export function drawCharts(dataUrl) {
|
2018-11-14 09:38:42 -05:00
|
|
|
// TODO Using window["location"]["hostname"] instead of
|
|
|
|
// window.location.hostname because when deno runs app_test.js it gets a type
|
|
|
|
// error here, not knowing about window.location. Ideally Deno would skip
|
|
|
|
// type check entirely on JS files.
|
|
|
|
if (window["location"]["hostname"] != "deno.github.io") {
|
|
|
|
dataUrl = "https://denoland.github.io/deno/" + dataUrl;
|
|
|
|
}
|
2019-04-25 13:20:10 -04:00
|
|
|
return drawChartsFromBenchmarkData(dataUrl);
|
2018-10-16 12:00:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the charts from the benchmark data stored in gh-pages branch.
|
|
|
|
*/
|
2018-10-20 03:56:24 -04:00
|
|
|
export async function drawChartsFromBenchmarkData(dataUrl) {
|
|
|
|
const data = await getJson(dataUrl);
|
2018-09-24 11:31:14 -04:00
|
|
|
|
|
|
|
const execTimeColumns = createExecTimeColumns(data);
|
2018-10-11 16:55:22 -04:00
|
|
|
const throughputColumns = createThroughputColumns(data);
|
2018-10-15 16:44:35 -04:00
|
|
|
const reqPerSecColumns = createReqPerSecColumns(data);
|
2019-03-24 23:36:27 -04:00
|
|
|
const maxLatencyColumns = createMaxLatencyColumns(data);
|
2019-04-16 13:57:05 -04:00
|
|
|
const maxMemoryColumns = createMaxMemoryColumns(data);
|
2018-09-24 11:31:14 -04:00
|
|
|
const binarySizeColumns = createBinarySizeColumns(data);
|
2018-09-24 18:12:52 -04:00
|
|
|
const threadCountColumns = createThreadCountColumns(data);
|
2018-09-24 23:58:18 -04:00
|
|
|
const syscallCountColumns = createSyscallCountColumns(data);
|
2018-09-24 11:31:14 -04:00
|
|
|
const sha1List = createSha1List(data);
|
2018-09-26 20:41:23 -04:00
|
|
|
const sha1ShortList = sha1List.map(sha1 => sha1.substring(0, 6));
|
2018-09-27 02:19:42 -04:00
|
|
|
|
|
|
|
const viewCommitOnClick = _sha1List => d => {
|
2018-10-24 15:26:21 -04:00
|
|
|
// @ts-ignore
|
2018-09-27 02:19:42 -04:00
|
|
|
window.open(
|
|
|
|
`https://github.com/denoland/deno/commit/${_sha1List[d["index"]]}`
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-10-20 12:43:40 -04:00
|
|
|
function gen(id, columns, yLabel = "", yTickFormat = null) {
|
2018-10-24 10:04:33 -04:00
|
|
|
generate(
|
2018-10-20 12:43:40 -04:00
|
|
|
id,
|
|
|
|
sha1ShortList,
|
|
|
|
columns,
|
|
|
|
viewCommitOnClick(sha1List),
|
|
|
|
yLabel,
|
|
|
|
yTickFormat
|
|
|
|
);
|
2018-10-18 06:23:26 -04:00
|
|
|
}
|
2018-09-23 11:54:07 -04:00
|
|
|
|
2019-02-06 18:08:26 -05:00
|
|
|
gen("#exec-time-chart", execTimeColumns, "seconds", logScale);
|
2019-02-11 17:41:13 -05:00
|
|
|
gen("#throughput-chart", throughputColumns, "seconds", logScale);
|
2018-10-24 10:04:33 -04:00
|
|
|
gen("#req-per-sec-chart", reqPerSecColumns, "1000 req/sec", formatReqSec);
|
2019-03-24 23:36:27 -04:00
|
|
|
gen("#max-latency-chart", maxLatencyColumns, "milliseconds", logScale);
|
2019-04-16 13:57:05 -04:00
|
|
|
gen("#max-memory-chart", maxMemoryColumns, "megabytes", formatMB);
|
2018-10-24 10:04:33 -04:00
|
|
|
gen("#binary-size-chart", binarySizeColumns, "megabytes", formatMB);
|
|
|
|
gen("#thread-count-chart", threadCountColumns, "threads");
|
|
|
|
gen("#syscall-count-chart", syscallCountColumns, "syscalls");
|
2018-10-16 12:00:47 -04:00
|
|
|
}
|