diskUtil.prl 3.32 KB
#!/usr/local/bin/perl5 -w
#
# Copyright (C) 1996-1998 by the Board of Trustees
#    of Leland Stanford Junior University.
# 
# This file is part of the SimOS distribution. 
# See LICENSE file for terms of the license. 
#


$inputFile = shift;
if( !defined( $inputFile ) ) {
    $inputFile = "cpu.log";
}
open(LOG,$inputFile);

$startTime = 0;
$entries = 0;
$minDiff = 10000000000;
$maxDiff = 0;
$totalDiff = 0;
$proc = 0;
$disklabel = 0;
$disk = 0;

for $i ( 0..10 ) {
    $usedTime[$i] = 0;
    $freeTime[$i] = 0;
    $lastUsed[$i] = 0;
    $prevUsed[$i] = 0;
    $diskInUse[$i] = 0;
}

while( <LOG>) {
    ($log,$time,$event,$cpu,$proc,$disklabel,$diskInfo,$op,$sizelabel,$size) = 
        split;
    if( defined($log) ) { 

        if( $log eq "CONFIG") {
            if( $time eq "CpuClock") {
                $clockRate = $event;
                $baseInt = $clockRate * 1000 * 40;
                $nextInt = $clockRate * 1000 * 40 ;
                $timeMS = 1;
            }
        }
        if ($log eq "PARAM")  {
            if ($time eq "CPU.Clock") {
                $clockRate = $event;
                $baseInt = $clockRate * 1000 * 40;
                $nextInt = $clockRate * 1000 * 40 ;
                $timeMS = 1;
            }
        }
            
        if( $log eq "LOG" ) {
            while( $time > $nextInt ) { 
                printf( "%8.5f  ", $nextInt/ ($clockRate * 1000000));
                for $i (1..8) { 
                    if( $diskInUse[$i] ) { 
                        $usedTime[$i] += $nextInt - $savedStart[$i];
                        $savedStart[$i] = $nextInt;
                    }
                    printf( "%6.2f ", 100 * ($usedTime[$i]-$prevUsed[$i])/$baseInt);
                    $prevUsed[$i] = $usedTime[$i];
                }
                printf("\n");
                $nextInt += $baseInt;
            }
                
            if( $event eq "DISK-req" ) {
                if ($diskInfo eq "disk") { 
                    ($foo,$disk) = split(/\./,$op);
                } else {
                    ($foo,$disk) = split(/\./,$diskInfo);
                }
                $freeTime[$disk] += $time - $lastUsed[$disk];
                $savedOp[$disk] = $op;
                $savedStart[$disk] = $time;
                $savedSize[$disk] = $size;
                $diskInUse[$disk] = 1;
            } 
            if( $event eq "DISK-ack" ) {
                ##
                ## deall with 'kernel idle' being a process name!
                if ($diskInfo eq "disk") { 
                    ($foo,$foo2,$disk) = split(/\./,$op);
                } else {
                    ($foo,$foo2,$disk) = split(/\./,$diskInfo);
                }
                #print "XXX $diskInfo --> $foo|$foo2|$disk \n";
                if( $savedStart[$disk] != 0 ) { 
                    $diff = $time-$savedStart[$disk];
                    $usedTime[$disk] += $diff;
                    $savedStart[$disk] = 0;
                    $diskInUse[$disk] = 0;
                } else {
                    print "No start for disk $disk in $remainder\n";
                    print $_;
                } 
            }         
        }
    }

}

# Unused variables - comment out if you ever use these
$cpu = 0;
$savedSize = 0;
$savedOp   = 0;

$timeMS = 0;
$remainder = 0;
$entries = 0;
$totalDiff = 0;
$minDiff = 0;
$startTime = 0;
$maxDiff = 0;
$sizelabel = 0;