Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / mini / viewstat.pl
1 #!/usr/bin/perl
2
3 use GD::Graph::bars;
4 use GD::Graph::bars3d;
5 use Getopt::Std;
6
7 $Usage = "usage: $0 [-e] [-o file] statfile";
8
9 # -e       generate a 3D graph
10 # -o file  write the graph to file, instead of starting the viewer
11
12 getopts('eo:', \%Opts)
13     or die "$Usage";
14 die "$Usage\n"
15     unless (@ARGV == 1);
16
17 $statfile = shift;
18
19 sub save_chart
20 {
21         my $chart = shift or die "Need a chart!";
22         my $name = shift or die "Need a name!";
23         local(*OUT);
24
25         open(OUT, ">$name") or 
26                 die "Cannot open $name.$ext for write: $!";
27         binmode OUT;
28         print OUT $chart->gd->png();
29         close OUT;
30 }
31
32
33 print STDERR "Processing file $statfile\n";
34
35 if ($Opts{'e'}) {
36     $graph = new GD::Graph::bars3d(800, 600);
37 } else {
38     $graph = new GD::Graph::bars(800, 600);
39 }
40 $graph->set( 
41              y_label         => 'Time',
42              y_long_ticks      => 1,
43
44              x_long_ticks      => 1,
45
46              y_tick_number   => 8,
47
48              x_labels_vertical   => 1,
49              bar_spacing         => 5,
50              
51              show_values         => 1,
52              values_vertical     => 1,
53                      
54              l_margin            => 10,
55              b_margin            => 10,
56              r_margin            => 10,
57              t_margin            => 10,
58
59              shadow_depth => 1,
60
61              transparent     => 0,
62 );
63
64 if ($Opts{'e'}) {
65     $graph->set (overwrite => 1);
66     $graph->set (show_values => 0);
67 }
68
69 require $statfile;
70
71 if ($stattitle ne "") {
72     $graph->set (title=> $stattitle);
73 }
74
75 $outfile = $Opts{'o'};
76
77 if ($outfile eq "") {
78     $tmp = $outfile = "/tmp/viewstat" . $$ . ".png";
79 }
80
81 $graph->plot(\@data);
82 save_chart($graph, $outfile);
83
84 if ($tmp) {
85     `eog $outfile`;
86     `rm $tmp`;
87 }