Skip to content

Commit 611a546

Browse files
fenrus75Ingo Molnar
authored andcommitted
perf util: SVG performance improvements
Tweak the output SVG to increase performance in SVG viewers by limiting the different types of font sizes and by smarter transformations on the text. At least with Inkscape this gives a notable performance improvement during zoom and scrolling. Signed-off-by: Arjan van de Ven <arjan@linux.intel.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> LKML-Reference: <20090920181438.3a49cb93@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 5094b65 commit 611a546

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

tools/perf/util/svghelper.c

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ static double time2pixels(u64 time)
5151
return X;
5252
}
5353

54+
/*
55+
* Round text sizes so that the svg viewer only needs a discrete
56+
* number of renderings of the font
57+
*/
58+
static 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+
5473
void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
5574
{
5675
int new_width;
@@ -122,8 +141,10 @@ void svg_sample(int Yslot, int cpu, u64 start, u64 end)
122141
text_size = text_size/2;
123142
if (text_size > 1.25)
124143
text_size = 1.25;
144+
text_size = round_text_size(text_size);
145+
125146
if (text_size > MIN_TEXT_SIZE)
126-
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",
127148
time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1);
128149

129150
}
@@ -162,17 +183,20 @@ void svg_waiting(int Yslot, u64 start, u64 end)
162183

163184
text = time_to_string(end-start);
164185

165-
font_size = 1.0 * (time2pixels(end)-time2pixels(start)) / strlen(text);
186+
font_size = 1.0 * (time2pixels(end)-time2pixels(start));
166187

167-
if (font_size > 0.2)
168-
font_size = 0.2;
188+
if (font_size > 3)
189+
font_size = 3;
169190

191+
font_size = round_text_size(font_size);
170192

171-
fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n",
172-
time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, style);
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);
173196
if (font_size > MIN_TEXT_SIZE)
174-
fprintf(svgfile, "<text transform=\"translate(%1.8f,%1.8f)\" font-size=\"%1.6fpt\">%s</text>\n",
175-
time2pixels(start), Yslot * SLOT_MULT + 2, font_size, text);
197+
fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%1.8fpt\"> %s</text>\n",
198+
font_size, text);
199+
fprintf(svgfile, "</g>\n");
176200
}
177201

178202
static char *cpu_model(void)
@@ -211,7 +235,7 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
211235
cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
212236

213237
sprintf(cpu_string, "CPU %i", (int)cpu+1);
214-
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",
215239
10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
216240

217241
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n",
@@ -225,15 +249,21 @@ void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name
225249
if (!svgfile)
226250
return;
227251

228-
fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n",
229-
time2pixels(start), time2pixels(end)-time2pixels(start), cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT, type);
252+
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);
230256
width = time2pixels(end)-time2pixels(start);
231257
if (width > 6)
232258
width = 6;
233259

260+
width = round_text_size(width);
261+
234262
if (width > MIN_TEXT_SIZE)
235-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">%s</text>\n",
236-
time2pixels(start), cpu2y(cpu), width, name);
263+
fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n",
264+
width, name);
265+
266+
fprintf(svgfile, "</g>\n");
237267
}
238268

239269
void svg_cstate(int cpu, u64 start, u64 end, int type)
@@ -254,13 +284,15 @@ void svg_cstate(int cpu, u64 start, u64 end, int type)
254284
time2pixels(start), time2pixels(end)-time2pixels(start),
255285
cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
256286

257-
width = time2pixels(end)-time2pixels(start);
287+
width = (time2pixels(end)-time2pixels(start))/2.0;
258288
if (width > 6)
259289
width = 6;
260290

291+
width = round_text_size(width);
292+
261293
if (width > MIN_TEXT_SIZE)
262-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"%3.4fpt\">C%i</text>\n",
263-
time2pixels(start), cpu2y(cpu), width, type);
294+
fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n",
295+
time2pixels(start), cpu2y(cpu)+width, width, type);
264296
}
265297

266298
static char *HzToHuman(unsigned long hz)
@@ -299,7 +331,7 @@ void svg_pstate(int cpu, u64 start, u64 end, u64 freq)
299331
height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height;
300332
fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n",
301333
time2pixels(start), time2pixels(end), height, height);
302-
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",
303335
time2pixels(start), height+0.9, HzToHuman(freq));
304336

305337
}
@@ -318,29 +350,29 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc
318350
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",
319351
time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
320352
if (desc2)
321-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s &gt;</text>\n",
353+
fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
322354
time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2);
323355
}
324356
if (row2) {
325357
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",
326358
time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT);
327359
if (desc1)
328-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s &gt;</text>\n",
360+
fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
329361
time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1);
330362
}
331363
} else {
332364
if (row2) {
333365
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",
334366
time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
335367
if (desc1)
336-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s &lt;</text>\n",
368+
fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
337369
time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1);
338370
}
339371
if (row1) {
340372
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",
341373
time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT);
342374
if (desc2)
343-
fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s &lt;</text>\n",
375+
fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
344376
time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2);
345377
}
346378
}
@@ -390,7 +422,7 @@ void svg_text(int Yslot, u64 start, const char *text)
390422
if (!svgfile)
391423
return;
392424

393-
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",
394426
time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text);
395427
}
396428

@@ -401,7 +433,7 @@ static void svg_legenda_box(int X, const char *text, const char *style)
401433

402434
fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
403435
X, boxsize, boxsize, style);
404-
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",
405437
X + boxsize + 5, boxsize, 0.8 * boxsize, text);
406438
}
407439

0 commit comments

Comments
 (0)