svghelper.c (de996228dedc74d9e72b749bbc8225f5e2bf19d8) svghelper.c (c507999790438cde78b5618fa64daefd697035af)
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
15#include <inttypes.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <unistd.h>
19#include <string.h>
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
15#include <inttypes.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <unistd.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
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
29

--- 4 unchanged lines hidden (view full) ---

34static u64 total_height;
35static FILE *svgfile;
36
37static double cpu2slot(int cpu)
38{
39 return 2 * cpu + 1;
40}
41
25
26static u64 first_time, last_time;
27static u64 turbo_frequency, max_freq;
28
29
30#define SLOT_MULT 30.0
31#define SLOT_HEIGHT 25.0
32

--- 4 unchanged lines hidden (view full) ---

37static u64 total_height;
38static FILE *svgfile;
39
40static double cpu2slot(int cpu)
41{
42 return 2 * cpu + 1;
43}
44
45static int *topology_map;
46
42static double cpu2y(int cpu)
43{
47static double cpu2y(int cpu)
48{
44 return cpu2slot(cpu) * SLOT_MULT;
49 if (topology_map)
50 return cpu2slot(topology_map[cpu]) * SLOT_MULT;
51 else
52 return cpu2slot(cpu) * SLOT_MULT;
45}
46
47static double time2pixels(u64 __time)
48{
49 double X;
50
51 X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time);
52 return X;

--- 217 unchanged lines hidden (view full) ---

270
271 fprintf(svgfile, "<g>\n");
272
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
53}
54
55static double time2pixels(u64 __time)
56{
57 double X;
58
59 X = 1.0 * svg_page_width * (__time - first_time) / (last_time - first_time);
60 return X;

--- 217 unchanged lines hidden (view full) ---

278
279 fprintf(svgfile, "<g>\n");
280
281 fprintf(svgfile, "<rect x=\"%4.8f\" width=\"%4.8f\" y=\"%4.1f\" height=\"%4.1f\" class=\"cpu\"/>\n",
282 time2pixels(first_time),
283 time2pixels(last_time)-time2pixels(first_time),
284 cpu2y(cpu), SLOT_MULT+SLOT_HEIGHT);
285
278 sprintf(cpu_string, "CPU %i", (int)cpu+1);
286 sprintf(cpu_string, "CPU %i", (int)cpu);
279 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
280 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
281
282 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n",
283 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model());
284
285 fprintf(svgfile, "</g>\n");
286}

--- 276 unchanged lines hidden (view full) ---

563void svg_close(void)
564{
565 if (svgfile) {
566 fprintf(svgfile, "</svg>\n");
567 fclose(svgfile);
568 svgfile = NULL;
569 }
570}
287 fprintf(svgfile, "<text x=\"%4.8f\" y=\"%4.8f\">%s</text>\n",
288 10+time2pixels(first_time), cpu2y(cpu) + SLOT_HEIGHT/2, cpu_string);
289
290 fprintf(svgfile, "<text transform=\"translate(%4.8f,%4.8f)\" font-size=\"1.25pt\">%s</text>\n",
291 10+time2pixels(first_time), cpu2y(cpu) + SLOT_MULT + SLOT_HEIGHT - 4, cpu_model());
292
293 fprintf(svgfile, "</g>\n");
294}

--- 276 unchanged lines hidden (view full) ---

571void svg_close(void)
572{
573 if (svgfile) {
574 fprintf(svgfile, "</svg>\n");
575 fclose(svgfile);
576 svgfile = NULL;
577 }
578}
579
580#define cpumask_bits(maskp) ((maskp)->bits)
581typedef struct { DECLARE_BITMAP(bits, MAX_NR_CPUS); } cpumask_t;
582
583struct topology {
584 cpumask_t *sib_core;
585 int sib_core_nr;
586 cpumask_t *sib_thr;
587 int sib_thr_nr;
588};
589
590static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos)
591{
592 int i;
593 int thr;
594
595 for (i = 0; i < t->sib_thr_nr; i++) {
596 if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
597 continue;
598
599 for_each_set_bit(thr,
600 cpumask_bits(&t->sib_thr[i]),
601 MAX_NR_CPUS)
602 if (map[thr] == -1)
603 map[thr] = (*pos)++;
604 }
605}
606
607static void scan_core_topology(int *map, struct topology *t)
608{
609 int pos = 0;
610 int i;
611 int cpu;
612
613 for (i = 0; i < t->sib_core_nr; i++)
614 for_each_set_bit(cpu,
615 cpumask_bits(&t->sib_core[i]),
616 MAX_NR_CPUS)
617 scan_thread_topology(map, t, cpu, &pos);
618}
619
620static int str_to_bitmap(char *s, cpumask_t *b)
621{
622 int i;
623 int ret = 0;
624 struct cpu_map *m;
625 int c;
626
627 m = cpu_map__new(s);
628 if (!m)
629 return -1;
630
631 for (i = 0; i < m->nr; i++) {
632 c = m->map[i];
633 if (c >= MAX_NR_CPUS) {
634 ret = -1;
635 break;
636 }
637
638 set_bit(c, cpumask_bits(b));
639 }
640
641 cpu_map__delete(m);
642
643 return ret;
644}
645
646int svg_build_topology_map(char *sib_core, int sib_core_nr,
647 char *sib_thr, int sib_thr_nr)
648{
649 int i;
650 struct topology t;
651
652 t.sib_core_nr = sib_core_nr;
653 t.sib_thr_nr = sib_thr_nr;
654 t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
655 t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
656
657 if (!t.sib_core || !t.sib_thr) {
658 fprintf(stderr, "topology: no memory\n");
659 goto exit;
660 }
661
662 for (i = 0; i < sib_core_nr; i++) {
663 if (str_to_bitmap(sib_core, &t.sib_core[i])) {
664 fprintf(stderr, "topology: can't parse siblings map\n");
665 goto exit;
666 }
667
668 sib_core += strlen(sib_core) + 1;
669 }
670
671 for (i = 0; i < sib_thr_nr; i++) {
672 if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
673 fprintf(stderr, "topology: can't parse siblings map\n");
674 goto exit;
675 }
676
677 sib_thr += strlen(sib_thr) + 1;
678 }
679
680 topology_map = malloc(sizeof(int) * MAX_NR_CPUS);
681 if (!topology_map) {
682 fprintf(stderr, "topology: no memory\n");
683 goto exit;
684 }
685
686 for (i = 0; i < MAX_NR_CPUS; i++)
687 topology_map[i] = -1;
688
689 scan_core_topology(topology_map, &t);
690
691 return 0;
692
693exit:
694 free(t.sib_core);
695 free(t.sib_thr);
696
697 return -1;
698}