1e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng/* 2e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * svghelper.c - helper functions for outputting svg 3e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * 4e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * (C) Copyright 2009 Intel Corporation 5e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * 6e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * Authors: 7e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * Arjan van de Ven <arjan@linux.intel.com> 8e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * 9e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * This program is free software; you can redistribute it and/or 10e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * modify it under the terms of the GNU General Public License 11e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * as published by the Free Software Foundation; version 2 12e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * of the License. 13e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng */ 14e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 15e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include <inttypes.h> 16e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include <stdio.h> 17e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include <stdlib.h> 18e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include <unistd.h> 19e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include <string.h> 20e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 21e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#include "svghelper.h" 22e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 23e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic u64 first_time, last_time; 24e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic u64 turbo_frequency, max_freq; 25e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 26e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 27e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#define SLOT_MULT 30.0 28e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#define SLOT_HEIGHT 25.0 29e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 30e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengint svg_page_width = 1000; 31e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 32e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng#define MIN_TEXT_SIZE 0.01 33e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 34e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic u64 total_height; 35e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic FILE *svgfile; 36e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 37e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic double cpu2slot(int cpu) 38e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 39e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return 2 * cpu + 1; 40e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 41e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 42e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic double cpu2y(int cpu) 43e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 44e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return cpu2slot(cpu) * SLOT_MULT; 45e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 46e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 47e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic double time2pixels(u64 __time) 48e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 49e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double X; 50e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 51e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time); 52e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return X; 53e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 54e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 55e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng/* 56e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * Round text sizes so that the svg viewer only needs a discrete 57e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * number of renderings of the font 58e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng */ 59e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic double round_text_size(double size) 60e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 61e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng int loop = 100; 62e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double target = 10.0; 63e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 64e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (size >= 10.0) 65e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return size; 66e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng while (loop--) { 67e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (size >= target) 68e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return target; 69e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng target = target / 2.0; 70e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 71e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return size; 72e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 73e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 74e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid open_svg(const char *filename, int cpus, int rows, u64 start, u64 end) 75e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 76e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng int new_width; 77e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 78e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svgfile = fopen(filename, "w"); 79e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) { 80e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(stderr, "Cannot open %s for output\n", filename); 81e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 82e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 83e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng first_time = start; 84e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng first_time = first_time / 100000000 * 100000000; 85e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng last_time = end; 86e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 87e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng /* 88e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * if the recording is short, we default to a width of 1000, but 89e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng * for longer recordings we want at least 200 units of width per second 90e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng */ 91e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng new_width = (last_time - first_time) / 5000000; 92e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 93e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (new_width > svg_page_width) 94e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_page_width = new_width; 95e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 96e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng total_height = (1 + rows + cpu2slot(cpus)) * SLOT_MULT; 97e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<?xml version=\"1.0\" standalone=\"no\"?> \n"); 98e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<svg width=\"%i\" height=\"%" PRIu64 "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n", svg_page_width, total_height); 99e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 100e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<defs>\n <style type=\"text/css\">\n <![CDATA[\n"); 101e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 102e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect { stroke-width: 1; }\n"); 103e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); 104e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.process2 { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 105e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 106e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 107e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 108e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 109e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.cpu { fill:rgb(192,192,192); fill-opacity:0.2; stroke-width:0.5; stroke:rgb(128,128,128); } \n"); 110e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.pstate { fill:rgb(128,128,128); fill-opacity:0.8; stroke-width:0; } \n"); 111e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c1 { fill:rgb(255,214,214); fill-opacity:0.5; stroke-width:0; } \n"); 112e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c2 { fill:rgb(255,172,172); fill-opacity:0.5; stroke-width:0; } \n"); 113e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c3 { fill:rgb(255,130,130); fill-opacity:0.5; stroke-width:0; } \n"); 114e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c4 { fill:rgb(255, 88, 88); fill-opacity:0.5; stroke-width:0; } \n"); 115e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c5 { fill:rgb(255, 44, 44); fill-opacity:0.5; stroke-width:0; } \n"); 116e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " rect.c6 { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; } \n"); 117e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " line.pstate { stroke:rgb(255,255, 0); stroke-opacity:0.8; stroke-width:2; } \n"); 118e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 119e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, " ]]>\n </style>\n</defs>\n"); 120e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 121e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 122e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_box(int Yslot, u64 start, u64 end, const char *type) 123e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 124e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 125e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 126e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 127e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n", 128e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT, type); 129e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 130e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 131e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_sample(int Yslot, int cpu, u64 start, u64 end) 132e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 133e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double text_size; 134e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 135e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 136e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 137e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n", 138e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT); 139e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 140e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text_size = (time2pixels(end)-time2pixels(start)); 141e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (cpu > 9) 142e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text_size = text_size/2; 143e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (text_size > 1.25) 144e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text_size = 1.25; 145e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text_size = round_text_size(text_size); 146e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 147e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (text_size > MIN_TEXT_SIZE) 148e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text x=\"%1.8f\" y=\"%1.8f\" font-size=\"%1.8fpt\">%i</text>\n", 149e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), Yslot * SLOT_MULT + SLOT_HEIGHT - 1, text_size, cpu + 1); 150e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 151e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 152e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 153e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic char *time_to_string(u64 duration) 154e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 155e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng static char text[80]; 156e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 157e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text[0] = 0; 158e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 159e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (duration < 1000) /* less than 1 usec */ 160e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return text; 161e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 162e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (duration < 1000 * 1000) { /* less than 1 msec */ 163e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(text, "%4.1f us", duration / 1000.0); 164e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return text; 165e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 166e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(text, "%4.1f ms", duration / 1000.0 / 1000); 167e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 168e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return text; 169e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 170e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 171e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_waiting(int Yslot, u64 start, u64 end) 172e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 173e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng char *text; 174e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng const char *style; 175e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double font_size; 176e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 177e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 178e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 179e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 180e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng style = "waiting"; 181e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 182e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (end-start > 10 * 1000000) /* 10 msec */ 183e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng style = "WAITING"; 184e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 185e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng text = time_to_string(end-start); 186e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 187e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng font_size = 1.0 * (time2pixels(end)-time2pixels(start)); 188e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 189e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (font_size > 3) 190e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng font_size = 3; 191e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 192e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng font_size = round_text_size(font_size); 193e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 194e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), Yslot * SLOT_MULT); 195e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", 196e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(end)-time2pixels(start), SLOT_HEIGHT, style); 197e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (font_size > MIN_TEXT_SIZE) 198e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%1.8fpt\"> %s</text>\n", 199e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng font_size, text); 200e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "</g>\n"); 201e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 202e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 203e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic char *cpu_model(void) 204e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 205e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng static char cpu_m[255]; 206e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng char buf[256]; 207e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng FILE *file; 208e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 209e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng cpu_m[0] = 0; 210e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng /* CPU type */ 211e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng file = fopen("/proc/cpuinfo", "r"); 212e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (file) { 213e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng while (fgets(buf, 255, file)) { 214e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (strstr(buf, "model name")) { 215e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng strncpy(cpu_m, &buf[13], 255); 216e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng break; 217e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 218e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 219e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fclose(file); 220e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 221e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 222e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng /* CPU type */ 223e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng file = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies", "r"); 224e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (file) { 225e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng while (fgets(buf, 255, file)) { 226e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng unsigned int freq; 227e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng freq = strtoull(buf, NULL, 10); 228e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (freq > max_freq) 229e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng max_freq = freq; 230e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 231e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fclose(file); 232e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 233e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return cpu_m; 234e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 235e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 236e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq) 237e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 238e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng char cpu_string[80]; 239e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 240e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 241e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 242e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng max_freq = __max_freq; 243e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng turbo_frequency = __turbo_freq; 244e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 245e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n", 246e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(first_time), 247e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(last_time)-time2pixels(first_time), 248e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); 249e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 250e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(cpu_string, "CPU %i", (int)cpu+1); 251e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", 252e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); 253e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 254e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n", 255e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model()); 256e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 257e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 258e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_process(int cpu, u64 start, u64 end, const char *type, const char *name) 259e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 260e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double width; 261e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 262e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 263e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 264e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 265e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 266e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); 267e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", 268e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type); 269e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = time2pixels(end)-time2pixels(start); 270e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (width > 6) 271e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = 6; 272e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 273e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = round_text_size(width); 274e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 275e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (width > MIN_TEXT_SIZE) 276e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text transform=\"rotate(90)\" font-size=\"%3.8fpt\">%s</text>\n", 277e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width, name); 278e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 279e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "</g>\n"); 280e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 281e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 282e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_cstate(int cpu, u64 start, u64 end, int type) 283e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 284e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double width; 285e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng char style[128]; 286e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 287e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 288e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 289e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 290e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 291e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (type > 6) 292e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng type = 6; 293e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(style, "c%i", type); 294e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 295e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect class=\"%s\" x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\"/>\n", 296e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng style, 297e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), time2pixels(end)-time2pixels(start), 298e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); 299e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 300e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = (time2pixels(end)-time2pixels(start))/2.0; 301e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (width > 6) 302e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = 6; 303e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 304e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng width = round_text_size(width); 305e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 306e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (width > MIN_TEXT_SIZE) 307e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"%3.8fpt\">C%i</text>\n", 308e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), cpu2y(cpu)+width, width, type); 309e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 310e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 311e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic char *HzToHuman(unsigned long hz) 312e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 313e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng static char buffer[1024]; 314e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng unsigned long long Hz; 315e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 316e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng memset(buffer, 0, 1024); 317e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 318e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng Hz = hz; 319e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 320e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng /* default: just put the Number in */ 321e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(buffer, "%9lli", Hz); 322e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 323e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (Hz > 1000) 324e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(buffer, " %6lli Mhz", (Hz+500)/1000); 325e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 326e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (Hz > 1500000) 327e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(buffer, " %6.2f Ghz", (Hz+5000.0)/1000000); 328e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 329e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (Hz == turbo_frequency) 330e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng sprintf(buffer, "Turbo"); 331e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 332e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return buffer; 333e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 334e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 335e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_pstate(int cpu, u64 start, u64 end, u64 freq) 336e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 337e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double height = 0; 338e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 339e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 340e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 341e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 342e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (max_freq) 343e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height = freq * 1.0 / max_freq * (SLOT_HEIGHT + SLOT_MULT); 344e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height = 1 + cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - height; 345e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<line x1=\"%4.8f\" x2=\"%4.8f\" y1=\"%4.1f\" y2=\"%4.1f\" class=\"pstate\"/>\n", 346e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), time2pixels(end), height, height); 347e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\" font-size=\"0.25pt\">%s</text>\n", 348e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), height+0.9, HzToHuman(freq)); 349e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 350e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 351e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 352e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 353e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc2) 354e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 355e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double height; 356e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 357e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 358e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 359e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 360e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 361e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row1 < row2) { 362e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row1) { 363e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 364e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); 365e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (desc2) 366e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", 367e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT + SLOT_HEIGHT/48, desc2); 368e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 369e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row2) { 370e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 371e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row2 * SLOT_MULT); 372e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (desc1) 373e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s ></text></g>\n", 374e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row2 * SLOT_MULT - SLOT_MULT/32, desc1); 375e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 376e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } else { 377e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row2) { 378e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 379e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/32); 380e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (desc1) 381e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", 382e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT + SLOT_MULT/48, desc1); 383e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 384e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row1) { 385e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 386e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row1 * SLOT_MULT - SLOT_MULT/32, time2pixels(start), row1 * SLOT_MULT); 387e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (desc2) 388e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\"><text transform=\"rotate(90)\" font-size=\"0.02pt\">%s <</text></g>\n", 389e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row1 * SLOT_MULT - SLOT_HEIGHT/32, desc2); 390e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 391e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 392e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height = row1 * SLOT_MULT; 393e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row2 > row1) 394e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height += SLOT_HEIGHT; 395e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row1) 396e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", 397e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), height); 398e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 399e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 400e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_wakeline(u64 start, int row1, int row2) 401e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 402e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double height; 403e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 404e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 405e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 406e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 407e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 408e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row1 < row2) 409e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 410e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row1 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row2 * SLOT_MULT); 411e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng else 412e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 413e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row2 * SLOT_MULT + SLOT_HEIGHT, time2pixels(start), row1 * SLOT_MULT); 414e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 415e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height = row1 * SLOT_MULT; 416e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (row2 > row1) 417e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng height += SLOT_HEIGHT; 418e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(32,255,32)\"/>\n", 419e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), height); 420e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 421e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 422e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_interrupt(u64 start, int row) 423e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 424e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 425e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 426e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 427e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", 428e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row * SLOT_MULT); 429e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<circle cx=\"%4.8f\" cy=\"%4.2f\" r = \"0.01\" style=\"fill:rgb(255,128,128)\"/>\n", 430e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), row * SLOT_MULT + SLOT_HEIGHT); 431e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 432e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 433e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_text(int Yslot, u64 start, const char *text) 434e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 435e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 436e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 437e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 438e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", 439e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(start), Yslot * SLOT_MULT+SLOT_HEIGHT/2, text); 440e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 441e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 442e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengstatic void svg_legenda_box(int X, const char *text, const char *style) 443e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 444e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double boxsize; 445e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng boxsize = SLOT_HEIGHT / 2; 446e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 447e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<rect x=\"%i\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", 448e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng X, boxsize, boxsize, style); 449e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "<text transform=\"translate(%4.8f, %4.8f)\" font-size=\"%4.8fpt\">%s</text>\n", 450e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng X + boxsize + 5, boxsize, 0.8 * boxsize, text); 451e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 452e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 453e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_legenda(void) 454e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 455e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 456e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 457e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 458e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(0, "Running", "sample"); 459e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(100, "Idle","c1"); 460e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(200, "Deeper Idle", "c3"); 461e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(350, "Deepest Idle", "c6"); 462e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(550, "Sleeping", "process2"); 463e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(650, "Waiting for cpu", "waiting"); 464e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svg_legenda_box(800, "Blocked on IO", "blocked"); 465e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 466e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 467e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_time_grid(void) 468e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 469e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng u64 i; 470e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 471e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (!svgfile) 472e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng return; 473e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 474e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng i = first_time; 475e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng while (i < last_time) { 476e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng int color = 220; 477e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng double thickness = 0.075; 478e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if ((i % 100000000) == 0) { 479e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng thickness = 0.5; 480e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng color = 192; 481e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 482e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if ((i % 1000000000) == 0) { 483e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng thickness = 2.0; 484e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng color = 128; 485e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 486e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 487e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 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", 488e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng time2pixels(i), SLOT_MULT/2, time2pixels(i), total_height, color, color, color, thickness); 489e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 490e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng i += 10000000; 491e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 492e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 493e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng 494e6817ec1d8ab31fc7b01906e305f848542df6413Ben Chengvoid svg_close(void) 495e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng{ 496e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng if (svgfile) { 497e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fprintf(svgfile, "</svg>\n"); 498e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng fclose(svgfile); 499e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng svgfile = NULL; 500e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng } 501e6817ec1d8ab31fc7b01906e305f848542df6413Ben Cheng} 502