aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/svghelper.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/svghelper.c')
-rw-r--r--tools/perf/util/svghelper.c159
1 files changed, 153 insertions, 6 deletions
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 8b79d3ad1246..56a84f2cc46d 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -17,8 +17,11 @@
17#include <stdlib.h> 17#include <stdlib.h>
18#include <unistd.h> 18#include <unistd.h>
19#include <string.h> 19#include <string.h>
20#include <linux/bitops.h>
20 21
22#include "perf.h"
21#include "svghelper.h" 23#include "svghelper.h"
24#include "cpumap.h"
22 25
23static u64 first_time, last_time; 26static u64 first_time, last_time;
24static u64 turbo_frequency, max_freq; 27static u64 turbo_frequency, max_freq;
@@ -28,6 +31,8 @@ static u64 turbo_frequency, max_freq;
28#define SLOT_HEIGHT 25.0 31#define SLOT_HEIGHT 25.0
29 32
30int svg_page_width = 1000; 33int svg_page_width = 1000;
34u64 svg_highlight;
35const char *svg_highlight_name;
31 36
32#define MIN_TEXT_SIZE 0.01 37#define MIN_TEXT_SIZE 0.01
33 38
@@ -39,9 +44,14 @@ static double cpu2slot(int cpu)
39 return 2 * cpu + 1; 44 return 2 * cpu + 1;
40} 45}
41 46
47static int *topology_map;
48
42static double cpu2y(int cpu) 49static double cpu2y(int cpu)
43{ 50{
44 return cpu2slot(cpu) * SLOT_MULT; 51 if (topology_map)
52 return cpu2slot(topology_map[cpu]) * SLOT_MULT;
53 else
54 return cpu2slot(cpu) * SLOT_MULT;
45} 55}
46 56
47static double time2pixels(u64 __time) 57static double time2pixels(u64 __time)
@@ -104,6 +114,7 @@ void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end)
104 fprintf(svgfile, " rect.process { fill:rgb(180,180,180); fill-opacity:0.9; stroke-width:1; stroke:rgb( 0, 0, 0); } \n"); 114 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"); 115 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"); 116 fprintf(svgfile, " rect.sample { fill:rgb( 0, 0,255); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
117 fprintf(svgfile, " rect.sample_hi{ fill:rgb(255,128, 0); 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"); 118 fprintf(svgfile, " rect.blocked { fill:rgb(255, 0, 0); fill-opacity:0.5; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
108 fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 119 fprintf(svgfile, " rect.waiting { fill:rgb(224,214, 0); fill-opacity:0.8; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
109 fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n"); 120 fprintf(svgfile, " rect.WAITING { fill:rgb(255,214, 48); fill-opacity:0.6; stroke-width:0; stroke:rgb( 0, 0, 0); } \n");
@@ -147,17 +158,24 @@ void svg_blocked(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)
147void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace) 158void svg_running(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)
148{ 159{
149 double text_size; 160 double text_size;
161 const char *type;
162
150 if (!svgfile) 163 if (!svgfile)
151 return; 164 return;
152 165
166 if (svg_highlight && end - start > svg_highlight)
167 type = "sample_hi";
168 else
169 type = "sample";
153 fprintf(svgfile, "<g>\n"); 170 fprintf(svgfile, "<g>\n");
154 171
155 fprintf(svgfile, "<title>#%d running %s</title>\n", 172 fprintf(svgfile, "<title>#%d running %s</title>\n",
156 cpu, time_to_string(end - start)); 173 cpu, time_to_string(end - start));
157 if (backtrace) 174 if (backtrace)
158 fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace); 175 fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace);
159 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"sample\"/>\n", 176 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"%s\"/>\n",
160 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT); 177 time2pixels(start), time2pixels(end)-time2pixels(start), Yslot * SLOT_MULT, SLOT_HEIGHT,
178 type);
161 179
162 text_size = (time2pixels(end)-time2pixels(start)); 180 text_size = (time2pixels(end)-time2pixels(start));
163 if (cpu > 9) 181 if (cpu > 9)
@@ -275,7 +293,7 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
275 time2pixels(last_time)-time2pixels(first_time), 293 time2pixels(last_time)-time2pixels(first_time),
276 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT); 294 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
277 295
278 sprintf(cpu_string, "CPU %i", (int)cpu+1); 296 sprintf(cpu_string, "CPU %i", (int)cpu);
279 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n", 297 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
280 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string); 298 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
281 299
@@ -285,16 +303,25 @@ void svg_cpu_box(int cpu, u64 __max_freq, u64 __turbo_freq)
285 fprintf(svgfile, "</g>\n"); 303 fprintf(svgfile, "</g>\n");
286} 304}
287 305
288void svg_process(int cpu, u64 start, u64 end, const char *type, const char *name) 306void svg_process(int cpu, u64 start, u64 end, int pid, const char *name, const char *backtrace)
289{ 307{
290 double width; 308 double width;
309 const char *type;
291 310
292 if (!svgfile) 311 if (!svgfile)
293 return; 312 return;
294 313
314 if (svg_highlight && end - start >= svg_highlight)
315 type = "sample_hi";
316 else if (svg_highlight_name && strstr(name, svg_highlight_name))
317 type = "sample_hi";
318 else
319 type = "sample";
295 320
296 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu)); 321 fprintf(svgfile, "<g transform=\"translate(%4.8f,%4.8f)\">\n", time2pixels(start), cpu2y(cpu));
297 fprintf(svgfile, "<title>%s %s</title>\n", name, time_to_string(end - start)); 322 fprintf(svgfile, "<title>%d %s running %s</title>\n", pid, name, time_to_string(end - start));
323 if (backtrace)
324 fprintf(svgfile, "<desc>Switched because:\n%s</desc>\n", backtrace);
298 fprintf(svgfile, "<rect x=\"0\" width=\"%4.8f\" y=\"0\" height=\"%4.1f\" class=\"%s\"/>\n", 325 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); 326 time2pixels(end)-time2pixels(start), SLOT_MULT+SLOT_HEIGHT, type);
300 width = time2pixels(end)-time2pixels(start); 327 width = time2pixels(end)-time2pixels(start);
@@ -566,3 +593,123 @@ void svg_close(void)
566 svgfile = NULL; 593 svgfile = NULL;
567 } 594 }
568} 595}
596
597#define cpumask_bits(maskp) ((maskp)->bits)
598typedef struct { DECLARE_BITMAP(bits, MAX_NR_CPUS); } cpumask_t;
599
600struct topology {
601 cpumask_t *sib_core;
602 int sib_core_nr;
603 cpumask_t *sib_thr;
604 int sib_thr_nr;
605};
606
607static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos)
608{
609 int i;
610 int thr;
611
612 for (i = 0; i < t->sib_thr_nr; i++) {
613 if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
614 continue;
615
616 for_each_set_bit(thr,
617 cpumask_bits(&t->sib_thr[i]),
618 MAX_NR_CPUS)
619 if (map[thr] == -1)
620 map[thr] = (*pos)++;
621 }
622}
623
624static void scan_core_topology(int *map, struct topology *t)
625{
626 int pos = 0;
627 int i;
628 int cpu;
629
630 for (i = 0; i < t->sib_core_nr; i++)
631 for_each_set_bit(cpu,
632 cpumask_bits(&t->sib_core[i]),
633 MAX_NR_CPUS)
634 scan_thread_topology(map, t, cpu, &pos);
635}
636
637static int str_to_bitmap(char *s, cpumask_t *b)
638{
639 int i;
640 int ret = 0;
641 struct cpu_map *m;
642 int c;
643
644 m = cpu_map__new(s);
645 if (!m)
646 return -1;
647
648 for (i = 0; i < m->nr; i++) {
649 c = m->map[i];
650 if (c >= MAX_NR_CPUS) {
651 ret = -1;
652 break;
653 }
654
655 set_bit(c, cpumask_bits(b));
656 }
657
658 cpu_map__delete(m);
659
660 return ret;
661}
662
663int svg_build_topology_map(char *sib_core, int sib_core_nr,
664 char *sib_thr, int sib_thr_nr)
665{
666 int i;
667 struct topology t;
668
669 t.sib_core_nr = sib_core_nr;
670 t.sib_thr_nr = sib_thr_nr;
671 t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
672 t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
673
674 if (!t.sib_core || !t.sib_thr) {
675 fprintf(stderr, "topology: no memory\n");
676 goto exit;
677 }
678
679 for (i = 0; i < sib_core_nr; i++) {
680 if (str_to_bitmap(sib_core, &t.sib_core[i])) {
681 fprintf(stderr, "topology: can't parse siblings map\n");
682 goto exit;
683 }
684
685 sib_core += strlen(sib_core) + 1;
686 }
687
688 for (i = 0; i < sib_thr_nr; i++) {
689 if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
690 fprintf(stderr, "topology: can't parse siblings map\n");
691 goto exit;
692 }
693
694 sib_thr += strlen(sib_thr) + 1;
695 }
696
697 topology_map = malloc(sizeof(int) * MAX_NR_CPUS);
698 if (!topology_map) {
699 fprintf(stderr, "topology: no memory\n");
700 goto exit;
701 }
702
703 for (i = 0; i < MAX_NR_CPUS; i++)
704 topology_map[i] = -1;
705
706 scan_core_topology(topology_map, &t);
707
708 return 0;
709
710exit:
711 free(t.sib_core);
712 free(t.sib_thr);
713
714 return -1;
715}