blob: 8b79d3ad124629e44184b8d20474592f9346a44b [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
288void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name)
289{
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 Fomichevcbb2e812013-11-01 20:25:49 +0400297 fprintf(svgfile, "<title>%s %s</title>\n", name, time_to_string(end - start));
Arjan van de Ven611a5462009-09-20 18:14:38 +0200298 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
299 time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type);
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200300 width = time2pixels(end)-time2pixels(start);
301 if (width > 6)
302 width = 6;
303
Arjan van de Ven611a5462009-09-20 18:14:38 +0200304 width = round_text_size(width);
305
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200306 if (width > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200307 fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n",
308 width, name);
309
310 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200311}
312
313void svg_cstate(int cpu, u64 start, u64 end, int type)
314{
315 double width;
316 char style[128];
317
318 if (!svgfile)
319 return;
320
321
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400322 fprintf(svgfile, "<g>\n");
323
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200324 if (type > 6)
325 type = 6;
326 sprintf(style, "c%i", type);
327
328 fprintf(svgfile, "<rect class=\"%s\" x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\"/>\n",
329 style,
330 time2pixels(start), time2pixels(end)-time2pixels(start),
331 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
332
Arjan van de Ven611a5462009-09-20 18:14:38 +0200333 width = (time2pixels(end)-time2pixels(start))/2.0;
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200334 if (width > 6)
335 width = 6;
336
Arjan van de Ven611a5462009-09-20 18:14:38 +0200337 width = round_text_size(width);
338
Arjan van de Ven964a0b32009-09-19 13:35:07 +0200339 if (width > MIN_TEXT_SIZE)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200340 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n",
341 time2pixels(start), cpu2y(cpu)+width, width, type);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400342
343 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200344}
345
346static char *HzToHuman(unsigned long hz)
347{
348 static char buffer[1024];
349 unsigned long long Hz;
350
351 memset(buffer, 0, 1024);
352
353 Hz = hz;
354
355 /* default: just put the Number in */
356 sprintf(buffer, "%9lli", Hz);
357
358 if (Hz > 1000)
359 sprintf(buffer, " %6lli Mhz", (Hz+500)/1000);
360
361 if (Hz > 1500000)
362 sprintf(buffer, " %6.2f Ghz", (Hz+5000.0)/1000000);
363
364 if (Hz == turbo_frequency)
365 sprintf(buffer, "Turbo");
366
367 return buffer;
368}
369
370void svg_pstate(int cpu, u64 start, u64 end, u64 freq)
371{
372 double height = 0;
373
374 if (!svgfile)
375 return;
376
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400377 fprintf(svgfile, "<g>\n");
378
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200379 if (max_freq)
380 height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT);
381 height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height;
382 fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n",
383 time2pixels(start), time2pixels(end), height, height);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200384 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 +0200385 time2pixels(start), height+0.9, HzToHuman(freq));
386
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400387 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200388}
389
390
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400391void 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 +0200392{
393 double height;
394
395 if (!svgfile)
396 return;
397
398
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400399 fprintf(svgfile, "<g>\n");
400
401 fprintf(svgfile, "<title>%s wakes up %s</title>\n",
402 desc1 ? desc1 : "?",
403 desc2 ? desc2 : "?");
404
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400405 if (backtrace)
406 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
407
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200408 if (row1 < row2) {
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200409 if (row1) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200410 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",
411 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 +0200412 if (desc2)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200413 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 +0200414 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2);
415 }
416 if (row2) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200417 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",
418 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200419 if (desc1)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200420 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 +0200421 time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1);
422 }
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200423 } else {
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200424 if (row2) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200425 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",
426 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 +0200427 if (desc1)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200428 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 +0200429 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1);
430 }
431 if (row1) {
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200432 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",
433 time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT);
Arjan van de Ven4f1202c2009-09-20 18:13:28 +0200434 if (desc2)
Arjan van de Ven611a5462009-09-20 18:14:38 +0200435 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 +0200436 time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2);
437 }
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200438 }
439 height = row1 * SLOT_MULT;
440 if (row2 > row1)
441 height += SLOT_HEIGHT;
442 if (row1)
443 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
444 time2pixels(start), height);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400445
446 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200447}
448
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400449void svg_wakeline(u64 start, int row1, int row2, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200450{
451 double height;
452
453 if (!svgfile)
454 return;
455
456
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400457 fprintf(svgfile, "<g>\n");
458
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400459 if (backtrace)
460 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
461
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200462 if (row1 < row2)
463 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",
464 time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT);
465 else
466 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",
467 time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT);
468
469 height = row1 * SLOT_MULT;
470 if (row2 > row1)
471 height += SLOT_HEIGHT;
472 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n",
473 time2pixels(start), height);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400474
475 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200476}
477
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400478void svg_interrupt(u64 start, int row, const char *backtrace)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200479{
480 if (!svgfile)
481 return;
482
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400483 fprintf(svgfile, "<g>\n");
484
485 fprintf(svgfile, "<title>Wakeup from interrupt</title>\n");
486
Stanislav Fomichev6f8d67f2013-11-01 20:25:51 +0400487 if (backtrace)
488 fprintf(svgfile, "<desc>%s</desc>\n", backtrace);
489
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200490 fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n",
491 time2pixels(start), row * SLOT_MULT);
492 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 + SLOT_HEIGHT);
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400494
495 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200496}
497
498void svg_text(int Yslot, u64 start, const char *text)
499{
500 if (!svgfile)
501 return;
502
Arjan van de Ven611a5462009-09-20 18:14:38 +0200503 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200504 time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text);
505}
506
507static void svg_legenda_box(int X, const char *text, const char *style)
508{
509 double boxsize;
510 boxsize = SLOT_HEIGHT / 2;
511
512 fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n",
513 X, boxsize, boxsize, style);
Arjan van de Ven611a5462009-09-20 18:14:38 +0200514 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 +0200515 X + boxsize + 5, boxsize, 0.8 * boxsize, text);
516}
517
518void svg_legenda(void)
519{
520 if (!svgfile)
521 return;
522
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400523 fprintf(svgfile, "<g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200524 svg_legenda_box(0, "Running", "sample");
Thomas Renningere8530722011-02-27 22:36:45 +0100525 svg_legenda_box(100, "Idle","c1");
526 svg_legenda_box(200, "Deeper Idle", "c3");
527 svg_legenda_box(350, "Deepest Idle", "c6");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200528 svg_legenda_box(550, "Sleeping", "process2");
529 svg_legenda_box(650, "Waiting for cpu", "waiting");
530 svg_legenda_box(800, "Blocked on IO", "blocked");
Stanislav Fomichevcbb2e812013-11-01 20:25:49 +0400531 fprintf(svgfile, "</g>\n");
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200532}
533
Arjan van de Ven5094b652009-09-20 18:14:16 +0200534void svg_time_grid(void)
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200535{
536 u64 i;
537
Arjan van de Venf48d55c2009-09-12 12:52:11 +0200538 if (!svgfile)
539 return;
540
541 i = first_time;
542 while (i < last_time) {
543 int color = 220;
544 double thickness = 0.075;
545 if ((i % 100000000) == 0) {
546 thickness = 0.5;
547 color = 192;
548 }
549 if ((i % 1000000000) == 0) {
550 thickness = 2.0;
551 color = 128;
552 }
553
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200554 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 +0200555 time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness);
556
557 i += 10000000;
558 }
559}
560
561void svg_close(void)
562{
563 if (svgfile) {
564 fprintf(svgfile, "</svg>\n");
565 fclose(svgfile);
566 svgfile = NULL;
567 }
568}