]> git.donarmstrong.com Git - wannabuild.git/blob - bin/wanna-build-statistics
Auto-committed schema changes.
[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 = "sid";
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         }
60         elsif (/^--$/) {
61                 last;
62         }
63         elsif (/^--database=(.*)$/) {
64                 $database = $1;
65         }
66         else {
67                 die "Unknown option: $_\n";
68         }
69 }
70
71 my($lastmsg, %n_state, $total, %n_builder);
72 open( my $pipe, '-|', "wanna-build --database=$database --dist=$dist --list=all 2>&1" )
73         or die "Cannot spawn wanna-build: $!\n";
74 while( <$pipe> ) {
75         if (/^Database for $dist doesn't exist$/) {
76                 exit 1;
77         }
78         elsif (/^Total (\d+) package\(s\) in state (\S+)\.$/) {
79                 $n_state{$2} = $1;
80         }
81         elsif (/^Total (\d+) package\(s\)$/) {
82                 $total = $1;
83         }
84         elsif (/^\S+: (\S+) by (\S+)/) {
85                 $n_builder{$1}->{$2}++;
86         }
87         $lastmsg = $_;
88 }
89 close( $pipe );
90 if ($?) {
91         print "$lastmsg";
92         die "Bad exit status $? from wanna-build\n";
93 }
94
95 print "Distribution $dist:\n";
96 print "--------------", "-" x length($dist), "\n";
97
98 my $total_width = 78;
99 my @state_list = qw(Installed Needs-Build Building Built Build-Attempted Uploaded Failed Dep-Wait
100                                         Failed-Removed Dep-Wait-Removed BD-Uninstallable
101                                         Not-For-Us);
102 my $statewidth = 0;
103 grep { $statewidth = length($_) if length($_) > $statewidth } @state_list;
104 my $startcol = $statewidth + 9;
105
106 my($state, $builder);
107 foreach $state (@state_list) {
108         printf "%-${statewidth}s: %5d", $state, $n_state{$state};
109         if (!keys %{$n_builder{$state}}) {
110                 print "\n";
111                 next;
112         }
113         my $sum = 0;
114         foreach $builder (keys %{$n_builder{$state}}) {
115                 $sum += $n_builder{$state}->{$builder};
116         }
117         $n_builder{$state}->{"unknown"} = $n_state{$state} - $sum;
118         print " (";
119         my $is_first = 1;
120         my $pos = $startcol;
121         foreach $builder (sort keys %{$n_builder{$state}}) {
122                 next if !$n_builder{$state}->{$builder};
123                 my $str = "$builder: $n_builder{$state}->{$builder}";
124                 $str = ", $str" if !$is_first;
125                 $is_first = 0;
126                 if ($pos + length($str) > $total_width) {
127                         print ",\n", " " x $startcol;
128                         $pos = $startcol;
129                         $str =~ s/^, //;
130                 }
131                 print $str;
132                 $pos += length($str);
133         }
134         print ")\n";
135 }
136 printf "%-${statewidth}s: %5d\n", "total", $total;
137 print "\n";
138
139 $total -= $n_state{"Not-For-Us"};
140 print percent(qw(Installed)), " up-to-date, ";
141 print percent(qw(Installed Uploaded)), " if also counting uploaded pkgs\n";
142 print percent(qw(Built Installed Uploaded)), " if also counting built pkgs\n";
143 print percent(qw(Needs-Build)), " uncompiled\n";
144 print percent(qw(Building)), " currently building (short-term delay)\n";
145 print percent(qw(Build-Attempted)), " currently failed building (short-term delay)\n";
146 print percent(qw(Failed BD-Uninstallable Dep-Wait)), " failed or waiting (long-term delay)\n";
147
148 exit 0;
149
150 sub percent {
151         my $n = 0;
152         foreach (@_) {
153                 $n += $n_state{$_};
154         }
155
156         return sprintf "%6.2f%%", $n*100/$total if $total;
157         return sprintf "%6.2f%%", 0;
158 }
159
160 sub isin {
161         my $val = shift;
162         return grep( $_ eq $val, @_ );
163 }