Commit | Line | Data |
---|---|---|
f48d55ce AV |
1 | /* |
2 | * svghelper.c - helper functions for outputting svg | |
3 | * | |
4 | * (C) Copyright 2009 Intel Corporation | |
5 | * | |
6 | * Authors: | |
7 | * Arjan van de Ven <arjan@linux.intel.com> | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU General Public License | |
11 | * as published by the Free Software Foundation; version 2 | |
12 | * of the License. | |
13 | */ | |
14 | ||
9486aa38 | 15 | #include <inttypes.h> |
f48d55ce AV |
16 | #include <stdio.h> |
17 | #include <stdlib.h> | |
18 | #include <unistd.h> | |
19 | #include <string.h> | |
20 | ||
21 | #include "svghelper.h" | |
22 | ||
23 | static u64 first_time, last_time; | |
24 | static u64 turbo_frequency, max_freq; | |
25 | ||
26 | ||
27 | #define SLOT_MULT 30.0 | |
28 | #define SLOT_HEIGHT 25.0 | |
5094b655 AV |
29 | |
30 | int svg_page_width = 1000; | |
f48d55ce | 31 | |
39a90a8e | 32 | #define MIN_TEXT_SIZE 0.01 |
964a0b3d | 33 | |
f48d55ce AV |
34 | static u64 total_height; |
35 | static FILE *svgfile; | |
36 | ||
37 | static double cpu2slot(int cpu) | |
38 | { | |
39 | return 2 * cpu + 1; | |
40 | } | |
41 | ||
42 | static double cpu2y(int cpu) | |
43 | { | |
44 | return cpu2slot(cpu) * SLOT_MULT; | |
45 | } | |
46 | ||
00e99a49 | 47 | static double time2pixels(u64 __time) |
f48d55ce AV |
48 | { |
49 | double X; | |
50 | ||
00e99a49 | 51 | X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time); |
f48d55ce AV |
52 | return X; |
53 | } | |
54 | ||
611a546b AV |
55 | /* |
56 | * Round text sizes so that the svg viewer only needs a discrete | |
57 | * number of renderings of the font | |
58 | */ | |
59 | static double round_text_size(double size) | |
60 | { | |
61 | int loop = 100; | |
62 | double target = 10.0; | |
63 | ||
64 | if (size >= 10.0) | |
65 | return size; | |
66 | while (loop--) { | |
67 | if (size >= target) | |
68 | return target; | |
69 | target = target / 2.0; | |
70 | } | |
71 | return size; | |
72 | } | |
73 | ||
5094b655 | 74 | void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end) |
f48d55ce | 75 | { |
5094b655 | 76 | int new_width; |
f48d55ce AV |
77 | |
78 | svgfile = fopen(filename, "w"); | |
79 | if (!svgfile) { | |
80 | fprintf(stderr, "Cannot open %s for output\n", filename); | |
81 | return; | |
82 | } | |
5094b655 AV |
83 | first_time = start; |
84 | first_time = first_time / 100000000 * 100000000; | |
85 | last_time = end; | |
86 | ||
87 | /* | |
88 | * if the recording is short, we default to a width of 1000, but | |
89 | * for longer recordings we want at least 200 units of width per second | |
90 | */ | |
91 | new_width = (last_time - first_time) / 5000000; | |
92 | ||
93 | if (new_width > svg_page_width) | |
94 | svg_page_width = new_width; | |
95 | ||
f48d55ce AV |
96 | total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; |
97 | fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); | |
cbb2e81e | 98 | fprintf(svgfile, "<!DOCTYPE svg SYSTEM \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); |
9486aa38 | 99 | fprintf(svgfile, "<svg width=\"%i\" height=\"%" PRIu64 "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height); |
f48d55ce AV |
100 | |
101 | fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); | |
102 | ||
103 | fprintf(svgfile, " rect { stroke-width: 1; }\n"); | |
104 | fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); | |
105 | fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | |
106 | fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | |
107 | fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | |
2e600d01 | 108 | fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
a92fe7b3 | 109 | fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
f48d55ce AV |
110 | fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n"); |
111 | fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n"); | |
112 | fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n"); | |
113 | fprintf(svgfile, " rect.c2 { fill:rgb(255,172,172); fill-opacity:0.5; stroke-width:0; } \n"); | |
114 | fprintf(svgfile, " rect.c3 { fill:rgb(255,130,130); fill-opacity:0.5; stroke-width:0; } \n"); | |
115 | fprintf(svgfile, " rect.c4 { fill:rgb(255, 88, 88); fill-opacity:0.5; stroke-width:0; } \n"); | |
116 | fprintf(svgfile, " rect.c5 { fill:rgb(255, 44, 44); fill-opacity:0.5; stroke-width:0; } \n"); | |
117 | fprintf(svgfile, " rect.c6 { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; } \n"); | |
118 | fprintf(svgfile, " line.pstate { stroke:rgb(255,255, 0); stroke-opacity:0.8; stroke-width:2; } \n"); | |
119 | ||
120 | fprintf(svgfile, " ]]>\n </style>\n</defs>\n"); | |
121 | } | |
122 | ||
123 | void svg_box(int Yslot, u64 start, u64 end, const char *type) | |
124 | { | |
125 | if (!svgfile) | |
126 | return; | |
127 | ||
128 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", | |
129 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); | |
130 | } | |
131 | ||
cbb2e81e SF |
132 | static char *time_to_string(u64 duration); |
133 | void svg_blocked(int Yslot, int cpu, u64 start, u64 end) | |
134 | { | |
135 | if (!svgfile) | |
136 | return; | |
137 | ||
138 | fprintf(svgfile, "<g>\n"); | |
139 | fprintf(svgfile, "<title>#%d blocked %s</title>\n", cpu, | |
140 | time_to_string(end - start)); | |
141 | svg_box(Yslot, start, end, "blocked"); | |
142 | fprintf(svgfile, "</g>\n"); | |
143 | } | |
144 | ||
145 | void svg_running(int Yslot, int cpu, u64 start, u64 end) | |
f48d55ce AV |
146 | { |
147 | double text_size; | |
148 | if (!svgfile) | |
149 | return; | |
150 | ||
cbb2e81e SF |
151 | fprintf(svgfile, "<g>\n"); |
152 | ||
153 | fprintf(svgfile, "<title>#%d running %s</title>\n", | |
154 | cpu, time_to_string(end - start)); | |
a92fe7b3 AV |
155 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n", |
156 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT); | |
f48d55ce AV |
157 | |
158 | text_size = (time2pixels(end)-time2pixels(start)); | |
159 | if (cpu > 9) | |
160 | text_size = text_size/2; | |
161 | if (text_size > 1.25) | |
162 | text_size = 1.25; | |
611a546b AV |
163 | text_size = round_text_size(text_size); |
164 | ||
964a0b3d | 165 | if (text_size > MIN_TEXT_SIZE) |
611a546b | 166 | fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n", |
f48d55ce AV |
167 | time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); |
168 | ||
cbb2e81e | 169 | fprintf(svgfile, "</g>\n"); |
f48d55ce AV |
170 | } |
171 | ||
a92fe7b3 AV |
172 | static char *time_to_string(u64 duration) |
173 | { | |
174 | static char text[80]; | |
175 | ||
176 | text[0] = 0; | |
177 | ||
178 | if (duration < 1000) /* less than 1 usec */ | |
179 | return text; | |
180 | ||
181 | if (duration < 1000 * 1000) { /* less than 1 msec */ | |
182 | sprintf(text, "%4.1f us", duration / 1000.0); | |
183 | return text; | |
184 | } | |
185 | sprintf(text, "%4.1f ms", duration / 1000.0 / 1000); | |
186 | ||
187 | return text; | |
188 | } | |
189 | ||
cbb2e81e | 190 | void svg_waiting(int Yslot, int cpu, u64 start, u64 end) |
a92fe7b3 AV |
191 | { |
192 | char *text; | |
193 | const char *style; | |
194 | double font_size; | |
195 | ||
196 | if (!svgfile) | |
197 | return; | |
198 | ||
199 | style = "waiting"; | |
200 | ||
201 | if (end-start > 10 * 1000000) /* 10 msec */ | |
202 | style = "WAITING"; | |
203 | ||
204 | text = time_to_string(end-start); | |
205 | ||
611a546b | 206 | font_size = 1.0 * (time2pixels(end)-time2pixels(start)); |
a92fe7b3 | 207 | |
611a546b AV |
208 | if (font_size > 3) |
209 | font_size = 3; | |
a92fe7b3 | 210 | |
611a546b | 211 | font_size = round_text_size(font_size); |
a92fe7b3 | 212 | |
611a546b | 213 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT); |
cbb2e81e | 214 | fprintf(svgfile, "<title>#%d waiting %s</title>\n", cpu, time_to_string(end - start)); |
611a546b AV |
215 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", |
216 | time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style); | |
a92fe7b3 | 217 | if (font_size > MIN_TEXT_SIZE) |
611a546b AV |
218 | fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%1.8fpt\"> %s</text>\n", |
219 | font_size, text); | |
220 | fprintf(svgfile, "</g>\n"); | |
a92fe7b3 AV |
221 | } |
222 | ||
f48d55ce AV |
223 | static char *cpu_model(void) |
224 | { | |
225 | static char cpu_m[255]; | |
226 | char buf[256]; | |
227 | FILE *file; | |
228 | ||
229 | cpu_m[0] = 0; | |
230 | /* CPU type */ | |
231 | file = fopen("/proc/cpuinfo", "r"); | |
232 | if (file) { | |
233 | while (fgets(buf, 255, file)) { | |
234 | if (strstr(buf, "model name")) { | |
235 | strncpy(cpu_m, &buf[13], 255); | |
236 | break; | |
237 | } | |
238 | } | |
239 | fclose(file); | |
240 | } | |
39a90a8e AV |
241 | |
242 | /* CPU type */ | |
243 | file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r"); | |
244 | if (file) { | |
245 | while (fgets(buf, 255, file)) { | |
246 | unsigned int freq; | |
247 | freq = strtoull(buf, NULL, 10); | |
248 | if (freq > max_freq) | |
249 | max_freq = freq; | |
250 | } | |
251 | fclose(file); | |
252 | } | |
f48d55ce AV |
253 | return cpu_m; |
254 | } | |
255 | ||
256 | void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq) | |
257 | { | |
258 | char cpu_string[80]; | |
259 | if (!svgfile) | |
260 | return; | |
261 | ||
262 | max_freq = __max_freq; | |
263 | turbo_frequency = __turbo_freq; | |
264 | ||
cbb2e81e SF |
265 | fprintf(svgfile, "<g>\n"); |
266 | ||
f48d55ce AV |
267 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n", |
268 | time2pixels(first_time), | |
269 | time2pixels(last_time)-time2pixels(first_time), | |
270 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); | |
271 | ||
272 | sprintf(cpu_string, "CPU %i", (int)cpu+1); | |
611a546b | 273 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", |
f48d55ce AV |
274 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); |
275 | ||
964a0b3d | 276 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", |
f48d55ce | 277 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); |
cbb2e81e SF |
278 | |
279 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
280 | } |
281 | ||
282 | void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name) | |
283 | { | |
284 | double width; | |
285 | ||
286 | if (!svgfile) | |
287 | return; | |
288 | ||
611a546b AV |
289 | |
290 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); | |
cbb2e81e | 291 | fprintf(svgfile, "<title>%s %s</title>\n", name, time_to_string(end - start)); |
611a546b AV |
292 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", |
293 | time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type); | |
f48d55ce AV |
294 | width = time2pixels(end)-time2pixels(start); |
295 | if (width > 6) | |
296 | width = 6; | |
297 | ||
611a546b AV |
298 | width = round_text_size(width); |
299 | ||
964a0b3d | 300 | if (width > MIN_TEXT_SIZE) |
611a546b AV |
301 | fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n", |
302 | width, name); | |
303 | ||
304 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
305 | } |
306 | ||
307 | void svg_cstate(int cpu, u64 start, u64 end, int type) | |
308 | { | |
309 | double width; | |
310 | char style[128]; | |
311 | ||
312 | if (!svgfile) | |
313 | return; | |
314 | ||
315 | ||
cbb2e81e SF |
316 | fprintf(svgfile, "<g>\n"); |
317 | ||
f48d55ce AV |
318 | if (type > 6) |
319 | type = 6; | |
320 | sprintf(style, "c%i", type); | |
321 | ||
322 | fprintf(svgfile, "<rect class=\"%s\" x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\"/>\n", | |
323 | style, | |
324 | time2pixels(start), time2pixels(end)-time2pixels(start), | |
325 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); | |
326 | ||
611a546b | 327 | width = (time2pixels(end)-time2pixels(start))/2.0; |
f48d55ce AV |
328 | if (width > 6) |
329 | width = 6; | |
330 | ||
611a546b AV |
331 | width = round_text_size(width); |
332 | ||
964a0b3d | 333 | if (width > MIN_TEXT_SIZE) |
611a546b AV |
334 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n", |
335 | time2pixels(start), cpu2y(cpu)+width, width, type); | |
cbb2e81e SF |
336 | |
337 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
338 | } |
339 | ||
340 | static char *HzToHuman(unsigned long hz) | |
341 | { | |
342 | static char buffer[1024]; | |
343 | unsigned long long Hz; | |
344 | ||
345 | memset(buffer, 0, 1024); | |
346 | ||
347 | Hz = hz; | |
348 | ||
349 | /* default: just put the Number in */ | |
350 | sprintf(buffer, "%9lli", Hz); | |
351 | ||
352 | if (Hz > 1000) | |
353 | sprintf(buffer, " %6lli Mhz", (Hz+500)/1000); | |
354 | ||
355 | if (Hz > 1500000) | |
356 | sprintf(buffer, " %6.2f Ghz", (Hz+5000.0)/1000000); | |
357 | ||
358 | if (Hz == turbo_frequency) | |
359 | sprintf(buffer, "Turbo"); | |
360 | ||
361 | return buffer; | |
362 | } | |
363 | ||
364 | void svg_pstate(int cpu, u64 start, u64 end, u64 freq) | |
365 | { | |
366 | double height = 0; | |
367 | ||
368 | if (!svgfile) | |
369 | return; | |
370 | ||
cbb2e81e SF |
371 | fprintf(svgfile, "<g>\n"); |
372 | ||
f48d55ce AV |
373 | if (max_freq) |
374 | height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT); | |
375 | height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; | |
376 | fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n", | |
377 | time2pixels(start), time2pixels(end), height, height); | |
611a546b | 378 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n", |
f48d55ce AV |
379 | time2pixels(start), height+0.9, HzToHuman(freq)); |
380 | ||
cbb2e81e | 381 | fprintf(svgfile, "</g>\n"); |
f48d55ce AV |
382 | } |
383 | ||
384 | ||
4f1202c8 | 385 | void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2) |
f48d55ce AV |
386 | { |
387 | double height; | |
388 | ||
389 | if (!svgfile) | |
390 | return; | |
391 | ||
392 | ||
cbb2e81e SF |
393 | fprintf(svgfile, "<g>\n"); |
394 | ||
395 | fprintf(svgfile, "<title>%s wakes up %s</title>\n", | |
396 | desc1 ? desc1 : "?", | |
397 | desc2 ? desc2 : "?"); | |
398 | ||
f48d55ce | 399 | if (row1 < row2) { |
4f1202c8 | 400 | if (row1) { |
f48d55ce AV |
401 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", |
402 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); | |
4f1202c8 | 403 | if (desc2) |
611a546b | 404 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", |
4f1202c8 AV |
405 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2); |
406 | } | |
407 | if (row2) { | |
f48d55ce AV |
408 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", |
409 | time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT); | |
4f1202c8 | 410 | if (desc1) |
611a546b | 411 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", |
4f1202c8 AV |
412 | time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1); |
413 | } | |
f48d55ce | 414 | } else { |
4f1202c8 | 415 | if (row2) { |
f48d55ce AV |
416 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", |
417 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); | |
4f1202c8 | 418 | if (desc1) |
611a546b | 419 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", |
4f1202c8 AV |
420 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1); |
421 | } | |
422 | if (row1) { | |
f48d55ce AV |
423 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", |
424 | time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT); | |
4f1202c8 | 425 | if (desc2) |
611a546b | 426 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", |
4f1202c8 AV |
427 | time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2); |
428 | } | |
f48d55ce AV |
429 | } |
430 | height = row1 * SLOT_MULT; | |
431 | if (row2 > row1) | |
432 | height += SLOT_HEIGHT; | |
433 | if (row1) | |
434 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | |
435 | time2pixels(start), height); | |
cbb2e81e SF |
436 | |
437 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
438 | } |
439 | ||
440 | void svg_wakeline(u64 start, int row1, int row2) | |
441 | { | |
442 | double height; | |
443 | ||
444 | if (!svgfile) | |
445 | return; | |
446 | ||
447 | ||
cbb2e81e SF |
448 | fprintf(svgfile, "<g>\n"); |
449 | ||
f48d55ce AV |
450 | if (row1 < row2) |
451 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | |
452 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT); | |
453 | else | |
454 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%4.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n", | |
455 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT); | |
456 | ||
457 | height = row1 * SLOT_MULT; | |
458 | if (row2 > row1) | |
459 | height += SLOT_HEIGHT; | |
460 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | |
461 | time2pixels(start), height); | |
cbb2e81e SF |
462 | |
463 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
464 | } |
465 | ||
466 | void svg_interrupt(u64 start, int row) | |
467 | { | |
468 | if (!svgfile) | |
469 | return; | |
470 | ||
cbb2e81e SF |
471 | fprintf(svgfile, "<g>\n"); |
472 | ||
473 | fprintf(svgfile, "<title>Wakeup from interrupt</title>\n"); | |
474 | ||
f48d55ce AV |
475 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", |
476 | time2pixels(start), row * SLOT_MULT); | |
477 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", | |
478 | time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT); | |
cbb2e81e SF |
479 | |
480 | fprintf(svgfile, "</g>\n"); | |
f48d55ce AV |
481 | } |
482 | ||
483 | void svg_text(int Yslot, u64 start, const char *text) | |
484 | { | |
485 | if (!svgfile) | |
486 | return; | |
487 | ||
611a546b | 488 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", |
f48d55ce AV |
489 | time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text); |
490 | } | |
491 | ||
492 | static void svg_legenda_box(int X, const char *text, const char *style) | |
493 | { | |
494 | double boxsize; | |
495 | boxsize = SLOT_HEIGHT / 2; | |
496 | ||
497 | fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", | |
498 | X, boxsize, boxsize, style); | |
611a546b | 499 | fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.8fpt\">%s</text>\n", |
f48d55ce AV |
500 | X + boxsize + 5, boxsize, 0.8 * boxsize, text); |
501 | } | |
502 | ||
503 | void svg_legenda(void) | |
504 | { | |
505 | if (!svgfile) | |
506 | return; | |
507 | ||
cbb2e81e | 508 | fprintf(svgfile, "<g>\n"); |
f48d55ce | 509 | svg_legenda_box(0, "Running", "sample"); |
e8530720 TR |
510 | svg_legenda_box(100, "Idle","c1"); |
511 | svg_legenda_box(200, "Deeper Idle", "c3"); | |
512 | svg_legenda_box(350, "Deepest Idle", "c6"); | |
f48d55ce AV |
513 | svg_legenda_box(550, "Sleeping", "process2"); |
514 | svg_legenda_box(650, "Waiting for cpu", "waiting"); | |
515 | svg_legenda_box(800, "Blocked on IO", "blocked"); | |
cbb2e81e | 516 | fprintf(svgfile, "</g>\n"); |
f48d55ce AV |
517 | } |
518 | ||
5094b655 | 519 | void svg_time_grid(void) |
f48d55ce AV |
520 | { |
521 | u64 i; | |
522 | ||
f48d55ce AV |
523 | if (!svgfile) |
524 | return; | |
525 | ||
526 | i = first_time; | |
527 | while (i < last_time) { | |
528 | int color = 220; | |
529 | double thickness = 0.075; | |
530 | if ((i % 100000000) == 0) { | |
531 | thickness = 0.5; | |
532 | color = 192; | |
533 | } | |
534 | if ((i % 1000000000) == 0) { | |
535 | thickness = 2.0; | |
536 | color = 128; | |
537 | } | |
538 | ||
9486aa38 | 539 | fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%" PRIu64 "\" style=\"stroke:rgb(%i,%i,%i);stroke-width:%1.3f\"/>\n", |
f48d55ce AV |
540 | time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness); |
541 | ||
542 | i += 10000000; | |
543 | } | |
544 | } | |
545 | ||
546 | void svg_close(void) | |
547 | { | |
548 | if (svgfile) { | |
549 | fprintf(svgfile, "</svg>\n"); | |
550 | fclose(svgfile); | |
551 | svgfile = NULL; | |
552 | } | |
553 | } |