#!/usr/bin/perl -w # day-report.pl -- create day reports based on rush's "jobinfo" files # # The ROFER/WOT project liked to archive all the jobinfo files from every job, # using a jobdumpcommand to automatically archive these files by date/time/jobid. # # This script walks the directory of those jobinfo files, and generates # day reports for the Producers of the show to indicate what was rendered each day. # # erco 1.00 ??/??/04 # use strict; $|=1; my $day = $ARGV[0]; # "may5" if ( $day eq "" ) { print STDERR "Expected eg. 'dayreport.pl may5' (assuming 'may5')\n"; $day = "may5"; } # print STDERR "# DAY=$day\n"; sub Percentage($$) { my ($total, $part) = @_; if ( $total < 0 ) { $total = 1; } if ( $part > $total ) { $part = $total; } if ( $part < 0 ) { $part = 0; } my $perc = int(100.0*($part/$total) + 0.5); if ( $perc > 100 ) { $perc = 100; } if ( $perc < 0 ) { $perc = 0; } return($perc); } # RETURN DATESTAMP ON FILE # Returns YYYY/MM/DD format, for easy sorting # sub GetDateStamp($) { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime, $ctime,$blksize,$blocks) = stat($_[0]); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime); return(sprintf("%04d/%02d/%02d",1900+$year,$mon+1,$mday)); } my @jobinfo_filenames; # Get a list of all 'jobinfo' files my $cmd = "dir /s /b \\\\roferraid\\wot_data\\rush\\rush_logs\\$day"; # print STDERR "# CMD=$cmd\n"; unless( open(DIRLIST, "$cmd|")) { print STDERR "DIR command failed: $!.\n"; exit(1); } while ( ) { chomp($_); if ( ! /jobinfo$/ ) { next; } # print STDERR "# DIR: $_\n"; push(@jobinfo_filenames, $_); } close(DIRLIST); # Header printf("%-10s %-55s %-10s %-10s %-10s %-10s %8s\n", " Date", "Title", "User", "Frames", "%Done", "%Fail", "CpuHours"); # Open each file, accumulate data my @report; my $jobinfo; foreach $jobinfo ( @jobinfo_filenames ) { # print STDERR "# WORKING ON $jobinfo\n"; # LOAD JOBINFO my $date = GetDateStamp($jobinfo); # date for generated data unless ( open(JINFO, "<$jobinfo") ) { print STDERR "open($jobinfo) failed: $!\n"; exit(1); } my %job; while ( ) { if ( /User: (\S+)/ ) { $job{User} = $1; next; } if ( /Title: (\S+)/ ) { $job{Title} = $1; next; } if ( /Frames: (\S+)/ ) { $job{Frames} = $1; next; } if ( /FramesDone: (\S+)/ ) { $job{FramesDone} = $1; next; } if ( /FramesFail: (\S+)/ ) { $job{FramesFail} = $1; next; } } close(JINFO); # LOAD FRAMELIST TO GET ELAPSED TIME my $framelist = $jobinfo; $framelist =~ s/jobinfo$/framelist/; unless ( open(FRAMELIST, "<$framelist") ) { print STDERR "open($framelist) failed: $!\n"; exit(1); } while ( ) { # PARSE THE ELAPSED TIME FOR 'DONE' FRAMES # STAT FRM TRY HOST PID JID START ELAPSED if ( /Done\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+:\d+:\d+)/ ) { my ($h,$m,$s) = ($1,$2,$3); # ELAPSED TIME $job{ElapsedSecs} += (( $h * 3600 ) + ( $m * 60 ) + $s); } } close(JINFO); $job{ElapsedHours} = $job{ElapsedSecs} / 3600.0; printf("%-10s %-55s %-10s %-10s %-10s %-10s %8s\n", $date, $job{Title}, $job{User}, $job{Frames}, Percentage($job{Frames}, $job{FramesDone}), Percentage($job{Frames}, $job{FramesFail}), sprintf("%.1f", $job{ElapsedHours})); }