#!/usr/bin/perl # # Create an SVG file that displays a gradient-histogram of file sizes # for a given directory and its subdirectories. # # The SVG goes to standard output. # # Copyright (C) 2002 J. David Eisenberg under GPL # use warnings; use strict; use File::Find; my @file_sizes; # array of file sizes my $total_files; # number of files in directory and subdirectories my $max_file_size; # maximum file size if (scalar @ARGV != 1) { print "Create SVG diagram showing file size ", " distribution for a directory\n"; print "Usage: $0 directory\n"; exit(0); } $total_files = 0; $max_file_size = 0; find(\&accumulate, $ARGV[0]); # # Create the header of the SVG file # print <<"SVG_HEAD"; File sizes for $ARGV[0] Distribution of file sizes of $ARGV[0] and its subdirectories SVG_HEAD my $size; # size of an individual file my $i; # the ubiquitous loop counter my $x; # x-offset of a size range my $pct_count; # % of files in a range my $hue; # amount of blue; # equal to 100 - file percentage my @slots; # number of files in each range # # figure out how many files are in # each percent of the range of file sizes # foreach $size (@file_sizes) { $pct_count = int(100 * $size/$max_file_size); if ($pct_count == 100) { $pct_count = 99; } $slots[$pct_count]++; } print qq!\n!; print qq!\t\n!; print qq!\t\t$ARGV[0] ($total_files files)\n!; print qq!\t\n!; for ($i=0; $i < 100; $i++) { next if (!$slots[$i]); $hue = 90 - int(100 * $slots[$i]/$total_files); if ($hue < 0 ) { $hue = 0; } $x = $i * 6; # display the rectangle print qq!\t\n!; # fill in the text if ($slots[$i] < 10) { print qq!\t$slots[$i]\n\n!; } else { print qq!\t$slots[$i]\n\n!; } } print qq!\t\n!; print qq!\t\n!; # # put labels beneath the bar # print qq!\t\n!; # # the zero label # print qq!\t\t!; print "0"; print qq!\n!; # # the middle label # print qq!\t\t!; print int($max_file_size/2048), "k"; print qq!\n!; # # the end label # print qq!\t\t!; print int($max_file_size/1024), "k"; print qq!\n!; print qq!\t\n!; # ends labeling print qq!\n!; # ends graph print "\n"; sub accumulate { my @info; if (-f $_) { @info = stat($_); push @file_sizes, $info[7]; if ($info[7] > $max_file_size) { $max_file_size = $info[7]; } $total_files++; } }