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
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
export async function getJson(path) {
return (await fetch(path)).json();
}
export function getTravisData() {
const url =
"https://api.travis-ci.com/repos/denoland/deno/builds?event_type=pull_request";
return fetch(url, {
headers: {
Accept: "application/vnd.travis-ci.2.1+json"
}
})
.then(res => res.json())
.then(data => data.builds.reverse());
}
export function createExecTimeColumns(data) {
const benchmarkNames = Object.keys(data[data.length - 1].benchmark);
return benchmarkNames.map(name => [
name,
...data.map(d => {
const benchmark = d.benchmark[name];
const meanValue = benchmark ? benchmark.mean : 0;
return meanValue || null;
})
]);
}
export function createBinarySizeColumns(data) {
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) {
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) {
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;
})
]);
}
function createTravisCompileTimeColumns(data) {
return [["duration_time", ...data.map(d => d.duration)]];
}
export function createSha1List(data) {
return data.map(d => d.sha1);
}
// Formats the byte sizes e.g. 19000 -> 18.55 KB
// Copied from https://stackoverflow.com/a/18650828
export function formatBytes(a, b) {
if (0 == a) return "0 Bytes";
var c = 1024,
d = b || 2,
e = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"],
f = Math.floor(Math.log(a) / Math.log(c));
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + " " + e[f];
}
export function formatSeconds(t) {
const a = t % 60;
const min = Math.floor(t / 60);
return a < 30 ? `${min} min` : `${min + 1} min`;
}
export async function main() {
const data = await getJson("./data.json");
const travisData = (await getTravisData()).filter(d => d.duration > 0);
const execTimeColumns = createExecTimeColumns(data);
const binarySizeColumns = createBinarySizeColumns(data);
const threadCountColumns = createThreadCountColumns(data);
const syscallCountColumns = createSyscallCountColumns(data);
const travisCompileTimeColumns = createTravisCompileTimeColumns(travisData);
const sha1List = createSha1List(data);
const sha1ShortList = sha1List.map(sha1 => sha1.substring(0, 6));
const prNumberList = travisData.map(d => d.pull_request_number);
const viewCommitOnClick = _sha1List => d => {
window.open(
`https://github.com/denoland/deno/commit/${_sha1List[d["index"]]}`
);
};
const viewPullRequestOnClick = _prNumberList => d => {
window.open(
`https://github.com/denoland/deno/pull/${_prNumberList[d["index"]]}`
);
};
c3.generate({
bindto: "#exec-time-chart",
data: {
columns: execTimeColumns,
onclick: viewCommitOnClick(sha1List)
},
axis: {
x: {
type: "category",
show: false,
categories: sha1List
},
y: {
label: "seconds"
}
}
});
c3.generate({
bindto: "#binary-size-chart",
data: {
columns: binarySizeColumns,
onclick: viewCommitOnClick(sha1List)
},
axis: {
x: {
type: "category",
show: false,
categories: sha1ShortList
},
y: {
tick: {
format: d => formatBytes(d)
}
}
}
});
c3.generate({
bindto: "#thread-count-chart",
data: {
columns: threadCountColumns,
onclick: viewCommitOnClick(sha1List)
},
axis: {
x: {
type: "category",
show: false,
categories: sha1ShortList
}
}
});
c3.generate({
bindto: "#syscall-count-chart",
data: {
columns: syscallCountColumns,
onclick: viewCommitOnClick(sha1List)
},
axis: {
x: {
type: "category",
show: false,
categories: sha1ShortList
}
}
});
c3.generate({
bindto: "#travis-compile-time-chart",
data: {
columns: travisCompileTimeColumns,
onclick: viewPullRequestOnClick(prNumberList)
},
axis: {
x: {
type: "category",
categories: prNumberList
},
y: {
tick: {
format: d => formatSeconds(d)
}
}
}
});
}
|