@@ -51,6 +51,25 @@ static double time2pixels(u64 time)
51
51
return X ;
52
52
}
53
53
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
+
54
73
void open_svg (const char * filename , int cpus , int rows , u64 start , u64 end )
55
74
{
56
75
int new_width ;
@@ -122,8 +141,10 @@ void svg_sample(int Yslot, int cpu, u64 start, u64 end)
122
141
text_size = text_size /2 ;
123
142
if (text_size > 1.25 )
124
143
text_size = 1.25 ;
144
+ text_size = round_text_size (text_size );
145
+
125
146
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" ,
127
148
time2pixels (start ), Yslot * SLOT_MULT + SLOT_HEIGHT - 1 , text_size , cpu + 1 );
128
149
129
150
}
@@ -162,17 +183,20 @@ void svg_waiting(int Yslot, u64 start, u64 end)
162
183
163
184
text = time_to_string (end - start );
164
185
165
- font_size = 1.0 * (time2pixels (end )- time2pixels (start )) / strlen ( text ) ;
186
+ font_size = 1.0 * (time2pixels (end )- time2pixels (start ));
166
187
167
- if (font_size > 0.2 )
168
- font_size = 0.2 ;
188
+ if (font_size > 3 )
189
+ font_size = 3 ;
169
190
191
+ font_size = round_text_size (font_size );
170
192
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 );
173
196
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" );
176
200
}
177
201
178
202
static char * cpu_model (void )
@@ -211,7 +235,7 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
211
235
cpu2y (cpu ), SLOT_MULT + SLOT_HEIGHT );
212
236
213
237
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" ,
215
239
10 + time2pixels (first_time ), cpu2y (cpu ) + SLOT_HEIGHT /2 , cpu_string );
216
240
217
241
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
225
249
if (!svgfile )
226
250
return ;
227
251
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 );
230
256
width = time2pixels (end )- time2pixels (start );
231
257
if (width > 6 )
232
258
width = 6 ;
233
259
260
+ width = round_text_size (width );
261
+
234
262
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" );
237
267
}
238
268
239
269
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)
254
284
time2pixels (start ), time2pixels (end )- time2pixels (start ),
255
285
cpu2y (cpu ), SLOT_MULT + SLOT_HEIGHT );
256
286
257
- width = time2pixels (end )- time2pixels (start );
287
+ width = ( time2pixels (end )- time2pixels (start ))/ 2.0 ;
258
288
if (width > 6 )
259
289
width = 6 ;
260
290
291
+ width = round_text_size (width );
292
+
261
293
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 );
264
296
}
265
297
266
298
static char * HzToHuman (unsigned long hz )
@@ -299,7 +331,7 @@ void svg_pstate(int cpu, u64 start, u64 end, u64 freq)
299
331
height = 1 + cpu2y (cpu ) + SLOT_MULT + SLOT_HEIGHT - height ;
300
332
fprintf (svgfile , "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n" ,
301
333
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" ,
303
335
time2pixels (start ), height + 0.9 , HzToHuman (freq ));
304
336
305
337
}
@@ -318,29 +350,29 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc
318
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" ,
319
351
time2pixels (start ), row1 * SLOT_MULT + SLOT_HEIGHT , time2pixels (start ), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT /32 );
320
352
if (desc2 )
321
- fprintf (svgfile , "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s ></text>\n" ,
353
+ fprintf (svgfile , "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\" rotate(90)\" font-size=\"0.02pt\">%s ></text></g >\n" ,
322
354
time2pixels (start ), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT /48 , desc2 );
323
355
}
324
356
if (row2 ) {
325
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" ,
326
358
time2pixels (start ), row2 * SLOT_MULT - SLOT_MULT /32 , time2pixels (start ), row2 * SLOT_MULT );
327
359
if (desc1 )
328
- fprintf (svgfile , "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s ></text>\n" ,
360
+ fprintf (svgfile , "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\" rotate(90)\" font-size=\"0.02pt\">%s ></text></g >\n" ,
329
361
time2pixels (start ), row2 * SLOT_MULT - SLOT_MULT /32 , desc1 );
330
362
}
331
363
} else {
332
364
if (row2 ) {
333
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" ,
334
366
time2pixels (start ), row2 * SLOT_MULT + SLOT_HEIGHT , time2pixels (start ), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT /32 );
335
367
if (desc1 )
336
- fprintf (svgfile , "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s <</text>\n" ,
368
+ fprintf (svgfile , "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\" rotate(90)\" font-size=\"0.02pt\">%s <</text></g >\n" ,
337
369
time2pixels (start ), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT /48 , desc1 );
338
370
}
339
371
if (row1 ) {
340
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" ,
341
373
time2pixels (start ), row1 * SLOT_MULT - SLOT_MULT /32 , time2pixels (start ), row1 * SLOT_MULT );
342
374
if (desc2 )
343
- fprintf (svgfile , "<text transform=\"translate(%4.8f,%4.8f) rotate(90)\" font-size=\"0.02pt\">%s <</text>\n" ,
375
+ fprintf (svgfile , "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\" rotate(90)\" font-size=\"0.02pt\">%s <</text></g >\n" ,
344
376
time2pixels (start ), row1 * SLOT_MULT - SLOT_HEIGHT /32 , desc2 );
345
377
}
346
378
}
@@ -390,7 +422,7 @@ void svg_text(int Yslot, u64 start, const char *text)
390
422
if (!svgfile )
391
423
return ;
392
424
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" ,
394
426
time2pixels (start ), Yslot * SLOT_MULT + SLOT_HEIGHT /2 , text );
395
427
}
396
428
@@ -401,7 +433,7 @@ static void svg_legenda_box(int X, const char *text, const char *style)
401
433
402
434
fprintf (svgfile , "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n" ,
403
435
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" ,
405
437
X + boxsize + 5 , boxsize , 0.8 * boxsize , text );
406
438
}
407
439
0 commit comments