2 ################################################################################
6 # Description: Logs Clearcase activity
7 # Author: Andrew@DeFaria.com
8 # Created: Tue Dec 27 16:33:30 PST 2005
9 # Modified: 2007/05/17 07:45:48
12 # (c) Copyright 2000-2005, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
23 my $lib_path = $^O =~ /MSWin/ ? "\\\\brcm-irv\\dfs\\projects\\ccase\\SCM\\lib"
24 : "/projects/ccase/SCM/lib";
26 # Extract relative path and basename from script name.
27 $0 =~ /(.*)[\/\\](.*)/;
29 my $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
30 $me = (!defined $2) ? $0 : $2;
33 # Add the appropriate path to our modules to @INC array.
34 unshift @INC, "$lib_path";
35 unshift @INC, $ENV {SITE_PERL_LIBPATH} if defined $ENV {SITE_PERL_LIBPATH};
36 unshift @INC, "$abs_path";
47 # The lshistory command needs a view context. We'll create this view
49 my $tag = $ENV {DEFAULT_VIEW} ? $ENV {DEFAULT_VIEW} : "default";
51 # Path to logs directory
52 my $logdir = "$scm_base$/logs";
54 error "Logdir $logdir does not exist - $!", 1 if !-d $logdir;
59 display "ERROR: $msg\n" if defined $msg;
61 display "Usage: $me\t[-u] [-v] [-d] [-n <# of days>]
66 -v: Turn on verbose mode
67 -d: Turn on debug mode
68 -n: Number of days to report (Default: 1)
70 Note: Number of days is relative to midnight. Output is to a logfile named
71 activity.<date>.log. Since we want <date> to be accurate this script attempts
72 to have each log file have only that days activity. Therefore -n 1 will report
73 everything in the last full 24 hour day, -n2 will be the last two full 24 hour
85 my $cc = Clearcase->new;
87 my $cmd = "$Clearcase::cleartool setview -exec \"$Clearcase::cleartool lshistory -since $since -avobs -fmt '%Nd;%Fu;%u@%h;%e;%n\\n'\" $view";
90 or error "Unable to open pipe for $cmd", 1;
97 # Split the line into fields. The first field is date and time
98 my @fields = split /;/;
100 # Now split the first field by "." which separates the date and time
101 @fields = split /\./, $fields [0];
103 # Never report today's activity because today's never over!
104 # Reporting on today may give a partial result
105 next if $fields [0] eq $today_ymd;
107 # Ugh - might have stuff that's future dated!
108 next if $fields [0] gt $today_ymd;
110 # Skip noise. In this case noise is activity to the perftest
111 # vob. No normal activity happens to perftest - just performance
113 next if /${Clearcase::vobtag_prefix}perftest/;
115 if ($fields [0] lt $date) {
117 my $log_filename = $cc->sitename . ".activity.$date";
118 verbose "Starting logfile $log_filename";
120 $logfile = Logger->new (name => $log_filename, path => $logdir);
133 if ($ARGV [0] eq "-v") {
134 Display::set_verbose;
135 } elsif ($ARGV [0] eq "-d") {
137 } elsif ($ARGV [0] eq "-n") {
140 $nbr_days = $ARGV [0];
142 Usage "Need to specify nbr_days after -n";
144 } elsif ($ARGV [0] eq "-u") {
147 Usage "Invalid argument: $ARGV [0]";
155 verbose "Creating view $tag";
156 my $view = Clearcase::View->new (tag => $tag);
159 verbose "Mounting all vobs";
160 my $vobs = Clearcase::Vobs->new;
164 my $seconds_in_day = 60 * 60 * 24;
165 my $since = YMD ($today - ($nbr_days * $seconds_in_day));
167 verbose "Producing report";
168 ReportActivity $tag, $since;