blob: 927851d05d03aff9f80ca096291cb8955c0a7cb5 [file] [log] [blame]
Arjan van de Venf48d55c2009-09-12 12:52:11 +02001/*
2 * svghelper.c - helper functions for outputting svg
3 *
4 * (C) Copyright 2009 Intel Corporation
5 *
6 * Authors:
7 * Arjan van de Ven <arjan@linux.intel.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; version 2
12 * of the License.
13 */
14
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -020015#include <inttypes.h>
Arjan van de Venf48d55c2009-09-12 12:52:11 +020016#include <stdio.h>
17#include <stdlib.h>
18#include <unistd.h>
19#include <string.h>
20
21#include "svghelper.h"
22
23static u64 first_time, last_time;
24static u64 turbo_frequency, max_freq;
25
26
27#define SLOT_MULT 30.0
28#define SLOT_HEIGHT 25.0
Arjan van de Ven5094b652009-09-20 18:14:16 +020029
30int svg_page_width = 1000;
Arjan van de Venf48d55c2009-09-12 12:52:11 +020031
Arjan van de Ven39a90a82009-09-24 15:40:13 +020032#define MIN_TEXT_SIZE 0.01
Arjan van de Ven964a0b32009-09-19 13:35:07 +020033
Arjan van de Venf48d55c2009-09-12 12:52:11 +020034static u64 total_height;
35static FILE *svgfile;
36
37static double cpu2slot(int cpu)
38{
39 return 2 * cpu + 1;
40}
41
42static double cpu2y(int cpu)
43{
44 return cpu2slot(cpu) * SLOT_MULT;
45}
46
Thomas Renninger00e99a42011-01-21 15:30:09 +010047static double time2pixels(u64 __time)
Arjan van de Venf48d55c2009-09-12 12:52:11 +020048{
49 double X;
50
Thomas Renninger00e99a42011-01-21 15:30:09 +010051 X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time);
Arjan van de Venf48d55c2009-09-12 12:52:11 +020052 return X;
53}
54
Arjan van de Ven611a5462009-09-20 18:14:38 +020055/*
56 * Round text sizes so that the svg viewer only needs a discrete
57 * number of renderings of the font
58 */
59static double round_text_size(double size)
60{
61 int loop = 100;
62 double target = 10.0;
63
64 if (size >= 10.0)
65 return size;
66 while (loop--) {
67 if (size >= target)
68 return target;
69 target = target / 2.0;
70 }
71 return size;
72}
73
Arjan van de Ven5094b652009-09-20 18:14:16 +020074void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
Arjan van de Venf48d55c2009-09-12 12:52:11 +020075{
Arjan van de Ven5094b652009-09-20 18:14:16 +020076 int new_width;
Arjan van de Venf48d55c2009-09-12 12:52:11 +020077
78 svgfile = fopen(filename, "w");
79 if (!svgfile) {
80 fprintf(stderr, "Cannot open %s for output\n", filename);
81 return;
82 }
Arjan van de Ven5094b652009-09-20 18:14:16 +020083 first_time = start;
84 first_time = first_time / 100000000 * 100000000;
85 last_time = end;
86
87 /*
88 * if the recording is short, we default to a width of 1000, but
89 * for longer recordings we want at least 200 units of width per second
90 */
91 new_width = (last_time - first_time) / 5000000;
92
93 if (new_width > svg_page_width)
94 svg_page_width = new_width;
95
Arjan van de Venf48d55c2009-09-12 12:52:11 +020096 total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT;
97 fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n");
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +040098 fprintf(svgfile, "<!DOCTYPE svg SYSTEM \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -020099 fprintf(svgfile, "<svg width=\"%i\" height=\"%" PRIu64 "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height);
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200100
101 fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n");
102
103 fprintf(svgfile, " rect { stroke-width: 1; }\n");
104 fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n");
105 fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
106 fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
107 fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
Arjan van de Ven2e600d02009-10-20 06:47:31 +0900108 fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200109 fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200110 fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n");
111 fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n");
112 fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n");
113 fprintf(svgfile, " rect.c2 { fill:rgb(255,172,172); fill-opacity:0.5; stroke-width:0; } \n");
114 fprintf(svgfile, " rect.c3 { fill:rgb(255,130,130); fill-opacity:0.5; stroke-width:0; } \n");
115 fprintf(svgfile, " rect.c4 { fill:rgb(255, 88, 88); fill-opacity:0.5; stroke-width:0; } \n");
116 fprintf(svgfile, " rect.c5 { fill:rgb(255, 44, 44); fill-opacity:0.5; stroke-width:0; } \n");
117 fprintf(svgfile, " rect.c6 { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; } \n");
118 fprintf(svgfile, " line.pstate { stroke:rgb(255,255, 0); stroke-opacity:0.8; stroke-width:2; } \n");
119
120 fprintf(svgfile, " ]]>\n </style>\n</defs>\n");
121}
122
123void svg_box(int Yslot, u64 start, u64 end, const char *type)
124{
125 if (!svgfile)
126 return;
127
128 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n",
129 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type);
130}
131
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400132static char *time_to_string(u64 duration);
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400133void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400134{
135 if (!svgfile)
136 return;
137
138 fprintf(svgfile, "<g>\n");
139 fprintf(svgfile, "<title>#%d blocked %s</title>\n", cpu,
140 time_to_string(end - start));
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400141 if (backtrace)
142 fprintf(svgfile, "<desc>Blocked on:\n%s</desc>\n", backtrace);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400143 svg_box(Yslot, start, end, "blocked");
144 fprintf(svgfile, "</g>\n");
145}
146
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400147void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200148{
149 double text_size;
150 if (!svgfile)
151 return;
152
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400153 fprintf(svgfile, "<g>\n");
154
155 fprintf(svgfile, "<title>#%d running %s</title>\n",
156 cpu, time_to_string(end - start));
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400157 if (backtrace)
158 fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace);
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200159 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n",
160 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT);
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200161
162 text_size = (time2pixels(end)-time2pixels(start));
163 if (cpu > 9)
164 text_size = text_size/2;
165 if (text_size > 1.25)
166 text_size = 1.25;
Arjan van de Ven611a5462009-09-20 18:14:38 +0200167 text_size = round_text_size(text_size);
168
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200169 if (text_size > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200170 fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200171 time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1);
172
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400173 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200174}
175
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200176static char *time_to_string(u64 duration)
177{
178 static char text[80];
179
180 text[0] = 0;
181
182 if (duration < 1000) /* less than 1 usec */
183 return text;
184
185 if (duration < 1000 * 1000) { /* less than 1 msec */
186 sprintf(text, "%4.1f us", duration / 1000.0);
187 return text;
188 }
189 sprintf(text, "%4.1f ms", duration / 1000.0 / 1000);
190
191 return text;
192}
193
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400194void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200195{
196 char *text;
197 const char *style;
198 double font_size;
199
200 if (!svgfile)
201 return;
202
203 style = "waiting";
204
205 if (end-start > 10 * 1000000) /* 10 msec */
206 style = "WAITING";
207
208 text = time_to_string(end-start);
209
Arjan van de Ven611a5462009-09-20 18:14:38 +0200210 font_size = 1.0 * (time2pixels(end)-time2pixels(start));
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200211
Arjan van de Ven611a5462009-09-20 18:14:38 +0200212 if (font_size > 3)
213 font_size = 3;
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200214
Arjan van de Ven611a5462009-09-20 18:14:38 +0200215 font_size = round_text_size(font_size);
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200216
Arjan van de Ven611a5462009-09-20 18:14:38 +0200217 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400218 fprintf(svgfile, "<title>#%d waiting %s</title>\n", cpu, time_to_string(end - start));
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400219 if (backtrace)
220 fprintf(svgfile, "<desc>Waiting on:\n%s</desc>\n", backtrace);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200221 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
222 time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style);
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200223 if (font_size > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200224 fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%1.8fpt\"> %s</text>\n",
225 font_size, text);
226 fprintf(svgfile, "</g>\n");
Arjan van de Vena92fe7b2009-09-20 18:13:53 +0200227}
228
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200229static char *cpu_model(void)
230{
231 static char cpu_m[255];
232 char buf[256];
233 FILE *file;
234
235 cpu_m[0] = 0;
236 /* CPU type */
237 file = fopen("/proc/cpuinfo", "r");
238 if (file) {
239 while (fgets(buf, 255, file)) {
240 if (strstr(buf, "model name")) {
241 strncpy(cpu_m, &buf[13], 255);
242 break;
243 }
244 }
245 fclose(file);
246 }
Arjan van de Ven39a90a82009-09-24 15:40:13 +0200247
248 /* CPU type */
249 file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r");
250 if (file) {
251 while (fgets(buf, 255, file)) {
252 unsigned int freq;
253 freq = strtoull(buf, NULL, 10);
254 if (freq > max_freq)
255 max_freq = freq;
256 }
257 fclose(file);
258 }
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200259 return cpu_m;
260}
261
262void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
263{
264 char cpu_string[80];
265 if (!svgfile)
266 return;
267
268 max_freq = __max_freq;
269 turbo_frequency = __turbo_freq;
270
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400271 fprintf(svgfile, "<g>\n");
272
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200273 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n",
274 time2pixels(first_time),
275 time2pixels(last_time)-time2pixels(first_time),
276 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
277
278 sprintf(cpu_string, "CPU %i", (int)cpu+1);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200279 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200280 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
281
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200282 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200283 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model());
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400284
285 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200286}
287
Stanislav Fomichevde996222013-12-02 18:37:34 +0400288void svg_process(int cpu, u64 start, u64 end, int pid, const char *type, const char *name, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200289{
290 double width;
291
292 if (!svgfile)
293 return;
294
Arjan van de Ven611a5462009-09-20 18:14:38 +0200295
296 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu));
Stanislav Fomichevde996222013-12-02 18:37:34 +0400297 fprintf(svgfile, "<title>%d %s running %s</title>\n", pid, name, time_to_string(end - start));
Stanislav Fomichev8b6dcca2013-12-02 18:37:33 +0400298 if (backtrace)
299 fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200300 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
301 time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type);
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200302 width = time2pixels(end)-time2pixels(start);
303 if (width > 6)
304 width = 6;
305
Arjan van de Ven611a5462009-09-20 18:14:38 +0200306 width = round_text_size(width);
307
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200308 if (width > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200309 fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n",
310 width, name);
311
312 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200313}
314
315void svg_cstate(int cpu, u64 start, u64 end, int type)
316{
317 double width;
318 char style[128];
319
320 if (!svgfile)
321 return;
322
323
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400324 fprintf(svgfile, "<g>\n");
325
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200326 if (type > 6)
327 type = 6;
328 sprintf(style, "c%i", type);
329
330 fprintf(svgfile, "<rect class=\"%s\" x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\"/>\n",
331 style,
332 time2pixels(start), time2pixels(end)-time2pixels(start),
333 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
334
Arjan van de Ven611a5462009-09-20 18:14:38 +0200335 width = (time2pixels(end)-time2pixels(start))/2.0;
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200336 if (width > 6)
337 width = 6;
338
Arjan van de Ven611a5462009-09-20 18:14:38 +0200339 width = round_text_size(width);
340
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200341 if (width > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200342 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n",
343 time2pixels(start), cpu2y(cpu)+width, width, type);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400344
345 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200346}
347
348static char *HzToHuman(unsigned long hz)
349{
350 static char buffer[1024];
351 unsigned long long Hz;
352
353 memset(buffer, 0, 1024);
354
355 Hz = hz;
356
357 /* default: just put the Number in */
358 sprintf(buffer, "%9lli", Hz);
359
360 if (Hz > 1000)
361 sprintf(buffer, " %6lli Mhz", (Hz+500)/1000);
362
363 if (Hz > 1500000)
364 sprintf(buffer, " %6.2f Ghz", (Hz+5000.0)/1000000);
365
366 if (Hz == turbo_frequency)
367 sprintf(buffer, "Turbo");
368
369 return buffer;
370}
371
372void svg_pstate(int cpu, u64 start, u64 end, u64 freq)
373{
374 double height = 0;
375
376 if (!svgfile)
377 return;
378
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400379 fprintf(svgfile, "<g>\n");
380
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200381 if (max_freq)
382 height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT);
383 height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height;
384 fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n",
385 time2pixels(start), time2pixels(end), height, height);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200386 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200387 time2pixels(start), height+0.9, HzToHuman(freq));
388
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400389 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200390}
391
392
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400393void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200394{
395 double height;
396
397 if (!svgfile)
398 return;
399
400
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400401 fprintf(svgfile, "<g>\n");
402
403 fprintf(svgfile, "<title>%s wakes up %s</title>\n",
404 desc1 ? desc1 : "?",
405 desc2 ? desc2 : "?");
406
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400407 if (backtrace)
408 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
409
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200410 if (row1 < row2) {
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200411 if (row1) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200412 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",
413 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200414 if (desc2)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200415 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200416 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2);
417 }
418 if (row2) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200419 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",
420 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200421 if (desc1)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200422 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &gt;</text></g>\n",
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200423 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1);
424 }
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200425 } else {
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200426 if (row2) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200427 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",
428 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200429 if (desc1)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200430 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200431 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1);
432 }
433 if (row1) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200434 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",
435 time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200436 if (desc2)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200437 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s &lt;</text></g>\n",
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200438 time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2);
439 }
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200440 }
441 height = row1 * SLOT_MULT;
442 if (row2 > row1)
443 height += SLOT_HEIGHT;
444 if (row1)
445 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
446 time2pixels(start), height);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400447
448 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200449}
450
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400451void svg_wakeline(u64 start, int row1, int row2, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200452{
453 double height;
454
455 if (!svgfile)
456 return;
457
458
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400459 fprintf(svgfile, "<g>\n");
460
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400461 if (backtrace)
462 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
463
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200464 if (row1 < row2)
465 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",
466 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT);
467 else
468 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",
469 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT);
470
471 height = row1 * SLOT_MULT;
472 if (row2 > row1)
473 height += SLOT_HEIGHT;
474 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
475 time2pixels(start), height);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400476
477 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200478}
479
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400480void svg_interrupt(u64 start, int row, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200481{
482 if (!svgfile)
483 return;
484
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400485 fprintf(svgfile, "<g>\n");
486
487 fprintf(svgfile, "<title>Wakeup from interrupt</title>\n");
488
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400489 if (backtrace)
490 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
491
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200492 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n",
493 time2pixels(start), row * SLOT_MULT);
494 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n",
495 time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400496
497 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200498}
499
500void svg_text(int Yslot, u64 start, const char *text)
501{
502 if (!svgfile)
503 return;
504
Arjan van de Ven611a5462009-09-20 18:14:38 +0200505 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200506 time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text);
507}
508
509static void svg_legenda_box(int X, const char *text, const char *style)
510{
511 double boxsize;
512 boxsize = SLOT_HEIGHT / 2;
513
514 fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
515 X, boxsize, boxsize, style);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200516 fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.8fpt\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200517 X + boxsize + 5, boxsize, 0.8 * boxsize, text);
518}
519
520void svg_legenda(void)
521{
522 if (!svgfile)
523 return;
524
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400525 fprintf(svgfile, "<g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200526 svg_legenda_box(0, "Running", "sample");
Thomas Renningere8530722011-02-27 22:36:45 +0100527 svg_legenda_box(100, "Idle","c1");
528 svg_legenda_box(200, "Deeper Idle", "c3");
529 svg_legenda_box(350, "Deepest Idle", "c6");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200530 svg_legenda_box(550, "Sleeping", "process2");
531 svg_legenda_box(650, "Waiting for cpu", "waiting");
532 svg_legenda_box(800, "Blocked on IO", "blocked");
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400533 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200534}
535
Arjan van de Ven5094b652009-09-20 18:14:16 +0200536void svg_time_grid(void)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200537{
538 u64 i;
539
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200540 if (!svgfile)
541 return;
542
543 i = first_time;
544 while (i < last_time) {
545 int color = 220;
546 double thickness = 0.075;
547 if ((i % 100000000) == 0) {
548 thickness = 0.5;
549 color = 192;
550 }
551 if ((i % 1000000000) == 0) {
552 thickness = 2.0;
553 color = 128;
554 }
555
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200556 fprintf(svgfile, "<line x1=\"%4.8f\" y1=\"%4.2f\" x2=\"%4.8f\" y2=\"%" PRIu64 "\" style=\"stroke:rgb(%i,%i,%i);stroke-width:%1.3f\"/>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200557 time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness);
558
559 i += 10000000;
560 }
561}
562
563void svg_close(void)
564{
565 if (svgfile) {
566 fprintf(svgfile, "</svg>\n");
567 fclose(svgfile);
568 svgfile = NULL;
569 }
570}