diff options
Diffstat (limited to 'tools/perf/util/svghelper.c')
-rw-r--r-- | tools/perf/util/svghelper.c | 235 |
1 files changed, 225 insertions, 10 deletions
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 96c866045d60..43262b83c541 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c | |||
@@ -17,8 +17,12 @@ | |||
17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | #include <unistd.h> | 18 | #include <unistd.h> |
19 | #include <string.h> | 19 | #include <string.h> |
20 | #include <linux/bitops.h> | ||
20 | 21 | ||
22 | #include "perf.h" | ||
21 | #include "svghelper.h" | 23 | #include "svghelper.h" |
24 | #include "util.h" | ||
25 | #include "cpumap.h" | ||
22 | 26 | ||
23 | static u64 first_time, last_time; | 27 | static u64 first_time, last_time; |
24 | static u64 turbo_frequency, max_freq; | 28 | static u64 turbo_frequency, max_freq; |
@@ -28,6 +32,8 @@ static u64 turbo_frequency, max_freq; | |||
28 | #define SLOT_HEIGHT 25.0 | 32 | #define SLOT_HEIGHT 25.0 |
29 | 33 | ||
30 | int svg_page_width = 1000; | 34 | int svg_page_width = 1000; |
35 | u64 svg_highlight; | ||
36 | const char *svg_highlight_name; | ||
31 | 37 | ||
32 | #define MIN_TEXT_SIZE 0.01 | 38 | #define MIN_TEXT_SIZE 0.01 |
33 | 39 | ||
@@ -39,9 +45,14 @@ static double cpu2slot(int cpu) | |||
39 | return 2 * cpu + 1; | 45 | return 2 * cpu + 1; |
40 | } | 46 | } |
41 | 47 | ||
48 | static int *topology_map; | ||
49 | |||
42 | static double cpu2y(int cpu) | 50 | static double cpu2y(int cpu) |
43 | { | 51 | { |
44 | return cpu2slot(cpu) * SLOT_MULT; | 52 | if (topology_map) |
53 | return cpu2slot(topology_map[cpu]) * SLOT_MULT; | ||
54 | else | ||
55 | return cpu2slot(cpu) * SLOT_MULT; | ||
45 | } | 56 | } |
46 | 57 | ||
47 | static double time2pixels(u64 __time) | 58 | static double time2pixels(u64 __time) |
@@ -95,6 +106,7 @@ void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end) | |||
95 | 106 | ||
96 | total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; | 107 | total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; |
97 | fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); | 108 | fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); |
109 | fprintf(svgfile, "<!DOCTYPE svg SYSTEM \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); | ||
98 | fprintf(svgfile, "<svg width=\"%i\" height=\"%" PRIu64 "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height); | 110 | fprintf(svgfile, "<svg width=\"%i\" height=\"%" PRIu64 "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height); |
99 | 111 | ||
100 | fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); | 112 | fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); |
@@ -103,6 +115,7 @@ void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end) | |||
103 | fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); | 115 | fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); |
104 | fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | 116 | fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
105 | fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | 117 | fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
118 | fprintf(svgfile, " rect.sample_hi{ fill:rgb(255,128, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | ||
106 | fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | 119 | fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
107 | fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | 120 | fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
108 | fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); | 121 | fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); |
@@ -128,14 +141,42 @@ void svg_box(int Yslot, u64 start, u64 end, const char *type) | |||
128 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); | 141 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); |
129 | } | 142 | } |
130 | 143 | ||
131 | void svg_sample(int Yslot, int cpu, u64 start, u64 end) | 144 | static char *time_to_string(u64 duration); |
145 | void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) | ||
146 | { | ||
147 | if (!svgfile) | ||
148 | return; | ||
149 | |||
150 | fprintf(svgfile, "<g>\n"); | ||
151 | fprintf(svgfile, "<title>#%d blocked %s</title>\n", cpu, | ||
152 | time_to_string(end - start)); | ||
153 | if (backtrace) | ||
154 | fprintf(svgfile, "<desc>Blocked on:\n%s</desc>\n", backtrace); | ||
155 | svg_box(Yslot, start, end, "blocked"); | ||
156 | fprintf(svgfile, "</g>\n"); | ||
157 | } | ||
158 | |||
159 | void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) | ||
132 | { | 160 | { |
133 | double text_size; | 161 | double text_size; |
162 | const char *type; | ||
163 | |||
134 | if (!svgfile) | 164 | if (!svgfile) |
135 | return; | 165 | return; |
136 | 166 | ||
137 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n", | 167 | if (svg_highlight && end - start > svg_highlight) |
138 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT); | 168 | type = "sample_hi"; |
169 | else | ||
170 | type = "sample"; | ||
171 | fprintf(svgfile, "<g>\n"); | ||
172 | |||
173 | fprintf(svgfile, "<title>#%d running %s</title>\n", | ||
174 | cpu, time_to_string(end - start)); | ||
175 | if (backtrace) | ||
176 | fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace); | ||
177 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", | ||
178 | time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, | ||
179 | type); | ||
139 | 180 | ||
140 | text_size = (time2pixels(end)-time2pixels(start)); | 181 | text_size = (time2pixels(end)-time2pixels(start)); |
141 | if (cpu > 9) | 182 | if (cpu > 9) |
@@ -148,6 +189,7 @@ void svg_sample(int Yslot, int cpu, u64 start, u64 end) | |||
148 | fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n", | 189 | fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n", |
149 | time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); | 190 | time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); |
150 | 191 | ||
192 | fprintf(svgfile, "</g>\n"); | ||
151 | } | 193 | } |
152 | 194 | ||
153 | static char *time_to_string(u64 duration) | 195 | static char *time_to_string(u64 duration) |
@@ -168,7 +210,7 @@ static char *time_to_string(u64 duration) | |||
168 | return text; | 210 | return text; |
169 | } | 211 | } |
170 | 212 | ||
171 | void svg_waiting(int Yslot, u64 start, u64 end) | 213 | void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) |
172 | { | 214 | { |
173 | char *text; | 215 | char *text; |
174 | const char *style; | 216 | const char *style; |
@@ -192,6 +234,9 @@ void svg_waiting(int Yslot, u64 start, u64 end) | |||
192 | font_size = round_text_size(font_size); | 234 | font_size = round_text_size(font_size); |
193 | 235 | ||
194 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT); | 236 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT); |
237 | fprintf(svgfile, "<title>#%d waiting %s</title>\n", cpu, time_to_string(end - start)); | ||
238 | if (backtrace) | ||
239 | fprintf(svgfile, "<desc>Waiting on:\n%s</desc>\n", backtrace); | ||
195 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", | 240 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", |
196 | time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style); | 241 | time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style); |
197 | if (font_size > MIN_TEXT_SIZE) | 242 | if (font_size > MIN_TEXT_SIZE) |
@@ -242,28 +287,42 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq) | |||
242 | max_freq = __max_freq; | 287 | max_freq = __max_freq; |
243 | turbo_frequency = __turbo_freq; | 288 | turbo_frequency = __turbo_freq; |
244 | 289 | ||
290 | fprintf(svgfile, "<g>\n"); | ||
291 | |||
245 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n", | 292 | fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n", |
246 | time2pixels(first_time), | 293 | time2pixels(first_time), |
247 | time2pixels(last_time)-time2pixels(first_time), | 294 | time2pixels(last_time)-time2pixels(first_time), |
248 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); | 295 | cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); |
249 | 296 | ||
250 | sprintf(cpu_string, "CPU %i", (int)cpu+1); | 297 | sprintf(cpu_string, "CPU %i", (int)cpu); |
251 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", | 298 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", |
252 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); | 299 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); |
253 | 300 | ||
254 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", | 301 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", |
255 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); | 302 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); |
303 | |||
304 | fprintf(svgfile, "</g>\n"); | ||
256 | } | 305 | } |
257 | 306 | ||
258 | void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name) | 307 | void svg_process(int cpu, u64 start, u64 end, int pid, const char *name, const char *backtrace) |
259 | { | 308 | { |
260 | double width; | 309 | double width; |
310 | const char *type; | ||
261 | 311 | ||
262 | if (!svgfile) | 312 | if (!svgfile) |
263 | return; | 313 | return; |
264 | 314 | ||
315 | if (svg_highlight && end - start >= svg_highlight) | ||
316 | type = "sample_hi"; | ||
317 | else if (svg_highlight_name && strstr(name, svg_highlight_name)) | ||
318 | type = "sample_hi"; | ||
319 | else | ||
320 | type = "sample"; | ||
265 | 321 | ||
266 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); | 322 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); |
323 | fprintf(svgfile, "<title>%d %s running %s</title>\n", pid, name, time_to_string(end - start)); | ||
324 | if (backtrace) | ||
325 | fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace); | ||
267 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", | 326 | fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", |
268 | time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type); | 327 | time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type); |
269 | width = time2pixels(end)-time2pixels(start); | 328 | width = time2pixels(end)-time2pixels(start); |
@@ -288,6 +347,8 @@ void svg_cstate(int cpu, u64 start, u64 end, int type) | |||
288 | return; | 347 | return; |
289 | 348 | ||
290 | 349 | ||
350 | fprintf(svgfile, "<g>\n"); | ||
351 | |||
291 | if (type > 6) | 352 | if (type > 6) |
292 | type = 6; | 353 | type = 6; |
293 | sprintf(style, "c%i", type); | 354 | sprintf(style, "c%i", type); |
@@ -306,6 +367,8 @@ void svg_cstate(int cpu, u64 start, u64 end, int type) | |||
306 | if (width > MIN_TEXT_SIZE) | 367 | if (width > MIN_TEXT_SIZE) |
307 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n", | 368 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n", |
308 | time2pixels(start), cpu2y(cpu)+width, width, type); | 369 | time2pixels(start), cpu2y(cpu)+width, width, type); |
370 | |||
371 | fprintf(svgfile, "</g>\n"); | ||
309 | } | 372 | } |
310 | 373 | ||
311 | static char *HzToHuman(unsigned long hz) | 374 | static char *HzToHuman(unsigned long hz) |
@@ -339,6 +402,8 @@ void svg_pstate(int cpu, u64 start, u64 end, u64 freq) | |||
339 | if (!svgfile) | 402 | if (!svgfile) |
340 | return; | 403 | return; |
341 | 404 | ||
405 | fprintf(svgfile, "<g>\n"); | ||
406 | |||
342 | if (max_freq) | 407 | if (max_freq) |
343 | height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT); | 408 | height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT); |
344 | height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; | 409 | height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; |
@@ -347,10 +412,11 @@ void svg_pstate(int cpu, u64 start, u64 end, u64 freq) | |||
347 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n", | 412 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n", |
348 | time2pixels(start), height+0.9, HzToHuman(freq)); | 413 | time2pixels(start), height+0.9, HzToHuman(freq)); |
349 | 414 | ||
415 | fprintf(svgfile, "</g>\n"); | ||
350 | } | 416 | } |
351 | 417 | ||
352 | 418 | ||
353 | void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2) | 419 | void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2, const char *backtrace) |
354 | { | 420 | { |
355 | double height; | 421 | double height; |
356 | 422 | ||
@@ -358,6 +424,15 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc | |||
358 | return; | 424 | return; |
359 | 425 | ||
360 | 426 | ||
427 | fprintf(svgfile, "<g>\n"); | ||
428 | |||
429 | fprintf(svgfile, "<title>%s wakes up %s</title>\n", | ||
430 | desc1 ? desc1 : "?", | ||
431 | desc2 ? desc2 : "?"); | ||
432 | |||
433 | if (backtrace) | ||
434 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); | ||
435 | |||
361 | if (row1 < row2) { | 436 | if (row1 < row2) { |
362 | if (row1) { | 437 | if (row1) { |
363 | 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", | 438 | 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", |
@@ -395,9 +470,11 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc | |||
395 | if (row1) | 470 | if (row1) |
396 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | 471 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", |
397 | time2pixels(start), height); | 472 | time2pixels(start), height); |
473 | |||
474 | fprintf(svgfile, "</g>\n"); | ||
398 | } | 475 | } |
399 | 476 | ||
400 | void svg_wakeline(u64 start, int row1, int row2) | 477 | void svg_wakeline(u64 start, int row1, int row2, const char *backtrace) |
401 | { | 478 | { |
402 | double height; | 479 | double height; |
403 | 480 | ||
@@ -405,6 +482,11 @@ void svg_wakeline(u64 start, int row1, int row2) | |||
405 | return; | 482 | return; |
406 | 483 | ||
407 | 484 | ||
485 | fprintf(svgfile, "<g>\n"); | ||
486 | |||
487 | if (backtrace) | ||
488 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); | ||
489 | |||
408 | if (row1 < row2) | 490 | if (row1 < row2) |
409 | 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", | 491 | 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", |
410 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT); | 492 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT); |
@@ -417,17 +499,28 @@ void svg_wakeline(u64 start, int row1, int row2) | |||
417 | height += SLOT_HEIGHT; | 499 | height += SLOT_HEIGHT; |
418 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", | 500 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", |
419 | time2pixels(start), height); | 501 | time2pixels(start), height); |
502 | |||
503 | fprintf(svgfile, "</g>\n"); | ||
420 | } | 504 | } |
421 | 505 | ||
422 | void svg_interrupt(u64 start, int row) | 506 | void svg_interrupt(u64 start, int row, const char *backtrace) |
423 | { | 507 | { |
424 | if (!svgfile) | 508 | if (!svgfile) |
425 | return; | 509 | return; |
426 | 510 | ||
511 | fprintf(svgfile, "<g>\n"); | ||
512 | |||
513 | fprintf(svgfile, "<title>Wakeup from interrupt</title>\n"); | ||
514 | |||
515 | if (backtrace) | ||
516 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); | ||
517 | |||
427 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", | 518 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", |
428 | time2pixels(start), row * SLOT_MULT); | 519 | time2pixels(start), row * SLOT_MULT); |
429 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", | 520 | fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", |
430 | time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT); | 521 | time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT); |
522 | |||
523 | fprintf(svgfile, "</g>\n"); | ||
431 | } | 524 | } |
432 | 525 | ||
433 | void svg_text(int Yslot, u64 start, const char *text) | 526 | void svg_text(int Yslot, u64 start, const char *text) |
@@ -455,6 +548,7 @@ void svg_legenda(void) | |||
455 | if (!svgfile) | 548 | if (!svgfile) |
456 | return; | 549 | return; |
457 | 550 | ||
551 | fprintf(svgfile, "<g>\n"); | ||
458 | svg_legenda_box(0, "Running", "sample"); | 552 | svg_legenda_box(0, "Running", "sample"); |
459 | svg_legenda_box(100, "Idle","c1"); | 553 | svg_legenda_box(100, "Idle","c1"); |
460 | svg_legenda_box(200, "Deeper Idle", "c3"); | 554 | svg_legenda_box(200, "Deeper Idle", "c3"); |
@@ -462,6 +556,7 @@ void svg_legenda(void) | |||
462 | svg_legenda_box(550, "Sleeping", "process2"); | 556 | svg_legenda_box(550, "Sleeping", "process2"); |
463 | svg_legenda_box(650, "Waiting for cpu", "waiting"); | 557 | svg_legenda_box(650, "Waiting for cpu", "waiting"); |
464 | svg_legenda_box(800, "Blocked on IO", "blocked"); | 558 | svg_legenda_box(800, "Blocked on IO", "blocked"); |
559 | fprintf(svgfile, "</g>\n"); | ||
465 | } | 560 | } |
466 | 561 | ||
467 | void svg_time_grid(void) | 562 | void svg_time_grid(void) |
@@ -499,3 +594,123 @@ void svg_close(void) | |||
499 | svgfile = NULL; | 594 | svgfile = NULL; |
500 | } | 595 | } |
501 | } | 596 | } |
597 | |||
598 | #define cpumask_bits(maskp) ((maskp)->bits) | ||
599 | typedef struct { DECLARE_BITMAP(bits, MAX_NR_CPUS); } cpumask_t; | ||
600 | |||
601 | struct topology { | ||
602 | cpumask_t *sib_core; | ||
603 | int sib_core_nr; | ||
604 | cpumask_t *sib_thr; | ||
605 | int sib_thr_nr; | ||
606 | }; | ||
607 | |||
608 | static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos) | ||
609 | { | ||
610 | int i; | ||
611 | int thr; | ||
612 | |||
613 | for (i = 0; i < t->sib_thr_nr; i++) { | ||
614 | if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i]))) | ||
615 | continue; | ||
616 | |||
617 | for_each_set_bit(thr, | ||
618 | cpumask_bits(&t->sib_thr[i]), | ||
619 | MAX_NR_CPUS) | ||
620 | if (map[thr] == -1) | ||
621 | map[thr] = (*pos)++; | ||
622 | } | ||
623 | } | ||
624 | |||
625 | static void scan_core_topology(int *map, struct topology *t) | ||
626 | { | ||
627 | int pos = 0; | ||
628 | int i; | ||
629 | int cpu; | ||
630 | |||
631 | for (i = 0; i < t->sib_core_nr; i++) | ||
632 | for_each_set_bit(cpu, | ||
633 | cpumask_bits(&t->sib_core[i]), | ||
634 | MAX_NR_CPUS) | ||
635 | scan_thread_topology(map, t, cpu, &pos); | ||
636 | } | ||
637 | |||
638 | static int str_to_bitmap(char *s, cpumask_t *b) | ||
639 | { | ||
640 | int i; | ||
641 | int ret = 0; | ||
642 | struct cpu_map *m; | ||
643 | int c; | ||
644 | |||
645 | m = cpu_map__new(s); | ||
646 | if (!m) | ||
647 | return -1; | ||
648 | |||
649 | for (i = 0; i < m->nr; i++) { | ||
650 | c = m->map[i]; | ||
651 | if (c >= MAX_NR_CPUS) { | ||
652 | ret = -1; | ||
653 | break; | ||
654 | } | ||
655 | |||
656 | set_bit(c, cpumask_bits(b)); | ||
657 | } | ||
658 | |||
659 | cpu_map__delete(m); | ||
660 | |||
661 | return ret; | ||
662 | } | ||
663 | |||
664 | int svg_build_topology_map(char *sib_core, int sib_core_nr, | ||
665 | char *sib_thr, int sib_thr_nr) | ||
666 | { | ||
667 | int i; | ||
668 | struct topology t; | ||
669 | |||
670 | t.sib_core_nr = sib_core_nr; | ||
671 | t.sib_thr_nr = sib_thr_nr; | ||
672 | t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t)); | ||
673 | t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t)); | ||
674 | |||
675 | if (!t.sib_core || !t.sib_thr) { | ||
676 | fprintf(stderr, "topology: no memory\n"); | ||
677 | goto exit; | ||
678 | } | ||
679 | |||
680 | for (i = 0; i < sib_core_nr; i++) { | ||
681 | if (str_to_bitmap(sib_core, &t.sib_core[i])) { | ||
682 | fprintf(stderr, "topology: can't parse siblings map\n"); | ||
683 | goto exit; | ||
684 | } | ||
685 | |||
686 | sib_core += strlen(sib_core) + 1; | ||
687 | } | ||
688 | |||
689 | for (i = 0; i < sib_thr_nr; i++) { | ||
690 | if (str_to_bitmap(sib_thr, &t.sib_thr[i])) { | ||
691 | fprintf(stderr, "topology: can't parse siblings map\n"); | ||
692 | goto exit; | ||
693 | } | ||
694 | |||
695 | sib_thr += strlen(sib_thr) + 1; | ||
696 | } | ||
697 | |||
698 | topology_map = malloc(sizeof(int) * MAX_NR_CPUS); | ||
699 | if (!topology_map) { | ||
700 | fprintf(stderr, "topology: no memory\n"); | ||
701 | goto exit; | ||
702 | } | ||
703 | |||
704 | for (i = 0; i < MAX_NR_CPUS; i++) | ||
705 | topology_map[i] = -1; | ||
706 | |||
707 | scan_core_topology(topology_map, &t); | ||
708 | |||
709 | return 0; | ||
710 | |||
711 | exit: | ||
712 | zfree(&t.sib_core); | ||
713 | zfree(&t.sib_thr); | ||
714 | |||
715 | return -1; | ||
716 | } | ||