]>
git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - tools/perf/util/svghelper.c
1 // SPDX-License-Identifier: GPL-2.0-only
3 * svghelper.c - helper functions for outputting svg
5 * (C) Copyright 2009 Intel Corporation
8 * Arjan van de Ven <arjan@linux.intel.com>
16 #include <linux/bitmap.h>
17 #include <linux/time64.h>
20 #include "svghelper.h"
24 static u64 first_time
, last_time
;
25 static u64 turbo_frequency
, max_freq
;
28 #define SLOT_MULT 30.0
29 #define SLOT_HEIGHT 25.0
30 #define SLOT_HALF (SLOT_HEIGHT / 2)
32 int svg_page_width
= 1000;
34 const char *svg_highlight_name
;
36 #define MIN_TEXT_SIZE 0.01
38 static u64 total_height
;
41 static double cpu2slot(int cpu
)
46 static int *topology_map
;
48 static double cpu2y(int cpu
)
51 return cpu2slot(topology_map
[cpu
]) * SLOT_MULT
;
53 return cpu2slot(cpu
) * SLOT_MULT
;
56 static double time2pixels(u64 __time
)
60 X
= 1.0 * svg_page_width
* (__time
- first_time
) / (last_time
- first_time
);
65 * Round text sizes so that the svg viewer only needs a discrete
66 * number of renderings of the font
68 static double round_text_size(double size
)
78 target
= target
/ 2.0;
83 void open_svg(const char *filename
, int cpus
, int rows
, u64 start
, u64 end
)
87 svgfile
= fopen(filename
, "w");
89 fprintf(stderr
, "Cannot open %s for output\n", filename
);
93 first_time
= first_time
/ 100000000 * 100000000;
97 * if the recording is short, we default to a width of 1000, but
98 * for longer recordings we want at least 200 units of width per second
100 new_width
= (last_time
- first_time
) / 5000000;
102 if (new_width
> svg_page_width
)
103 svg_page_width
= new_width
;
105 total_height
= (1 + rows
+ cpu2slot(cpus
)) * SLOT_MULT
;
106 fprintf(svgfile
, "<?xml version=\"1.0\" standalone=\"no\"?> \n");
107 fprintf(svgfile
, "<!DOCTYPE svg SYSTEM \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
108 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
, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
112 fprintf(svgfile
, " rect { stroke-width: 1; }\n");
113 fprintf(svgfile
, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n");
114 fprintf(svgfile
, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
115 fprintf(svgfile
, " rect.process3 { fill:rgb(180,180,180); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
116 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_hi{ fill:rgb(255,128, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
118 fprintf(svgfile
, " rect.error { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
119 fprintf(svgfile
, " rect.net { fill:rgb( 0,128, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
120 fprintf(svgfile
, " rect.disk { fill:rgb( 0, 0,255); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
121 fprintf(svgfile
, " rect.sync { fill:rgb(128,128, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
122 fprintf(svgfile
, " rect.poll { fill:rgb( 0,128,128); fill-opacity:0.2; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
123 fprintf(svgfile
, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
124 fprintf(svgfile
, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
125 fprintf(svgfile
, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
126 fprintf(svgfile
, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n");
127 fprintf(svgfile
, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n");
128 fprintf(svgfile
, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n");
129 fprintf(svgfile
, " rect.c2 { fill:rgb(255,172,172); fill-opacity:0.5; stroke-width:0; } \n");
130 fprintf(svgfile
, " rect.c3 { fill:rgb(255,130,130); fill-opacity:0.5; stroke-width:0; } \n");
131 fprintf(svgfile
, " rect.c4 { fill:rgb(255, 88, 88); fill-opacity:0.5; stroke-width:0; } \n");
132 fprintf(svgfile
, " rect.c5 { fill:rgb(255, 44, 44); fill-opacity:0.5; stroke-width:0; } \n");
133 fprintf(svgfile
, " rect.c6 { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; } \n");
134 fprintf(svgfile
, " line.pstate { stroke:rgb(255,255, 0); stroke-opacity:0.8; stroke-width:2; } \n");
136 fprintf(svgfile
, " ]]>\n </style>\n</defs>\n");
139 static double normalize_height(double height
)
143 else if (height
< 0.50)
145 else if (height
< 0.75)
151 void svg_ubox(int Yslot
, u64 start
, u64 end
, double height
, const char *type
, int fd
, int err
, int merges
)
153 double w
= time2pixels(end
) - time2pixels(start
);
154 height
= normalize_height(height
);
159 fprintf(svgfile
, "<g>\n");
160 fprintf(svgfile
, "<title>fd=%d error=%d merges=%d</title>\n", fd
, err
, merges
);
161 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"%s\"/>\n",
167 fprintf(svgfile
, "</g>\n");
170 void svg_lbox(int Yslot
, u64 start
, u64 end
, double height
, const char *type
, int fd
, int err
, int merges
)
172 double w
= time2pixels(end
) - time2pixels(start
);
173 height
= normalize_height(height
);
178 fprintf(svgfile
, "<g>\n");
179 fprintf(svgfile
, "<title>fd=%d error=%d merges=%d</title>\n", fd
, err
, merges
);
180 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"%s\"/>\n",
183 Yslot
* SLOT_MULT
+ SLOT_HEIGHT
- SLOT_HALF
* height
,
186 fprintf(svgfile
, "</g>\n");
189 void svg_fbox(int Yslot
, u64 start
, u64 end
, double height
, const char *type
, int fd
, int err
, int merges
)
191 double w
= time2pixels(end
) - time2pixels(start
);
192 height
= normalize_height(height
);
197 fprintf(svgfile
, "<g>\n");
198 fprintf(svgfile
, "<title>fd=%d error=%d merges=%d</title>\n", fd
, err
, merges
);
199 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"%s\"/>\n",
202 Yslot
* SLOT_MULT
+ SLOT_HEIGHT
- SLOT_HEIGHT
* height
,
203 SLOT_HEIGHT
* height
,
205 fprintf(svgfile
, "</g>\n");
208 void svg_box(int Yslot
, u64 start
, u64 end
, const char *type
)
213 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"%s\"/>\n",
214 time2pixels(start
), time2pixels(end
)-time2pixels(start
), Yslot
* SLOT_MULT
, SLOT_HEIGHT
, type
);
217 static char *time_to_string(u64 duration
);
218 void svg_blocked(int Yslot
, int cpu
, u64 start
, u64 end
, const char *backtrace
)
223 fprintf(svgfile
, "<g>\n");
224 fprintf(svgfile
, "<title>#%d blocked %s</title>\n", cpu
,
225 time_to_string(end
- start
));
227 fprintf(svgfile
, "<desc>Blocked on:\n%s</desc>\n", backtrace
);
228 svg_box(Yslot
, start
, end
, "blocked");
229 fprintf(svgfile
, "</g>\n");
232 void svg_running(int Yslot
, int cpu
, u64 start
, u64 end
, const char *backtrace
)
240 if (svg_highlight
&& end
- start
> svg_highlight
)
244 fprintf(svgfile
, "<g>\n");
246 fprintf(svgfile
, "<title>#%d running %s</title>\n",
247 cpu
, time_to_string(end
- start
));
249 fprintf(svgfile
, "<desc>Switched because:\n%s</desc>\n", backtrace
);
250 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"%s\"/>\n",
251 time2pixels(start
), time2pixels(end
)-time2pixels(start
), Yslot
* SLOT_MULT
, SLOT_HEIGHT
,
254 text_size
= (time2pixels(end
)-time2pixels(start
));
256 text_size
= text_size
/2;
257 if (text_size
> 1.25)
259 text_size
= round_text_size(text_size
);
261 if (text_size
> MIN_TEXT_SIZE
)
262 fprintf(svgfile
, "<text x=\"%.8f\" y=\"%.8f\" font-size=\"%.8fpt\">%i</text>\n",
263 time2pixels(start
), Yslot
* SLOT_MULT
+ SLOT_HEIGHT
- 1, text_size
, cpu
+ 1);
265 fprintf(svgfile
, "</g>\n");
268 static char *time_to_string(u64 duration
)
270 static char text
[80];
274 if (duration
< NSEC_PER_USEC
) /* less than 1 usec */
277 if (duration
< NSEC_PER_MSEC
) { /* less than 1 msec */
278 sprintf(text
, "%.1f us", duration
/ (double)NSEC_PER_USEC
);
281 sprintf(text
, "%.1f ms", duration
/ (double)NSEC_PER_MSEC
);
286 void svg_waiting(int Yslot
, int cpu
, u64 start
, u64 end
, const char *backtrace
)
297 if (end
-start
> 10 * NSEC_PER_MSEC
) /* 10 msec */
300 text
= time_to_string(end
-start
);
302 font_size
= 1.0 * (time2pixels(end
)-time2pixels(start
));
307 font_size
= round_text_size(font_size
);
309 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\">\n", time2pixels(start
), Yslot
* SLOT_MULT
);
310 fprintf(svgfile
, "<title>#%d waiting %s</title>\n", cpu
, time_to_string(end
- start
));
312 fprintf(svgfile
, "<desc>Waiting on:\n%s</desc>\n", backtrace
);
313 fprintf(svgfile
, "<rect x=\"0\" width=\"%.8f\" y=\"0\" height=\"%.1f\" class=\"%s\"/>\n",
314 time2pixels(end
)-time2pixels(start
), SLOT_HEIGHT
, style
);
315 if (font_size
> MIN_TEXT_SIZE
)
316 fprintf(svgfile
, "<text transform=\"rotate(90)\" font-size=\"%.8fpt\"> %s</text>\n",
318 fprintf(svgfile
, "</g>\n");
321 static char *cpu_model(void)
323 static char cpu_m
[255];
329 file
= fopen("/proc/cpuinfo", "r");
331 while (fgets(buf
, 255, file
)) {
332 if (strstr(buf
, "model name")) {
333 strlcpy(cpu_m
, &buf
[13], 255);
341 file
= fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r");
343 while (fgets(buf
, 255, file
)) {
345 freq
= strtoull(buf
, NULL
, 10);
354 void svg_cpu_box(int cpu
, u64 __max_freq
, u64 __turbo_freq
)
360 max_freq
= __max_freq
;
361 turbo_frequency
= __turbo_freq
;
363 fprintf(svgfile
, "<g>\n");
365 fprintf(svgfile
, "<rect x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\" class=\"cpu\"/>\n",
366 time2pixels(first_time
),
367 time2pixels(last_time
)-time2pixels(first_time
),
368 cpu2y(cpu
), SLOT_MULT
+SLOT_HEIGHT
);
370 sprintf(cpu_string
, "CPU %i", (int)cpu
);
371 fprintf(svgfile
, "<text x=\"%.8f\" y=\"%.8f\">%s</text>\n",
372 10+time2pixels(first_time
), cpu2y(cpu
) + SLOT_HEIGHT
/2, cpu_string
);
374 fprintf(svgfile
, "<text transform=\"translate(%.8f,%.8f)\" font-size=\"1.25pt\">%s</text>\n",
375 10+time2pixels(first_time
), cpu2y(cpu
) + SLOT_MULT
+ SLOT_HEIGHT
- 4, cpu_model());
377 fprintf(svgfile
, "</g>\n");
380 void svg_process(int cpu
, u64 start
, u64 end
, int pid
, const char *name
, const char *backtrace
)
388 if (svg_highlight
&& end
- start
>= svg_highlight
)
390 else if (svg_highlight_name
&& strstr(name
, svg_highlight_name
))
395 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\">\n", time2pixels(start
), cpu2y(cpu
));
396 fprintf(svgfile
, "<title>%d %s running %s</title>\n", pid
, name
, time_to_string(end
- start
));
398 fprintf(svgfile
, "<desc>Switched because:\n%s</desc>\n", backtrace
);
399 fprintf(svgfile
, "<rect x=\"0\" width=\"%.8f\" y=\"0\" height=\"%.1f\" class=\"%s\"/>\n",
400 time2pixels(end
)-time2pixels(start
), SLOT_MULT
+SLOT_HEIGHT
, type
);
401 width
= time2pixels(end
)-time2pixels(start
);
405 width
= round_text_size(width
);
407 if (width
> MIN_TEXT_SIZE
)
408 fprintf(svgfile
, "<text transform=\"rotate(90)\" font-size=\"%.8fpt\">%s</text>\n",
411 fprintf(svgfile
, "</g>\n");
414 void svg_cstate(int cpu
, u64 start
, u64 end
, int type
)
423 fprintf(svgfile
, "<g>\n");
427 sprintf(style
, "c%i", type
);
429 fprintf(svgfile
, "<rect class=\"%s\" x=\"%.8f\" width=\"%.8f\" y=\"%.1f\" height=\"%.1f\"/>\n",
431 time2pixels(start
), time2pixels(end
)-time2pixels(start
),
432 cpu2y(cpu
), SLOT_MULT
+SLOT_HEIGHT
);
434 width
= (time2pixels(end
)-time2pixels(start
))/2.0;
438 width
= round_text_size(width
);
440 if (width
> MIN_TEXT_SIZE
)
441 fprintf(svgfile
, "<text x=\"%.8f\" y=\"%.8f\" font-size=\"%.8fpt\">C%i</text>\n",
442 time2pixels(start
), cpu2y(cpu
)+width
, width
, type
);
444 fprintf(svgfile
, "</g>\n");
447 static char *HzToHuman(unsigned long hz
)
449 static char buffer
[1024];
450 unsigned long long Hz
;
452 memset(buffer
, 0, 1024);
456 /* default: just put the Number in */
457 sprintf(buffer
, "%9lli", Hz
);
460 sprintf(buffer
, " %6lli Mhz", (Hz
+500)/1000);
463 sprintf(buffer
, " %6.2f Ghz", (Hz
+5000.0)/1000000);
465 if (Hz
== turbo_frequency
)
466 sprintf(buffer
, "Turbo");
471 void svg_pstate(int cpu
, u64 start
, u64 end
, u64 freq
)
478 fprintf(svgfile
, "<g>\n");
481 height
= freq
* 1.0 / max_freq
* (SLOT_HEIGHT
+ SLOT_MULT
);
482 height
= 1 + cpu2y(cpu
) + SLOT_MULT
+ SLOT_HEIGHT
- height
;
483 fprintf(svgfile
, "<line x1=\"%.8f\" x2=\"%.8f\" y1=\"%.1f\" y2=\"%.1f\" class=\"pstate\"/>\n",
484 time2pixels(start
), time2pixels(end
), height
, height
);
485 fprintf(svgfile
, "<text x=\"%.8f\" y=\"%.8f\" font-size=\"0.25pt\">%s</text>\n",
486 time2pixels(start
), height
+0.9, HzToHuman(freq
));
488 fprintf(svgfile
, "</g>\n");
492 void svg_partial_wakeline(u64 start
, int row1
, char *desc1
, int row2
, char *desc2
, const char *backtrace
)
500 fprintf(svgfile
, "<g>\n");
502 fprintf(svgfile
, "<title>%s wakes up %s</title>\n",
504 desc2
? desc2
: "?");
507 fprintf(svgfile
, "<desc>%s</desc>\n", backtrace
);
511 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
512 time2pixels(start
), row1
* SLOT_MULT
+ SLOT_HEIGHT
, time2pixels(start
), row1
* SLOT_MULT
+ SLOT_HEIGHT
+ SLOT_MULT
/32);
514 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n",
515 time2pixels(start
), row1
* SLOT_MULT
+ SLOT_HEIGHT
+ SLOT_HEIGHT
/48, desc2
);
518 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
519 time2pixels(start
), row2
* SLOT_MULT
- SLOT_MULT
/32, time2pixels(start
), row2
* SLOT_MULT
);
521 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n",
522 time2pixels(start
), row2
* SLOT_MULT
- SLOT_MULT
/32, desc1
);
526 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
527 time2pixels(start
), row2
* SLOT_MULT
+ SLOT_HEIGHT
, time2pixels(start
), row2
* SLOT_MULT
+ SLOT_HEIGHT
+ SLOT_MULT
/32);
529 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n",
530 time2pixels(start
), row2
* SLOT_MULT
+ SLOT_HEIGHT
+ SLOT_MULT
/48, desc1
);
533 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
534 time2pixels(start
), row1
* SLOT_MULT
- SLOT_MULT
/32, time2pixels(start
), row1
* SLOT_MULT
);
536 fprintf(svgfile
, "<g transform=\"translate(%.8f,%.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n",
537 time2pixels(start
), row1
* SLOT_MULT
- SLOT_HEIGHT
/32, desc2
);
540 height
= row1
* SLOT_MULT
;
542 height
+= SLOT_HEIGHT
;
544 fprintf(svgfile
, "<circle cx=\"%.8f\" cy=\"%.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
545 time2pixels(start
), height
);
547 fprintf(svgfile
, "</g>\n");
550 void svg_wakeline(u64 start
, int row1
, int row2
, const char *backtrace
)
558 fprintf(svgfile
, "<g>\n");
561 fprintf(svgfile
, "<desc>%s</desc>\n", backtrace
);
564 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
565 time2pixels(start
), row1
* SLOT_MULT
+ SLOT_HEIGHT
, time2pixels(start
), row2
* SLOT_MULT
);
567 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%.2f\" style=\"stroke:rgb(32,255,32);stroke-width:0.009\"/>\n",
568 time2pixels(start
), row2
* SLOT_MULT
+ SLOT_HEIGHT
, time2pixels(start
), row1
* SLOT_MULT
);
570 height
= row1
* SLOT_MULT
;
572 height
+= SLOT_HEIGHT
;
573 fprintf(svgfile
, "<circle cx=\"%.8f\" cy=\"%.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
574 time2pixels(start
), height
);
576 fprintf(svgfile
, "</g>\n");
579 void svg_interrupt(u64 start
, int row
, const char *backtrace
)
584 fprintf(svgfile
, "<g>\n");
586 fprintf(svgfile
, "<title>Wakeup from interrupt</title>\n");
589 fprintf(svgfile
, "<desc>%s</desc>\n", backtrace
);
591 fprintf(svgfile
, "<circle cx=\"%.8f\" cy=\"%.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n",
592 time2pixels(start
), row
* SLOT_MULT
);
593 fprintf(svgfile
, "<circle cx=\"%.8f\" cy=\"%.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n",
594 time2pixels(start
), row
* SLOT_MULT
+ SLOT_HEIGHT
);
596 fprintf(svgfile
, "</g>\n");
599 void svg_text(int Yslot
, u64 start
, const char *text
)
604 fprintf(svgfile
, "<text x=\"%.8f\" y=\"%.8f\">%s</text>\n",
605 time2pixels(start
), Yslot
* SLOT_MULT
+SLOT_HEIGHT
/2, text
);
608 static void svg_legenda_box(int X
, const char *text
, const char *style
)
611 boxsize
= SLOT_HEIGHT
/ 2;
613 fprintf(svgfile
, "<rect x=\"%i\" width=\"%.8f\" y=\"0\" height=\"%.1f\" class=\"%s\"/>\n",
614 X
, boxsize
, boxsize
, style
);
615 fprintf(svgfile
, "<text transform=\"translate(%.8f, %.8f)\" font-size=\"%.8fpt\">%s</text>\n",
616 X
+ boxsize
+ 5, boxsize
, 0.8 * boxsize
, text
);
619 void svg_io_legenda(void)
624 fprintf(svgfile
, "<g>\n");
625 svg_legenda_box(0, "Disk", "disk");
626 svg_legenda_box(100, "Network", "net");
627 svg_legenda_box(200, "Sync", "sync");
628 svg_legenda_box(300, "Poll", "poll");
629 svg_legenda_box(400, "Error", "error");
630 fprintf(svgfile
, "</g>\n");
633 void svg_legenda(void)
638 fprintf(svgfile
, "<g>\n");
639 svg_legenda_box(0, "Running", "sample");
640 svg_legenda_box(100, "Idle","c1");
641 svg_legenda_box(200, "Deeper Idle", "c3");
642 svg_legenda_box(350, "Deepest Idle", "c6");
643 svg_legenda_box(550, "Sleeping", "process2");
644 svg_legenda_box(650, "Waiting for cpu", "waiting");
645 svg_legenda_box(800, "Blocked on IO", "blocked");
646 fprintf(svgfile
, "</g>\n");
649 void svg_time_grid(double min_thickness
)
657 while (i
< last_time
) {
659 double thickness
= 0.075;
660 if ((i
% 100000000) == 0) {
664 if ((i
% 1000000000) == 0) {
669 if (thickness
>= min_thickness
)
670 fprintf(svgfile
, "<line x1=\"%.8f\" y1=\"%.2f\" x2=\"%.8f\" y2=\"%" PRIu64
"\" style=\"stroke:rgb(%i,%i,%i);stroke-width:%.3f\"/>\n",
671 time2pixels(i
), SLOT_MULT
/2, time2pixels(i
),
672 total_height
, color
, color
, color
, thickness
);
681 fprintf(svgfile
, "</svg>\n");
687 #define cpumask_bits(maskp) ((maskp)->bits)
688 typedef struct { DECLARE_BITMAP(bits
, MAX_NR_CPUS
); } cpumask_t
;
697 static void scan_thread_topology(int *map
, struct topology
*t
, int cpu
, int *pos
)
702 for (i
= 0; i
< t
->sib_thr_nr
; i
++) {
703 if (!test_bit(cpu
, cpumask_bits(&t
->sib_thr
[i
])))
706 for_each_set_bit(thr
,
707 cpumask_bits(&t
->sib_thr
[i
]),
714 static void scan_core_topology(int *map
, struct topology
*t
)
720 for (i
= 0; i
< t
->sib_core_nr
; i
++)
721 for_each_set_bit(cpu
,
722 cpumask_bits(&t
->sib_core
[i
]),
724 scan_thread_topology(map
, t
, cpu
, &pos
);
727 static int str_to_bitmap(char *s
, cpumask_t
*b
)
738 for (i
= 0; i
< m
->nr
; i
++) {
740 if (c
>= MAX_NR_CPUS
) {
745 set_bit(c
, cpumask_bits(b
));
753 int svg_build_topology_map(char *sib_core
, int sib_core_nr
,
754 char *sib_thr
, int sib_thr_nr
)
759 t
.sib_core_nr
= sib_core_nr
;
760 t
.sib_thr_nr
= sib_thr_nr
;
761 t
.sib_core
= calloc(sib_core_nr
, sizeof(cpumask_t
));
762 t
.sib_thr
= calloc(sib_thr_nr
, sizeof(cpumask_t
));
764 if (!t
.sib_core
|| !t
.sib_thr
) {
765 fprintf(stderr
, "topology: no memory\n");
769 for (i
= 0; i
< sib_core_nr
; i
++) {
770 if (str_to_bitmap(sib_core
, &t
.sib_core
[i
])) {
771 fprintf(stderr
, "topology: can't parse siblings map\n");
775 sib_core
+= strlen(sib_core
) + 1;
778 for (i
= 0; i
< sib_thr_nr
; i
++) {
779 if (str_to_bitmap(sib_thr
, &t
.sib_thr
[i
])) {
780 fprintf(stderr
, "topology: can't parse siblings map\n");
784 sib_thr
+= strlen(sib_thr
) + 1;
787 topology_map
= malloc(sizeof(int) * MAX_NR_CPUS
);
789 fprintf(stderr
, "topology: no memory\n");
793 for (i
= 0; i
< MAX_NR_CPUS
; i
++)
794 topology_map
[i
] = -1;
796 scan_core_topology(topology_map
, &t
);