Tomato 1.28
[tomato.git] / release / src / btools / sizehistory.pl
blobfe9e95259faee2ad9f1101cad2c9db1ff96820e0
1 #!/usr/bin/perl
3 # sizehistory
4 # Copyright (C) 2006 Jonathan Zarate
7 if (($#ARGV < 0) || ($#ARGV > 1)) {
8 print "Usage: sizehistory <filename> [datafile]\n";
9 exit 1;
12 $fname = $ARGV[0];
13 $dname = ($ARGV[1] || $fname) . ".size";
15 print "\nSize history for $fname\n\n";
16 @size = `mipsel-linux-size $fname`;
17 foreach (@size) {
18 if (($text, $data, $bss, $total) = $_ =~ /^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+/) {
19 $line = "$text\t$data\t$bss\t$total\t" . scalar localtime((stat($fname))[10]);
20 print "text\tdata\tbss\ttotal\ttime\n";
22 if (open(F, "<$dname")) {
23 @hist = <F>;
24 close(F);
25 if ($#hist >= 0) {
26 if ($#hist > 20) {
27 splice(@hist, 0, $#hist - 19);
29 print @hist;
30 if ($hist[$#hist] =~ /^(\d+)\t(\d+)\t(\d+)\t(\d+)\t/) {
31 if (($1 == $text) && ($2 == $data) && ($3 == $bss)) {
32 print "--- same size as last ---\n$line <= current\n";
33 exit 0;
35 printf "%d\t%d\t%d\t%d\t--- changes since above ---\n", ($text - $1), ($data - $2), ($bss - $3), ($total - $4);
40 print $line, "\n";
42 if ((localtime((stat($dname))[9]))[7] != (localtime())[7]) {
43 open(F, ">>$dname") || die "$dname: $!";
44 print F $line, "\n";
45 close(F);
47 exit 0;
50 exit 1;