aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/svghelper.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/svghelper.c')
-rw-r--r--tools/perf/util/svghelper.c170
1 files changed, 137 insertions, 33 deletions
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index b0fcecdf378d..a778fd0f4ae4 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -25,7 +25,8 @@ static u64 turbo_frequency, max_freq;
25 25
26#define SLOT_MULT 30.0 26#define SLOT_MULT 30.0
27#define SLOT_HEIGHT 25.0 27#define SLOT_HEIGHT 25.0
28#define WIDTH 1000.0 28
29int svg_page_width = 1000;
29 30
30#define MIN_TEXT_SIZE 0.001 31#define MIN_TEXT_SIZE 0.001
31 32
@@ -46,21 +47,54 @@ static double time2pixels(u64 time)
46{ 47{
47 double X; 48 double X;
48 49
49 X = WIDTH * (time - first_time) / (last_time - first_time); 50 X = 1.0 * svg_page_width * (time - first_time) / (last_time - first_time);
50 return X; 51 return X;
51} 52}
52 53
53void open_svg(const char *filename, int cpus, int rows) 54/*
55 * Round text sizes so that the svg viewer only needs a discrete
56 * number of renderings of the font
57 */
58static double round_text_size(double size)
59{
60 int loop = 100;
61 double target = 10.0;
62
63 if (size >= 10.0)
64 return size;
65 while (loop--) {
66 if (size >= target)
67 return target;
68 target = target / 2.0;
69 }
70 return size;
71}
72
73void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
54{ 74{
75 int new_width;
55 76
56 svgfile = fopen(filename, "w"); 77 svgfile = fopen(filename, "w");
57 if (!svgfile) { 78 if (!svgfile) {
58 fprintf(stderr, "Cannot open %s for output\n", filename); 79 fprintf(stderr, "Cannot open %s for output\n", filename);
59 return; 80 return;
60 } 81 }
82 first_time = start;
83 first_time = first_time / 100000000 * 100000000;
84 last_time = end;
85
86 /*
87 * if the recording is short, we default to a width of 1000, but
88 * for longer recordings we want at least 200 units of width per second
89 */
90 new_width = (last_time - first_time) / 5000000;
91
92 if (new_width > svg_page_width)
93 svg_page_width = new_width;
94
61 total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; 95 total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT;
62 fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); 96 fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n");
63 fprintf(svgfile, "<svg width=\"%4.1f\" height=\"%llu\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", WIDTH, total_height); 97 fprintf(svgfile, "<svg width=\"%i\" height=\"%llu\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height);
64 98
65 fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); 99 fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
66 100
@@ -69,7 +103,8 @@ void open_svg(const char *filename, int cpus, int rows)
69 fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 103 fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
70 fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 104 fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
71 fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 105 fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
72 fprintf(svgfile, " rect.waiting { fill:rgb(255,255, 0); fill-opacity:0.3; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 106 fprintf(svgfile, " rect.waiting { fill:rgb(214,214, 0); fill-opacity:0.3; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
107 fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
73 fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n"); 108 fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n");
74 fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n"); 109 fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n");
75 fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n"); 110 fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n");
@@ -92,26 +127,78 @@ void svg_box(int Yslot, u64 start, u64 end, const char *type)
92 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); 127 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type);
93} 128}
94 129
95void svg_sample(int Yslot, int cpu, u64 start, u64 end, const char *type) 130void svg_sample(int Yslot, int cpu, u64 start, u64 end)
96{ 131{
97 double text_size; 132 double text_size;
98 if (!svgfile) 133 if (!svgfile)
99 return; 134 return;
100 135
101 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", 136 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n",
102 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); 137 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT);
103 138
104 text_size = (time2pixels(end)-time2pixels(start)); 139 text_size = (time2pixels(end)-time2pixels(start));
105 if (cpu > 9) 140 if (cpu > 9)
106 text_size = text_size/2; 141 text_size = text_size/2;
107 if (text_size > 1.25) 142 if (text_size > 1.25)
108 text_size = 1.25; 143 text_size = 1.25;
144 text_size = round_text_size(text_size);
145
109 if (text_size > MIN_TEXT_SIZE) 146 if (text_size > MIN_TEXT_SIZE)
110 fprintf(svgfile, "<text transform=\"translate(%1.8f,%1.8f)\" font-size=\"%1.6fpt\">%i</text>\n", 147 fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n",
111 time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); 148 time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1);
112 149
113} 150}
114 151
152static char *time_to_string(u64 duration)
153{
154 static char text[80];
155
156 text[0] = 0;
157
158 if (duration < 1000) /* less than 1 usec */
159 return text;
160
161 if (duration < 1000 * 1000) { /* less than 1 msec */
162 sprintf(text, "%4.1f us", duration / 1000.0);
163 return text;
164 }
165 sprintf(text, "%4.1f ms", duration / 1000.0 / 1000);
166
167 return text;
168}
169
170void svg_waiting(int Yslot, u64 start, u64 end)
171{
172 char *text;
173 const char *style;
174 double font_size;
175
176 if (!svgfile)
177 return;
178
179 style = "waiting";
180
181 if (end-start > 10 * 1000000) /* 10 msec */
182 style = "WAITING";
183
184 text = time_to_string(end-start);
185
186 font_size = 1.0 * (time2pixels(end)-time2pixels(start));
187
188 if (font_size > 3)
189 font_size = 3;
190
191 font_size = round_text_size(font_size);
192
193 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT);
194 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
195 time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style);
196 if (font_size > MIN_TEXT_SIZE)
197 fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%1.8fpt\"> %s</text>\n",
198 font_size, text);
199 fprintf(svgfile, "</g>\n");
200}
201
115static char *cpu_model(void) 202static char *cpu_model(void)
116{ 203{
117 static char cpu_m[255]; 204 static char cpu_m[255];
@@ -148,7 +235,7 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
148 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); 235 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
149 236
150 sprintf(cpu_string, "CPU %i", (int)cpu+1); 237 sprintf(cpu_string, "CPU %i", (int)cpu+1);
151 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\">%s</text>\n", 238 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
152 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); 239 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
153 240
154 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", 241 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n",
@@ -162,15 +249,21 @@ void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name
162 if (!svgfile) 249 if (!svgfile)
163 return; 250 return;
164 251
165 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", 252
166 time2pixels(start), time2pixels(end)-time2pixels(start), cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT, type); 253 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu));
254 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
255 time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type);
167 width = time2pixels(end)-time2pixels(start); 256 width = time2pixels(end)-time2pixels(start);
168 if (width > 6) 257 if (width > 6)
169 width = 6; 258 width = 6;
170 259
260 width = round_text_size(width);
261
171 if (width > MIN_TEXT_SIZE) 262 if (width > MIN_TEXT_SIZE)
172 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">%s</text>\n", 263 fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n",
173 time2pixels(start), cpu2y(cpu), width, name); 264 width, name);
265
266 fprintf(svgfile, "</g>\n");
174} 267}
175 268
176void svg_cstate(int cpu, u64 start, u64 end, int type) 269void svg_cstate(int cpu, u64 start, u64 end, int type)
@@ -191,13 +284,15 @@ void svg_cstate(int cpu, u64 start, u64 end, int type)
191 time2pixels(start), time2pixels(end)-time2pixels(start), 284 time2pixels(start), time2pixels(end)-time2pixels(start),
192 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); 285 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
193 286
194 width = time2pixels(end)-time2pixels(start); 287 width = (time2pixels(end)-time2pixels(start))/2.0;
195 if (width > 6) 288 if (width > 6)
196 width = 6; 289 width = 6;
197 290
291 width = round_text_size(width);
292
198 if (width > MIN_TEXT_SIZE) 293 if (width > MIN_TEXT_SIZE)
199 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">C%i</text>\n", 294 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n",
200 time2pixels(start), cpu2y(cpu), width, type); 295 time2pixels(start), cpu2y(cpu)+width, width, type);
201} 296}
202 297
203static char *HzToHuman(unsigned long hz) 298static char *HzToHuman(unsigned long hz)
@@ -236,13 +331,13 @@ void svg_pstate(int cpu, u64 start, u64 end, u64 freq)
236 height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; 331 height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height;
237 fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n", 332 fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n",
238 time2pixels(start), time2pixels(end), height, height); 333 time2pixels(start), time2pixels(end), height, height);
239 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"0.25pt\">%s</text>\n", 334 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n",
240 time2pixels(start), height+0.9, HzToHuman(freq)); 335 time2pixels(start), height+0.9, HzToHuman(freq));
241 336
242} 337}
243 338
244 339
245void svg_partial_wakeline(u64 start, int row1, int row2) 340void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2)
246{ 341{
247 double height; 342 double height;
248 343
@@ -251,21 +346,35 @@ void svg_partial_wakeline(u64 start, int row1, int row2)
251 346
252 347
253 if (row1 < row2) { 348 if (row1 < row2) {
254 if (row1) 349 if (row1) {
255 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", 350 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",
256 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); 351 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
257 352 if (desc2)
258 if (row2) 353 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
354 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2);
355 }
356 if (row2) {
259 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", 357 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",
260 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT); 358 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT);
359 if (desc1)
360 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
361 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1);
362 }
261 } else { 363 } else {
262 if (row2) 364 if (row2) {
263 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", 365 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",
264 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); 366 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
265 367 if (desc1)
266 if (row1) 368 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
369 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1);
370 }
371 if (row1) {
267 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", 372 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",
268 time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT); 373 time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT);
374 if (desc2)
375 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
376 time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2);
377 }
269 } 378 }
270 height = row1 * SLOT_MULT; 379 height = row1 * SLOT_MULT;
271 if (row2 > row1) 380 if (row2 > row1)
@@ -313,7 +422,7 @@ void svg_text(int Yslot, u64 start, const char *text)
313 if (!svgfile) 422 if (!svgfile)
314 return; 423 return;
315 424
316 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\">%s</text>\n", 425 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
317 time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text); 426 time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text);
318} 427}
319 428
@@ -324,7 +433,7 @@ static void svg_legenda_box(int X, const char *text, const char *style)
324 433
325 fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", 434 fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
326 X, boxsize, boxsize, style); 435 X, boxsize, boxsize, style);
327 fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.4fpt\">%s</text>\n", 436 fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.8fpt\">%s</text>\n",
328 X + boxsize + 5, boxsize, 0.8 * boxsize, text); 437 X + boxsize + 5, boxsize, 0.8 * boxsize, text);
329} 438}
330 439
@@ -342,15 +451,10 @@ void svg_legenda(void)
342 svg_legenda_box(800, "Blocked on IO", "blocked"); 451 svg_legenda_box(800, "Blocked on IO", "blocked");
343} 452}
344 453
345void svg_time_grid(u64 start, u64 end) 454void svg_time_grid(void)
346{ 455{
347 u64 i; 456 u64 i;
348 457
349 first_time = start;
350 last_time = end;
351
352 first_time = first_time / 100000000 * 100000000;
353
354 if (!svgfile) 458 if (!svgfile)
355 return; 459 return;
356 460