Port it to use the new Linux perf_event API rather than the old perfmon patch.
[beedb.git] / perf / graph.pl
blobdb5078bb863ca1f44ace86e3eee3d1a3c3481cb9
1 #! /usr/bin/perl
3 use strict;
4 use warnings;
6 use POSIX();
7 use GD::Graph::bars;
8 use GD::Graph::hbars;
9 use DBI;
14 # Find a good max value that is a nice round number and not too far
15 # from given max data value.
16 sub calc_good_max {
17 my ($value)= @_;
18 $value= -$value if $value < 0;
19 $value= 1 if $value == 0;
20 my $base= 10**POSIX::floor(log($value)/log(10));
21 for (1, 2.5, 5, 10)
23 my $candidate= $_*$base;
24 return $candidate if $candidate >= $value;
26 # Shouldn't really be possible to get here...
27 return $value;
31 my ($host, $user, $pass)= @ARGV;
33 my $dbh= DBI->connect("dbi:mysql:database=beedb;host=$host", $user, $pass,
34 { RaiseError => 1, PrintError => 0 });
36 my $sql= <<SQL;
37 SELECT instance_idx, counter_idx, variant, iterations, workunits, counter_name, counter_value
38 FROM perf_test_run
39 INNER JOIN perf_counts ON (perf_test_run.id = perf_counts.test_run_id)
40 WHERE perf_test_run.suite_run_id = 17
41 AND test_major = 'bitcopy'
42 AND test_minor = 'bitcopy'
43 AND param1 = 'bits=17'
44 AND param2 = 'offs s=17 d=42'
45 ORDER BY counter_name, instance_idx, counter_idx, variant
46 SQL
47 my $sth= $dbh->prepare($sql);
48 $sth->execute();
49 my $data= [];
50 my $idx_x;
51 my $idx_y= 0;
52 my ($last_instance, $last_counter);
53 my $variant_names= [];
54 my $max_y= undef;
55 my ($instance_idx, $counter_idx, $variant, $iterations, $workunits, $counter_name, $counter_value);
57 while (my $r= $sth->fetchrow_arrayref())
59 ($instance_idx, $counter_idx, $variant, $iterations, $workunits, $counter_name, $counter_value)= @$r;
60 if ($instance_idx == 0 && $counter_idx == 0)
62 push @$variant_names, $variant;
65 if ((!defined($last_instance) || $last_instance != $instance_idx) ||
66 (!defined($last_counter) || $last_counter != $counter_idx))
68 if (!defined($last_instance))
70 $idx_y= 0;
72 else
74 $idx_y++;
76 $idx_x= 1;
79 $iterations= 1 unless $iterations;
80 $workunits= 1 unless $workunits;
81 my $value= $counter_value / $iterations / $workunits;
82 $max_y= $value unless defined($max_y) && $max_y >= $value;
83 $data->[$idx_x][$idx_y]= $value;
84 $data->[0][$idx_y]= $counter_name if $idx_x == 1;
85 $last_instance= $instance_idx;
86 $last_counter= $counter_idx;
87 $idx_x++;
90 use Data::Dumper;
91 # print Dumper($data);
92 # print Dumper($variant_names);
94 my $graph= GD::Graph::hbars->new(1400, 800);
95 $graph->set( x_label => "Counter name",
96 y_label => "Counts per iteration(I) per workunit(U)",
97 title => "bitcopy/bitcopy [bits=17; offs s=17 d=42] I=$iterations U=$workunits",
98 y_max_value => calc_good_max($max_y),
99 bargroup_spacing => 4,
101 $graph->set_legend(@$variant_names);
102 $graph->plot($data);
104 binmode STDOUT;
105 my $ext= $graph->export_format();
106 print $graph->gd->$ext();