-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisualize.html
More file actions
186 lines (157 loc) · 4.08 KB
/
visualize.html
File metadata and controls
186 lines (157 loc) · 4.08 KB
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
<html>
<body>
<style>
body {
background-color: #eee;
overflow: scroll;
}
#container {
position: relative;
margin: 30px auto;
font-size: 12px;
}
.axis-wrap {
position: relative;
top: -33px;
color: #999;
}
.node {
position: relative;
padding: 10px;
/* border: 1px solid black; */
height: 200px;
margin: 50px 0;
box-sizing: border-box;
background-color: #fff;
}
.node h3 {
position: relative;
top: -45px;
left: -10px;
}
.node .box {
position: absolute;
padding: 1px;
box-sizing: border-box;
border: 1px solid black;
}
.node .line {
position: absolute;
width: 3000px;
border-top: 1px solid #ccc;
}
.box.cold{ background: #b9b9b9; ; }
.box.type-T { background-color: #e0e0e0; }
.box.type-D { background-color: #ccc; }
.box.type-B { background-color: #bbb; }
.axis {
position: absolute;
top: 5px;
}
</style>
<div id="file-area">
<input id="file-input" type="file" onChange="fileOnChange()">
<script>
function fileOnChange() {
var file = document.getElementById('file-input').files[0];
if (file) {
var reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = function (event) {
draw(event.target.result);
}
reader.onerror = function (event) {
console.error(event);
}
}
}
</script>
</div>
<div id="container"></div>
<script>
const WIDTH_OVER_MSEC = 0.05;
const HEIGHT = 25;
const NUM_NODES = 8;
const NODE_CAPACITY = 8;
function draw(log) {
let htmls = [];
for (let i = 0; i < NUM_NODES; i++) {
htmls[i] = `<h3>Node ${i}</h3>`;
}
var stdTime = -1;
var localOffsets = [];
var totalWidth = 0;
for (let i = 0; i < NUM_NODES; i++) {
var arr = [];
for (let j = 0; j < NODE_CAPACITY; j++) {
arr.push(0);
}
localOffsets.push(arr)
}
log.split("\n").forEach(e => {
const splitted = e.split(' ');
if (splitted.length < 3) {
return;
}
const startTime = parseInt(splitted[2]);
const endTime = parseInt(splitted[3]);
const appName = splitted[4];
let nodeIndex;
try {
nodeIndex = parseInt(e.split('"WorkerNodeId":')[1].split(',')[0]);
} catch (e) {
return;
}
if (stdTime == -1) {
stdTime = startTime;
}
const left = (startTime - stdTime) * WIDTH_OVER_MSEC + 5;
const width = (endTime - startTime) * WIDTH_OVER_MSEC;
totalWidth = Math.max(totalWidth, left + width);
var localOffset = -1;
for (let j = 0; j < localOffsets[nodeIndex].length; j++) {
if (localOffsets[nodeIndex][j] <= startTime) {
localOffsets[nodeIndex][j] = endTime;
localOffset = j;
break;
}
}
const top = localOffset * HEIGHT + 5;
let color = 'white';
if (e.indexOf('"UsingExistingRestContainer":true') !== -1) {
color = 'skyblue';
} else if (e.indexOf('"UsingPooledContainer":true') !== -1) {
color = '#89ff89';
} else if (e.indexOf('"ImageBuilt":true') !== -1) {
color = '#ffc7c7';
}
htmls[nodeIndex] += `
<div class="box"
style="left: ${left}px; top: ${top}px; width: ${width}px; background-color: ${color}">
<span>${appName}</span></sub>
</div>`;
});
let finalHtml = '';
let axisHtml = `<div class="axis-wrap">`;
for (let x = WIDTH_OVER_MSEC * 1000; x <= totalWidth; x += WIDTH_OVER_MSEC * 1000) {
const k = x / WIDTH_OVER_MSEC / 1000;
axisHtml += `<div class="axis" style="left: ${x}px">${k}s</div>`;
}
axisHtml += `</div>`;
for (let i = 0; i < NUM_NODES; i++) {
const height = NODE_CAPACITY * HEIGHT + 10;
let lines = '';
for (let j = 1; j < NODE_CAPACITY; j++)
lines += `<div class="line" style="top: ${j * HEIGHT + 5}; width: ${totalWidth}"></div>`;
finalHtml += `<div id="node${i}" class="node" style="height: ${height}; width: ${totalWidth}">
${axisHtml}
${lines}
${htmls[i]}
</div>`;
// document.getElementById('node' + i).innerHTML += htmls[i];
}
document.getElementById('container').innerHTML = finalHtml;
}
</script>
</body>
</html>