Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 1 | /* |
| 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 Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 15 | #include <inttypes.h> |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <unistd.h> |
| 19 | #include <string.h> |
| 20 | |
| 21 | #include "svghelper.h" |
| 22 | |
| 23 | static u64 first_time, last_time; |
| 24 | static u64 turbo_frequency, max_freq; |
| 25 | |
| 26 | |
| 27 | #define SLOT_MULT 30.0 |
| 28 | #define SLOT_HEIGHT 25.0 |
Arjan van de Ven | 5094b65 | 2009-09-20 18:14:16 +0200 | [diff] [blame] | 29 | |
| 30 | int svg_page_width = 1000; |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 31 | |
Arjan van de Ven | 39a90a8 | 2009-09-24 15:40:13 +0200 | [diff] [blame] | 32 | #define MIN_TEXT_SIZE 0.01 |
Arjan van de Ven | 964a0b3 | 2009-09-19 13:35:07 +0200 | [diff] [blame] | 33 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 34 | static u64 total_height; |
| 35 | static FILE *svgfile; |
| 36 | |
| 37 | static double cpu2slot(int cpu) |
| 38 | { |
| 39 | return 2 * cpu + 1; |
| 40 | } |
| 41 | |
| 42 | static double cpu2y(int cpu) |
| 43 | { |
| 44 | return cpu2slot(cpu) * SLOT_MULT; |
| 45 | } |
| 46 | |
Thomas Renninger | 00e99a4 | 2011-01-21 15:30:09 +0100 | [diff] [blame] | 47 | static double time2pixels(u64 __time) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 48 | { |
| 49 | double X; |
| 50 | |
Thomas Renninger | 00e99a4 | 2011-01-21 15:30:09 +0100 | [diff] [blame] | 51 | X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 52 | return X; |
| 53 | } |
| 54 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 55 | /* |
| 56 | * Round text sizes so that the svg viewer only needs a discrete |
| 57 | * number of renderings of the font |
| 58 | */ |
| 59 | static 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 Ven | 5094b65 | 2009-09-20 18:14:16 +0200 | [diff] [blame] | 74 | void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 75 | { |
Arjan van de Ven | 5094b65 | 2009-09-20 18:14:16 +0200 | [diff] [blame] | 76 | int new_width; |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 77 | |
| 78 | svgfile = fopen(filename, "w"); |
| 79 | if (!svgfile) { |
| 80 | fprintf(stderr, "Cannot open %s for output\n", filename); |
| 81 | return; |
| 82 | } |
Arjan van de Ven | 5094b65 | 2009-09-20 18:14:16 +0200 | [diff] [blame] | 83 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 96 | total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; |
| 97 | fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 98 | fprintf(svgfile, "<!DOCTYPE svg SYSTEM \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"); |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 99 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 100 | |
| 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 Ven | 2e600d0 | 2009-10-20 06:47:31 +0900 | [diff] [blame] | 108 | 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 Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 109 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 110 | 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 | |
| 123 | void 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 132 | static char *time_to_string(u64 duration); |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 133 | void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 134 | { |
| 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 Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 141 | if (backtrace) |
| 142 | fprintf(svgfile, "<desc>Blocked on:\n%s</desc>\n", backtrace); |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 143 | svg_box(Yslot, start, end, "blocked"); |
| 144 | fprintf(svgfile, "</g>\n"); |
| 145 | } |
| 146 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 147 | void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 148 | { |
| 149 | double text_size; |
| 150 | if (!svgfile) |
| 151 | return; |
| 152 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 153 | fprintf(svgfile, "<g>\n"); |
| 154 | |
| 155 | fprintf(svgfile, "<title>#%d running %s</title>\n", |
| 156 | cpu, time_to_string(end - start)); |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 157 | if (backtrace) |
| 158 | fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace); |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 159 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 161 | |
| 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 167 | text_size = round_text_size(text_size); |
| 168 | |
Arjan van de Ven | 964a0b3 | 2009-09-19 13:35:07 +0200 | [diff] [blame] | 169 | if (text_size > MIN_TEXT_SIZE) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 170 | fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 171 | time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); |
| 172 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 173 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 176 | static 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 Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 194 | void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 195 | { |
| 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 210 | font_size = 1.0 * (time2pixels(end)-time2pixels(start)); |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 211 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 212 | if (font_size > 3) |
| 213 | font_size = 3; |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 214 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 215 | font_size = round_text_size(font_size); |
Arjan van de Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 216 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 217 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT); |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 218 | fprintf(svgfile, "<title>#%d waiting %s</title>\n", cpu, time_to_string(end - start)); |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 219 | if (backtrace) |
| 220 | fprintf(svgfile, "<desc>Waiting on:\n%s</desc>\n", backtrace); |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 221 | 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 Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 223 | if (font_size > MIN_TEXT_SIZE) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 224 | 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 Ven | a92fe7b | 2009-09-20 18:13:53 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 229 | static 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 Ven | 39a90a8 | 2009-09-24 15:40:13 +0200 | [diff] [blame] | 247 | |
| 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 259 | return cpu_m; |
| 260 | } |
| 261 | |
| 262 | void 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 271 | fprintf(svgfile, "<g>\n"); |
| 272 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 273 | 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 279 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 280 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); |
| 281 | |
Arjan van de Ven | 964a0b3 | 2009-09-19 13:35:07 +0200 | [diff] [blame] | 282 | fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 283 | 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 284 | |
| 285 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Stanislav Fomichev | de99622 | 2013-12-02 18:37:34 +0400 | [diff] [blame^] | 288 | void svg_process(int cpu, u64 start, u64 end, int pid, const char *type, const char *name, const char *backtrace) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 289 | { |
| 290 | double width; |
| 291 | |
| 292 | if (!svgfile) |
| 293 | return; |
| 294 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 295 | |
| 296 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); |
Stanislav Fomichev | de99622 | 2013-12-02 18:37:34 +0400 | [diff] [blame^] | 297 | fprintf(svgfile, "<title>%d %s running %s</title>\n", pid, name, time_to_string(end - start)); |
Stanislav Fomichev | 8b6dcca | 2013-12-02 18:37:33 +0400 | [diff] [blame] | 298 | if (backtrace) |
| 299 | fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace); |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 300 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 302 | width = time2pixels(end)-time2pixels(start); |
| 303 | if (width > 6) |
| 304 | width = 6; |
| 305 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 306 | width = round_text_size(width); |
| 307 | |
Arjan van de Ven | 964a0b3 | 2009-09-19 13:35:07 +0200 | [diff] [blame] | 308 | if (width > MIN_TEXT_SIZE) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 309 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 324 | fprintf(svgfile, "<g>\n"); |
| 325 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 326 | 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 335 | width = (time2pixels(end)-time2pixels(start))/2.0; |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 336 | if (width > 6) |
| 337 | width = 6; |
| 338 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 339 | width = round_text_size(width); |
| 340 | |
Arjan van de Ven | 964a0b3 | 2009-09-19 13:35:07 +0200 | [diff] [blame] | 341 | if (width > MIN_TEXT_SIZE) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 342 | 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 344 | |
| 345 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 346 | } |
| 347 | |
| 348 | static 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 | |
| 372 | void svg_pstate(int cpu, u64 start, u64 end, u64 freq) |
| 373 | { |
| 374 | double height = 0; |
| 375 | |
| 376 | if (!svgfile) |
| 377 | return; |
| 378 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 379 | fprintf(svgfile, "<g>\n"); |
| 380 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 381 | 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 386 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 387 | time2pixels(start), height+0.9, HzToHuman(freq)); |
| 388 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 389 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 393 | void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2, const char *backtrace) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 394 | { |
| 395 | double height; |
| 396 | |
| 397 | if (!svgfile) |
| 398 | return; |
| 399 | |
| 400 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 401 | fprintf(svgfile, "<g>\n"); |
| 402 | |
| 403 | fprintf(svgfile, "<title>%s wakes up %s</title>\n", |
| 404 | desc1 ? desc1 : "?", |
| 405 | desc2 ? desc2 : "?"); |
| 406 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 407 | if (backtrace) |
| 408 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); |
| 409 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 410 | if (row1 < row2) { |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 411 | if (row1) { |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 412 | 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 Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 414 | if (desc2) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 415 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 416 | time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2); |
| 417 | } |
| 418 | if (row2) { |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 419 | 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 Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 421 | if (desc1) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 422 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 423 | time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1); |
| 424 | } |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 425 | } else { |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 426 | if (row2) { |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 427 | 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 Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 429 | if (desc1) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 430 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 431 | time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1); |
| 432 | } |
| 433 | if (row1) { |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 434 | 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 Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 436 | if (desc2) |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 437 | fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", |
Arjan van de Ven | 4f1202c | 2009-09-20 18:13:28 +0200 | [diff] [blame] | 438 | time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2); |
| 439 | } |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 440 | } |
| 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 447 | |
| 448 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 449 | } |
| 450 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 451 | void svg_wakeline(u64 start, int row1, int row2, const char *backtrace) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 452 | { |
| 453 | double height; |
| 454 | |
| 455 | if (!svgfile) |
| 456 | return; |
| 457 | |
| 458 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 459 | fprintf(svgfile, "<g>\n"); |
| 460 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 461 | if (backtrace) |
| 462 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); |
| 463 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 464 | 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 476 | |
| 477 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 480 | void svg_interrupt(u64 start, int row, const char *backtrace) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 481 | { |
| 482 | if (!svgfile) |
| 483 | return; |
| 484 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 485 | fprintf(svgfile, "<g>\n"); |
| 486 | |
| 487 | fprintf(svgfile, "<title>Wakeup from interrupt</title>\n"); |
| 488 | |
Stanislav Fomichev | 6f8d67f | 2013-11-01 20:25:51 +0400 | [diff] [blame] | 489 | if (backtrace) |
| 490 | fprintf(svgfile, "<desc>%s</desc>\n", backtrace); |
| 491 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 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); |
| 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 496 | |
| 497 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | void svg_text(int Yslot, u64 start, const char *text) |
| 501 | { |
| 502 | if (!svgfile) |
| 503 | return; |
| 504 | |
Arjan van de Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 505 | fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 506 | time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text); |
| 507 | } |
| 508 | |
| 509 | static 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 Ven | 611a546 | 2009-09-20 18:14:38 +0200 | [diff] [blame] | 516 | fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.8fpt\">%s</text>\n", |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 517 | X + boxsize + 5, boxsize, 0.8 * boxsize, text); |
| 518 | } |
| 519 | |
| 520 | void svg_legenda(void) |
| 521 | { |
| 522 | if (!svgfile) |
| 523 | return; |
| 524 | |
Stanislav Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 525 | fprintf(svgfile, "<g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 526 | svg_legenda_box(0, "Running", "sample"); |
Thomas Renninger | e853072 | 2011-02-27 22:36:45 +0100 | [diff] [blame] | 527 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 530 | 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 Fomichev | cbb2e81 | 2013-11-01 20:25:49 +0400 | [diff] [blame] | 533 | fprintf(svgfile, "</g>\n"); |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 534 | } |
| 535 | |
Arjan van de Ven | 5094b65 | 2009-09-20 18:14:16 +0200 | [diff] [blame] | 536 | void svg_time_grid(void) |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 537 | { |
| 538 | u64 i; |
| 539 | |
Arjan van de Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 540 | 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 Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 556 | 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 Ven | f48d55c | 2009-09-12 12:52:11 +0200 | [diff] [blame] | 557 | time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness); |
| 558 | |
| 559 | i += 10000000; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | void svg_close(void) |
| 564 | { |
| 565 | if (svgfile) { |
| 566 | fprintf(svgfile, "</svg>\n"); |
| 567 | fclose(svgfile); |
| 568 | svgfile = NULL; |
| 569 | } |
| 570 | } |