-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxLine.html
More file actions
223 lines (206 loc) · 9.14 KB
/
boxLine.html
File metadata and controls
223 lines (206 loc) · 9.14 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
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
<html>
<head>
<script type="text/javascript" language="javascript">
var ret;
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
if(files[0])
{
var reader = new FileReader();
reader.readAsText(files[0]);
reader.onload = loaded;
}
}
function loaded(evt) {
var fileString = evt.target.result;
ret = fileString;
}
</script>
</head>
<body>
<h1>Tracing Time Box plot</h1>
<div id="plotSVG">
</div>
<div style="width:800;">
<input type="file" id="file" name="files[]" multiple />
<script type="text/javascript">
var btn=document.getElementById('file');
btn.addEventListener('change', handleFileSelect, false);
</script>
<input type="button" value="Begin Draw" onclick="document.getElementById('show').value=readFile();"/>
<textarea style="margin-top:20; height:500; width:700;" id="show" name="show" cols="50" rows="8" >
</textarea>
</div>
</body>
<script>
var lineHeight = 6; // the width of idle line.
var seperatorWidth = 4; // the width of white lines at each time tag points.
var seperatorDistance = 500; // 500 = 1s, When /= 20000
var bigBoxHeight = 100; // the vertical length of box.
var smallBoxHeight = 60;
var innerBoxWidthRatio = 0.5; // in a two color box, width(innerBox) = 0.4 * width(outerBox).
var cpuLineMargin = 50; // the blank spaces between two cpu lines.
var textHeight = 50; // the height of text "0s, 1s, 2s, ..."
var textCPUWidth = 200; // the width of text "CPU 0, CPU 1, CPU 2, CPU 3"
var maxLength = 20000;
function readFile()
{
var allEvents = []
var lines = ret.trim().split('\n');
var min = Number.MAX_VALUE, max = Number.MIN_VALUE;
var flag = 0;
for (var i = 0; i < lines.length; i++) {
var e = lines[i].split(' ');
var start = parseInt(e[1]), end = parseInt(e[2]);
var boxShape = "";
//if (e[0] == '2' && min > start)
if (min > start)
min = start;
//if (e[0] == '2' && max < end)
if (max < end)
max = end;
if (e[5] == "idle")
boxShape = "line";
else if (e[5] == "user")
boxShape = "smallBox";
else
boxShape = "bigBox";
allEvents.push([e[0], start, end, boxShape, e[3], e[4]]);
}
for (var i = 0; i < allEvents.length; i++) {
allEvents[i][1] -= min;
allEvents[i][2] -= min;
//allEvents[i][0] = (maxLength + 0.0)/(max - min) * allEvents[i][0];
//allEvents[i][1] = (maxLength + 0.0)/(max - min) * allEvents[i][1];
// Set to 20000 would be great.
allEvents[i][1] /= 20000;
allEvents[i][2] /= 20000;
//if (allEvents[i][2] - allEvents[i][1] < 0.1)
// allEvents[i][2] = allEvents[i][1] + 0.1;
}
var tempArray = allEvents.slice();
var filter = []
for (var i = 0; i < tempArray.length; i++) {
if (allEvents[i][2] - allEvents[i][1] > 0.0005)
filter.push(tempArray[i]);
}
allEvents = filter.slice();
var max = 0;
for (i = 0; i < allEvents.length; i++) {
if (max < allEvents[i][2]) max = allEvents[i][2];
//console.log(allEvents[i]);
}
console.log(allEvents.length);
//allEvents = allEvents.slice(0, 200000);
function colorRGB(colorName) {
if (colorName == "blue") return "rgb(0,0,255)";
if (colorName == "red") return "rgb(255,0,0)";
if (colorName == "green") return "rgb(0,255,0)";
if (colorName == "black") return "rgb(0,0,0)";
if (colorName == "white") return "rgb(255,255,255)";
return "rgb(0,0,0)";
}
function colorRGB2(colorString) {
return "rgb"+colorString;
}
// Draw a width * height rectangle with color at position (x, y).
function drawRectangle(x, y, width, height, color) {
if (width < 0) {
console.log(x)
console.log(y)
console.log(width)
console.log(height)
console.log(color)
}
return "<rect x=\""+ x +"\" y=\""+ y +"\" width=\"" + width.toFixed(2) +"\" height=\""
+ height + "\" style=\"fill:" + colorRGB2(color) + ";stroke-width:3\" />"
}
function drawTwoColorRec(x, y, width, height, color1, color2) {
return drawRectangle(x, y, width, height, color1) +
drawRectangle(x, y + ((height - (height * innerBoxWidthRatio)) / 2), width, height - (height - (height * innerBoxWidthRatio)), color2);
}
// Generate a event box. offsetTop is added to the vertical absolute position of the box.
function appendEvent2(startTime, endTime, type, offsetTop) {
var height = 0, color = "black", verticalPosition = 0;
if (type == "line") {
height = lineHeight;
verticalPosition = (bigBoxHeight - lineHeight) / 2;
color = "black";
}
else if (type == "smallBox") {
height = smallBoxHeight;
verticalPosition = (bigBoxHeight - smallBoxHeight) / 2;
color = "blue";
}
else if (type == "bigBox") {
height = bigBoxHeight;
verticalPosition = 0;
color = "red";
}
return drawRectangle(startTime, offsetTop + verticalPosition, endTime - startTime, height, color);
}
function appendEvent(startTime, endTime, type, color1, color2, offsetTop) {
var height = 0, verticalPosition = 0;
if (type == "line") {
height = lineHeight;
verticalPosition = (bigBoxHeight - lineHeight) / 2;
return drawRectangle(startTime, offsetTop + verticalPosition, endTime-startTime, height, color1);
}
else if (type == "smallBox") {
height = smallBoxHeight;
verticalPosition = (bigBoxHeight - smallBoxHeight) / 2;
}
else if (type == "bigBox") {
height = bigBoxHeight;
verticalPosition = 0;
}
return drawTwoColorRec(startTime, offsetTop + verticalPosition, endTime - startTime, height, color1, color2);
}
var content = "<svg style=\"width:" + maxLength + "; height:" + (bigBoxHeight + cpuLineMargin) * 5 + "\">";
//console.log(allEvents.length);
//console.log(allEvnets[allEvents.length - 1]);
content += appendEvent(textCPUWidth - 5, textCPUWidth + max, "line", "(50, 50, 50)", "(100, 100, 100)", textHeight);
//content += appendEvent(0, allEvents[allEvents.length-1][2], "line", "(0,0,0)", "(0,0,0)");
for (i = 0; i < allEvents.length; i++) {
// Append a event at the end of CPU 0, vertical position offset = 0 * one line.
if (allEvents[i][0] == '0')
content += appendEvent(textCPUWidth + allEvents[i][1], textCPUWidth + allEvents[i][2], allEvents[i][3], allEvents[i][4], allEvents[i][5], textHeight);
}
// Draw the CPU 1
content += appendEvent(textCPUWidth - 5, textCPUWidth + max, "line", "(50, 50, 50)", "(100, 100, 100)", textHeight + bigBoxHeight + cpuLineMargin);
for (i = 0; i < allEvents.length; i++) {
// Append a event at the end of CPU 1, vertical position offset = 0 * one line.
if (allEvents[i][0] == '1')
content += appendEvent(textCPUWidth + allEvents[i][1], textCPUWidth + allEvents[i][2], allEvents[i][3], allEvents[i][4], allEvents[i][5], textHeight + bigBoxHeight + cpuLineMargin);
}
// Draw the CPU 2
content += appendEvent(textCPUWidth - 5, textCPUWidth + max, "line", "(50, 50, 50)", "(100, 100, 100)", textHeight + 2 * (bigBoxHeight + cpuLineMargin));
for (i = 0; i < allEvents.length; i++) {
// Append a event at the end of CPU 3, vertical position offset = 0 * one line.
if (allEvents[i][0] == '2')
content += appendEvent(textCPUWidth + allEvents[i][1], textCPUWidth + allEvents[i][2], allEvents[i][3], allEvents[i][4], allEvents[i][5], textHeight + 2 * (bigBoxHeight + cpuLineMargin));
}
// Draw the CPU 3
content += appendEvent(textCPUWidth - 5, textCPUWidth + max, "line", "(50, 50, 50)", "(100, 100, 100)", textHeight + 3 * (bigBoxHeight + cpuLineMargin));
for (i = 0; i < allEvents.length; i++) {
// Append a event at the end of CPU 3, vertical position offset = 0 * one line.
if (allEvents[i][0] == '3')
content += appendEvent(textCPUWidth + allEvents[i][1], textCPUWidth + allEvents[i][2], allEvents[i][3], allEvents[i][4], allEvents[i][5], textHeight + 3 * (bigBoxHeight + cpuLineMargin));
}
// Draw the vertical white time tag line.
for (i = 0; i < maxLength; i += seperatorDistance) {
content += drawRectangle(textCPUWidth + i, 0, seperatorWidth, (bigBoxHeight + cpuLineMargin) * 4,"(255,255,255)");
content += "<text x=\"" + (textCPUWidth + i) + "\" y=\"" + textHeight + "\" font-size=\"30px\" fill=\"black\">" + i/seperatorDistance + "s</text>";
}
for (i = 0; i < 4; i++) {
content += "<text x=\"10\" y=\"" + ((i + 1) * (bigBoxHeight + cpuLineMargin) - 25) + "\" font-size=\"50px\" fill=\"black\">CPU " + i + " </text>";
}
content += "</svg>";
document.getElementById("plotSVG").innerHTML = content;
return allEvents.slice(0,100);
}
</script>
</html>
<!--svg id="plotSVG">
<rect x="200" y="0" width="60" height="20" style="fill:rgb(0,0,255);stroke-width:3" />
</svg-->