]> git.donarmstrong.com Git - wannabuild.git/blob - bin/wanna-build-statistics
initial import of /org/wanna-build
[wannabuild.git] / bin / wanna-build-statistics
1 #!/usr/bin/perl
2 #
3 # wanna-build-statistics: print statistics for wanna-build databases
4 # Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 # $Id: wanna-build-statistics 43 2005-06-01 09:28:43Z rmurray $
21 #
22 # $Log: wanna-build-statistics,v $
23 # Revision 1.4  2000/10/19 09:15:37  rnhodek
24 # percent: handle $total == 0 case.
25 #
26 # Revision 1.3  1999/01/13 09:57:17  rnhodek
27 # If wanna-build returns error status, also print last message from it.
28 #
29 # Revision 1.2  1998/12/16 10:51:34  rnhodek
30 # Print nothing at all if wanna-build says that the db doesn't exist.
31 # Remove debugging stuff.
32 #
33 # Revision 1.1  1998/12/16 10:29:09  rnhodek
34 # Initial writing.
35 #
36
37 use strict;
38 use vars qw($verbose $dist $database);
39
40 $verbose = 0;
41 $dist = "unstable";
42 $database = "build-db";
43
44 while( @ARGV && $ARGV[0] =~ /^-/ ) {
45         $_ = shift @ARGV;
46         if (/^-v$/ || /^--verbose$/) {
47                 $verbose++;
48         }
49         elsif (/^-d/ || /^--dist/) {
50                 if (/^-d(.)/ || /^--dist=(.)/) {
51                         $dist = $1.$';
52                 }
53                 elsif (!@ARGV) {
54                         die "$_ option missing argument\n";
55                 }
56                 else {
57                         $dist = shift @ARGV;
58                 }
59                 $dist = "stable"   if $dist eq "s";
60                 $dist = "testing"  if $dist eq "t";
61                 $dist = "unstable" if $dist eq "u";
62                 die "Bad distribution\n" if !isin($dist, qw(stable testing unstable stable-security testing-security));
63         }
64         elsif (/^--$/) {
65                 last;
66         }
67         elsif (/^--database=(.*)$/) {
68                 $database = $1;
69         }
70         else {
71                 die "Unknown option: $_\n";
72         }
73 }
74
75 my($lastmsg, %n_state, $total, %n_builder);
76 open( PIPE, "wanna-build --database=$database --dist=$dist --list=all 2>&1 |" )
77         or die "Cannot spawn wanna-build: $!\n";
78 while( <PIPE> ) {
79         if (/^Database for $dist doesn't exist$/) {
80                 exit 1;
81         }
82         elsif (/^Total (\d+) package\(s\) in state (\S+)\.$/) {
83                 $n_state{$2} = $1;
84         }
85         elsif (/^Total (\d+) package\(s\)$/) {
86                 $total = $1;
87         }
88         elsif (/^\S+: (\S+) by (\S+)/) {
89                 $n_builder{$1}->{$2}++;
90         }
91         $lastmsg = $_;
92 }
93 close( PIPE );
94 if ($?) {
95         print "$lastmsg";
96         die "Bad exit status $? from wanna-build\n";
97 }
98
99 print "Distribution $dist:\n";
100 print "--------------", "-" x length($dist), "\n";
101
102 my $total_width = 78;
103 my @state_list = qw(Installed Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait
104                                         Failed-Removed Dep-Wait-Removed
105                                         Not-For-Us);
106 my $statewidth = 0;
107 grep { $statewidth = length($_) if length($_) > $statewidth } @state_list;
108 my $startcol = $statewidth + 9;
109
110 my($state, $builder);
111 foreach $state (@state_list) {
112         printf "%-${statewidth}s: %5d", $state, $n_state{$state};
113         if (!keys %{$n_builder{$state}}) {
114                 print "\n";
115                 next;
116         }
117         my $sum = 0;
118         foreach $builder (keys %{$n_builder{$state}}) {
119                 $sum += $n_builder{$state}->{$builder};
120         }
121         $n_builder{$state}->{"unknown"} = $n_state{$state} - $sum;
122         print " (";
123         my $is_first = 1;
124         my $pos = $startcol;
125         foreach $builder (sort keys %{$n_builder{$state}}) {
126                 next if !$n_builder{$state}->{$builder};
127                 my $str = "$builder: $n_builder{$state}->{$builder}";
128                 $str = ", $str" if !$is_first;
129                 $is_first = 0;
130                 if ($pos + length($str) > $total_width) {
131                         print ",\n", " " x $startcol;
132                         $pos = $startcol;
133                         $str =~ s/^, //;
134                 }
135                 print $str;
136                 $pos += length($str);
137         }
138         print ")\n";
139 }
140 printf "%-${statewidth}s: %5d\n", "total", $total;
141 print "\n";
142
143 $total -= $n_state{"Not-For-Us"};
144 print percent(qw(Installed)), " up-to-date, ";
145 print percent(qw(Installed Uploaded)), " if also counting uploaded pkgs\n";
146 print percent(qw(Built Installed Uploaded)), " if also counting built pkgs\n";
147 print percent(qw(Needs-Build)), " uncompiled\n";
148 print percent(qw(Building)), " currently building (short-term delay)\n";
149 print percent(qw(Build-Attempted)), " currently failed building (short-term delay)\n";
150 print percent(qw(Failed Dep-Wait)), " failed or waiting (long-term delay)\n";
151
152 exit 0;
153
154 sub percent {
155         my $n = 0;
156         foreach (@_) {
157                 $n += $n_state{$_};
158         }
159
160         return sprintf "%6.2f%%", $n*100/$total if $total;
161         return sprintf "%6.2f%%", 0;
162 }
163
164 sub isin {
165         my $val = shift;
166         return grep( $_ eq $val, @_ );
167 }