Debian Codegraph @

helper/avg-crowd

raw
1 #! /usr/bin/perl
2 use warnings;
3 use strict;
4 use FindBin;
5 use lib $FindBin::RealBin;
6 use Def;
7 no integer;
8
9 # This helper script determines the average ram size from the package's
10 # point of view. It computes the crowding average. For example, in
11 #
12 # --------------
13 # 0001 RAM X (1)
14 # --------------
15 # pkg-x1
16 #
17 # --------------
18 # 0002 RAM Y (3)
19 # --------------
20 # pkg-y1
21 # pkg-y2
22 # pkg-y3
23 #
24 # --------------
25 # 0003 RAM Z (6)
26 # --------------
27 # pkg-z1
28 # pkg-z2
29 # pkg-z3
30 # pkg-z4
31 # pkg-z5
32 # pkg-z6
33 #
34 # --------------
35 # 0004 RAM Q (0)
36 # --------------
37 #
38 # the average ram size is
39 #
40 # ( 1*1 + 3*3 + 6*6 + 0*0 ) / ( 1 + 3 + 6 + 0 )
41 # = 46 / 10 = 4.60 packages.
42 #
43 # Notice that the average size is as seen from the package's not the
44 # ram's point of view. In particular, notice that the empty
45 # ram [0004 RAM Q] fails to reduce the average at all, because no
46 # package is there to see its emptiness. Empty rams do not influence
47 # this average, because they do not relieve package crowding. One can
48 # only reduce the crowding average by actually splitting the crowded
49 # rams up.
50 #
51 # This script counts actual listed packages. It ignores the number in
52 # parentheses at each title-line's end.
53 #
54 # usage: avg-crowd { debram.txt }
55 #
56 # If no debram.txt file is named, the script examines the main
57 # debram.txt file.
58 #
59 #
60
61 our $fmt_n_pkg = "%${Def::ndig_pkg_count}d";
62 our $fmt_n_ram = "%${Def::ndig_ram_count}d";
63 our $fmt_avg = "%6.2f";
64
65 # Count.
66 my @n;
67 open F, '<', $Def::debram_txt;
68 1 while <F> ne $Def::mark_main_body;
69 {
70 my $n;
71 my $intitle = 0;
72 while ( 1 ) {
73 local $_ = <F>;
74 if ( /^-----/ ) {
75 push @n, $n if !$intitle && defined($n);
76 $n = 0;
77 $intitle = !$intitle;
78 }
79 elsif ( $intitle ) {
80 last if $intitle && !( defined() && /^\d{$Def::ndig}/o )
81 }
82 else {
83 ++$n if /\S/;
84 }
85 }
86 }
87 close F;
88
89 # Calculate.
90 my $crowd = 0;
91 my $n_pkg = 0;
92 $crowd += $_*$_, $n_pkg += $_ for @n;
93 my $avg = $crowd / $n_pkg;
94
95 # Output.
96 printf "A total of $fmt_n_pkg packages "
97 . "spread over $fmt_n_ram branches.\n"
98 . "The average package crowd is $fmt_avg in number.\n",
99 $n_pkg, scalar(@n), $avg;
100