Skip to content

Commit 5094b65

Browse files
fenrus75Ingo Molnar
authored andcommitted
perf util: Make the timechart SVG width dynamic
This patch adds a command line option for timechart that allows the user to specify the width of the SVG file. This patch also makes sure that each second of recording has at least 200 units (pixels at 96 DPI) of width. This impacts recordings longer than 5 seconds; recordings shorter than 5 second will scale up to have a width of 1000 units for the whole recording (as before). 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: <20090920181416.69570c5d@linux.intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent a92fe7b commit 5094b65

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

tools/perf/Documentation/perf-timechart.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ OPTIONS
2828
-i::
2929
--input=::
3030
Select the input file (default: perf.data)
31+
-w::
32+
--width=::
33+
Select the width of the SVG file (default: 1000)
3134

3235

3336
SEE ALSO

tools/perf/builtin-timechart.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,9 @@ static void write_svg_file(const char *filename)
915915
if (count < 15)
916916
count = determine_display_tasks(TIME_THRESH / 10);
917917

918-
open_svg(filename, numcpus, count);
918+
open_svg(filename, numcpus, count, first_time, last_time);
919919

920-
svg_time_grid(first_time, last_time);
920+
svg_time_grid();
921921
svg_legenda();
922922

923923
for (i = 0; i < numcpus; i++)
@@ -1132,6 +1132,8 @@ static const struct option options[] = {
11321132
"input file name"),
11331133
OPT_STRING('o', "output", &output_name, "file",
11341134
"output file name"),
1135+
OPT_INTEGER('w', "width", &svg_page_width,
1136+
"page width"),
11351137
OPT_END()
11361138
};
11371139

tools/perf/util/svghelper.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static u64 turbo_frequency, max_freq;
2525

2626
#define SLOT_MULT 30.0
2727
#define SLOT_HEIGHT 25.0
28-
#define WIDTH 1000.0
28+
29+
int svg_page_width = 1000;
2930

3031
#define MIN_TEXT_SIZE 0.001
3132

@@ -46,21 +47,35 @@ static double time2pixels(u64 time)
4647
{
4748
double X;
4849

49-
X = WIDTH * (time - first_time) / (last_time - first_time);
50+
X = 1.0 * svg_page_width * (time - first_time) / (last_time - first_time);
5051
return X;
5152
}
5253

53-
void open_svg(const char *filename, int cpus, int rows)
54+
void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
5455
{
56+
int new_width;
5557

5658
svgfile = fopen(filename, "w");
5759
if (!svgfile) {
5860
fprintf(stderr, "Cannot open %s for output\n", filename);
5961
return;
6062
}
63+
first_time = start;
64+
first_time = first_time / 100000000 * 100000000;
65+
last_time = end;
66+
67+
/*
68+
* if the recording is short, we default to a width of 1000, but
69+
* for longer recordings we want at least 200 units of width per second
70+
*/
71+
new_width = (last_time - first_time) / 5000000;
72+
73+
if (new_width > svg_page_width)
74+
svg_page_width = new_width;
75+
6176
total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT;
6277
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);
78+
fprintf(svgfile, "<svg width=\"%i\" height=\"%llu\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height);
6479

6580
fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
6681

@@ -404,15 +419,10 @@ void svg_legenda(void)
404419
svg_legenda_box(800, "Blocked on IO", "blocked");
405420
}
406421

407-
void svg_time_grid(u64 start, u64 end)
422+
void svg_time_grid(void)
408423
{
409424
u64 i;
410425

411-
first_time = start;
412-
last_time = end;
413-
414-
first_time = first_time / 100000000 * 100000000;
415-
416426
if (!svgfile)
417427
return;
418428

tools/perf/util/svghelper.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "types.h"
55

6-
extern void open_svg(const char *filename, int cpus, int rows);
6+
extern void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
77
extern void svg_box(int Yslot, u64 start, u64 end, const char *type);
88
extern void svg_sample(int Yslot, int cpu, u64 start, u64 end);
99
extern void svg_waiting(int Yslot, u64 start, u64 end);
@@ -15,12 +15,14 @@ extern void svg_cstate(int cpu, u64 start, u64 end, int type);
1515
extern void svg_pstate(int cpu, u64 start, u64 end, u64 freq);
1616

1717

18-
extern void svg_time_grid(u64 start, u64 end);
18+
extern void svg_time_grid(void);
1919
extern void svg_legenda(void);
2020
extern void svg_wakeline(u64 start, int row1, int row2);
2121
extern void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2);
2222
extern void svg_interrupt(u64 start, int row);
2323
extern void svg_text(int Yslot, u64 start, const char *text);
2424
extern void svg_close(void);
2525

26+
extern int svg_page_width;
27+
2628
#endif

0 commit comments

Comments
 (0)