-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.ts
480 lines (428 loc) · 13.2 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// How much to multiply time values in order to process log graphs properly.
const TimeScaleFactor = 10000;
export interface BenchmarkExecTimeResult {
min?: number;
max?: number;
mean?: number;
stddev?: number;
system?: number;
user?: number;
}
export interface BenchmarkExecTimeResultSet {
[variant: string]: BenchmarkExecTimeResult;
}
export interface BenchmarkVariantsResultSet {
[variant: string]: number;
}
export interface BenchmarkRun {
created_at: string;
sha1: string;
benchmark: BenchmarkExecTimeResultSet;
binary_size?: BenchmarkVariantsResultSet | number;
max_memory?: BenchmarkVariantsResultSet | number;
bundle_size?: BenchmarkVariantsResultSet;
max_latency?: BenchmarkVariantsResultSet;
req_per_sec?: BenchmarkVariantsResultSet;
req_per_sec_proxy?: BenchmarkVariantsResultSet;
syscall_count?: BenchmarkVariantsResultSet;
thread_count?: BenchmarkVariantsResultSet;
throughput?: BenchmarkVariantsResultSet;
}
export type BenchmarkName = Exclude<keyof BenchmarkRun, "created_at" | "sha1">;
type Column = [string, ...Array<number | null>];
interface C3DataNode {
id: string;
index: number;
name: string;
value: number;
x: number;
}
type C3OnClickCallback = (C3DataNode, unknown) => void;
type C3OnRenderedCallback = () => void;
type C3TickFormatter = (number) => number | string;
export async function getJson(path: string): Promise<unknown> {
return (await fetch(path)).json();
}
function getBenchmarkVarieties(
data: BenchmarkRun[],
benchmarkName: BenchmarkName
): string[] {
// Look at last sha hash.
const last = data[data.length - 1];
return Object.keys(last[benchmarkName]);
}
export function createColumns(
data: BenchmarkRun[],
benchmarkName: BenchmarkName
): Column[] {
const varieties = getBenchmarkVarieties(data, benchmarkName);
return varieties.map(variety => [
variety,
...data.map(d => {
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;
})
]);
}
export function createNormalizedColumns(
data: BenchmarkRun[],
benchmarkName: BenchmarkName,
baselineBenchmark: BenchmarkName,
baselineVariety: string
): Column[] {
const varieties = getBenchmarkVarieties(data, benchmarkName);
return varieties.map(variety => [
variety,
...data.map(d => {
if (d[baselineBenchmark] != null) {
if (d[baselineBenchmark][baselineVariety] != null) {
const baseline = d[baselineBenchmark][baselineVariety];
if (d[benchmarkName] != null) {
if (d[benchmarkName][variety] != null && baseline != 0) {
const v = d[benchmarkName][variety];
if (benchmarkName == "benchmark") {
const meanValue = v ? v.mean : 0;
return meanValue || null;
} else {
return v / baseline;
}
}
}
}
}
return null;
})
]);
}
export function createExecTimeColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "benchmark");
}
export function createThroughputColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "throughput");
}
export function createProxyColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "req_per_sec_proxy");
}
export function createNormalizedProxyColumns(data: BenchmarkRun[]): Column[] {
return createNormalizedColumns(
data,
"req_per_sec_proxy",
"req_per_sec",
"hyper"
);
}
export function createReqPerSecColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "req_per_sec");
}
export function createNormalizedReqPerSecColumns(
data: BenchmarkRun[]
): Column[] {
return createNormalizedColumns(data, "req_per_sec", "req_per_sec", "hyper");
}
export function createMaxLatencyColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "max_latency");
}
export function createMaxMemoryColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "max_memory");
}
export function createBinarySizeColumns(data: BenchmarkRun[]): Column[] {
const propName = "binary_size";
const binarySizeNames = Object.keys(data[data.length - 1][propName]);
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) {
return null;
}
return binarySizeData[name] || null;
}
})
]);
}
export function createThreadCountColumns(data: BenchmarkRun[]): Column[] {
const propName = "thread_count";
const threadCountNames = Object.keys(data[data.length - 1][propName]);
return threadCountNames.map(name => [
name,
...data.map(d => {
const threadCountData = d[propName];
if (!threadCountData) {
return null;
}
return threadCountData[name] || null;
})
]);
}
export function createSyscallCountColumns(data: BenchmarkRun[]): Column[] {
const propName = "syscall_count";
const syscallCountNames = Object.keys(data[data.length - 1][propName]);
return syscallCountNames.map(name => [
name,
...data.map(d => {
const syscallCountData = d[propName];
if (!syscallCountData) {
return null;
}
return syscallCountData[name] || null;
})
]);
}
export function createBundleSizeColumns(data: BenchmarkRun[]): Column[] {
return createColumns(data, "bundle_size");
}
export function createSha1List(data: BenchmarkRun[]): string[] {
return data.map(d => d.sha1);
}
export function formatKB(bytes: number): string {
return (bytes / 1024).toFixed(2);
}
export function formatMB(bytes: number): string {
return (bytes / (1024 * 1024)).toFixed(2);
}
export function formatReqSec(reqPerSec: number): string {
return (reqPerSec / 1000).toFixed(3);
}
export function formatPercentage(decimal: number): string {
return (decimal * 100).toFixed(2);
}
/**
* @param {string} id The id of dom element
* @param {string[]} categories categories for x-axis values
* @param {any[][]} columns The columns data
* @param {function} onclick action on clicking nodes of chart
* @param {string} yLabel label of y axis
* @param {function} yTickFormat formatter of y axis ticks
* @param {boolean} zoomEnabled enables the zoom feature
*/
function generate(
id: string,
categories: string[],
columns: Column[],
onclick: C3OnClickCallback,
yLabel = "",
yTickFormat?: C3TickFormatter,
zoomEnabled = true,
onrendered?: C3OnRenderedCallback
): void {
const yAxis = {
padding: { bottom: 0 },
min: 0,
label: yLabel,
tick: null
};
if (yTickFormat) {
yAxis.tick = {
format: yTickFormat
};
if (yTickFormat == logScale) {
delete yAxis.min;
for (const col of columns) {
for (let i = 1; i < col.length; i++) {
if (col[i] == null || col[i] === 0) {
continue;
}
col[i] = Math.log10((col[i] as number) * TimeScaleFactor);
}
}
}
}
// @ts-ignore
c3.generate({
bindto: id,
onrendered,
data: {
columns,
onclick
},
axis: {
x: {
type: "category",
show: false,
categories
},
y: yAxis
},
zoom: {
enabled: zoomEnabled
}
});
}
function logScale(t: number): string {
return (Math.pow(10, t) / TimeScaleFactor).toFixed(4);
}
/**
* @param dataUrl The url of benchmark data json.
*/
export function drawCharts(dataUrl: string): Promise<void> {
// 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;
}
return drawChartsFromBenchmarkData(dataUrl);
}
const proxyFields: BenchmarkName[] = ["req_per_sec"];
function extractProxyFields(data: BenchmarkRun[]): void {
for (const row of data) {
for (const field of proxyFields) {
const d = row[field];
if (!d) continue;
const name = field + "_proxy";
const newField = {};
row[name] = newField;
for (const k of Object.getOwnPropertyNames(d)) {
if (k.includes("_proxy")) {
const v = d[k];
delete d[k];
newField[k] = v;
}
}
}
}
}
/**
* Draws the charts from the benchmark data stored in gh-pages branch.
*/
export async function drawChartsFromBenchmarkData(
dataUrl: string
): Promise<void> {
const data = (await getJson(dataUrl)) as BenchmarkRun[];
// hack to extract proxy fields from req/s fields
extractProxyFields(data);
const execTimeColumns = createExecTimeColumns(data);
const throughputColumns = createThroughputColumns(data);
const reqPerSecColumns = createReqPerSecColumns(data);
const normalizedReqPerSecColumns = createNormalizedReqPerSecColumns(data);
const proxyColumns = createProxyColumns(data);
const normalizedProxyColumns = createNormalizedProxyColumns(data);
const maxLatencyColumns = createMaxLatencyColumns(data);
const maxMemoryColumns = createMaxMemoryColumns(data);
const binarySizeColumns = createBinarySizeColumns(data);
const threadCountColumns = createThreadCountColumns(data);
const syscallCountColumns = createSyscallCountColumns(data);
const bundleSizeColumns = createBundleSizeColumns(data);
const sha1List = createSha1List(data);
const sha1ShortList = sha1List.map(sha1 => sha1.substring(0, 6));
function viewCommitOnClick(d: C3DataNode, _: unknown): void {
// @ts-ignore
window.open(`https://github.com/denoland/deno/commit/${sha1List[d.index]}`);
}
function gen(
id: string,
columns: Column[],
yLabel = "",
yTickFormat?: C3TickFormatter,
onrendered?: C3OnRenderedCallback
): void {
generate(
id,
sha1ShortList,
columns,
viewCommitOnClick,
yLabel,
yTickFormat,
true,
onrendered
);
}
gen("#exec-time-chart", execTimeColumns, "seconds", logScale);
gen("#throughput-chart", throughputColumns, "seconds", logScale);
gen("#req-per-sec-chart", reqPerSecColumns, "1000 req/sec", formatReqSec);
gen(
"#normalized-req-per-sec-chart",
normalizedReqPerSecColumns,
"% of hyper througput",
formatPercentage,
hideOnRender("normalized-req-per-sec-chart")
);
gen("#proxy-req-per-sec-chart", proxyColumns, "req/sec");
gen(
"#normalized-proxy-req-per-sec-chart",
normalizedProxyColumns,
"% of hyper througput",
formatPercentage,
hideOnRender("normalized-proxy-req-per-sec-chart")
);
gen("#max-latency-chart", maxLatencyColumns, "milliseconds", logScale);
gen("#max-memory-chart", maxMemoryColumns, "megabytes", formatMB);
gen("#binary-size-chart", binarySizeColumns, "megabytes", formatMB);
gen("#thread-count-chart", threadCountColumns, "threads");
gen("#syscall-count-chart", syscallCountColumns, "syscalls");
gen("#bundle-size-chart", bundleSizeColumns, "kilobytes", formatKB);
}
function hideOnRender(elementID: string): C3OnRenderedCallback {
return (): void => {
const chart = window["document"].getElementById(elementID);
if (!chart.getAttribute("data-inital-hide-done")) {
chart.setAttribute("data-inital-hide-done", "true");
chart.classList.add("hidden");
}
};
}
function registerNormalizedSwitcher(
checkboxID: string,
chartID: string,
normalizedChartID: string
): void {
const checkbox = window["document"].getElementById(checkboxID);
const regularChart = window["document"].getElementById(chartID);
const normalizedChart = window["document"].getElementById(normalizedChartID);
checkbox.addEventListener("change", _ => {
// If checked is true the normalized variant should be shown
// @ts-ignore
if (checkbox.checked) {
regularChart.classList.add("hidden");
normalizedChart.classList.remove("hidden");
} else {
normalizedChart.classList.add("hidden");
regularChart.classList.remove("hidden");
}
});
}
export function main(): void {
window["chartWidth"] = 800;
const overlay = window["document"].getElementById("spinner-overlay");
function showSpinner(): void {
overlay.style.display = "block";
}
function hideSpinner(): void {
overlay.style.display = "none";
}
function updateCharts(): void {
const u = window.location.hash.match("all") ? "./data.json" : "recent.json";
showSpinner();
drawCharts(u)
.then(hideSpinner)
.catch(hideSpinner);
}
updateCharts();
registerNormalizedSwitcher(
"req-per-sec-chart-show-normalized",
"req-per-sec-chart",
"normalized-req-per-sec-chart"
);
registerNormalizedSwitcher(
"proxy-req-per-sec-chart-show-normalized",
"proxy-req-per-sec-chart",
"normalized-proxy-req-per-sec-chart"
);
window["onhashchange"] = updateCharts;
}