diskDelay.prl 3.13 KB
#!/usr/local/bin/perl5
#
# 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. 
#

#
# Use the output from the disk device to measure the delays 
# experienced by the disks. 
#
# $Author: blythe $
# $Date: 2002/05/29 01:09:09 $

$inputFile = shift;

if (!defined( $inputFile)) {
    $inputFile = "cpu.log";
}

open(LOG,$inputFile);


# Initialization
for ($i=0; $i<16; $i++) {
    $savedOp[$disk]    = 0;
    $savedStart[$disk] = 0;
    $savedSize[$disk]  = 0;
    $maxDiff[$disk]    = 0;
    $minDiff[$disk]    = 10000000000;
    $totalDiff[$disk]  = 0;
}


$maxDisk = 0;
#$disklabel = 0;
$disk = 0;

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

    if (defined($log) ) { 
        if ($log eq "CONFIG") {
            if ($time eq "CpuClock") {
                $clockRate = $event;
            }
        }

        if ($log eq "LOG" ) {
            if ($event eq "DISK-req" ) {
                $savedOp[$disk] = $op;
                $savedStart[$disk] = $time;
                $savedSize[$disk] = $size;
                if ($disk > $maxDisk) {
                    $maxDisk = $disk;
                }
            } 
            if ($event eq "DISK-ack" ) {
                if ($savedStart[$disk] != 0 ) { 
                    $diff = $time-$savedStart[$disk];
                    $allDiffs[$disk][$entries[$disk]] = $diff;
                    $entries[$disk]++;
                    if ($minDiff[$disk] > $diff ) {   
                        $minDiff[$disk] = $diff;
                    }
                    if ($diff >  $maxDiff[$disk]) {
                        $maxDiff[$disk] = $diff; 
                    }
                    $totalDiff[$disk] += $diff;
                    $savedStart[$disk] = 0;
                } else {
                    print "No start for disk $disk\n";
                    print $_;
                } 
            }         
        }
    }
}

$unit = $clockRate * 1000;

for ($disk=0; $disk <= $maxDisk; $disk++) {
    printf("\nDisk %d\n", $disk);
    printf("=======\n");

    if ($entries[$disk]) {
        $avgDiff = $totalDiff[$disk] * 1.0 / $entries[$disk];
        printf("Requests=%d: Min = %3.1f Max = %3.1f  Avg = %.2f [ms]\n",
               $entries[$disk], $minDiff[$disk]/$unit, 
               $maxDiff[$disk]/$unit, $avgDiff/$unit);
        
        $maxHisto = 0;
        for ($i=0; $i < $entries[$disk]; $i++) {
            $j = int($allDiffs[$disk][$i]*1.0/$unit);
            $histogram[$disk][$j]++;
            if ($j > $maxBucket[$disk]) { 
                $maxBucket[$disk] = $j;
            }
        }
        
        for ($bucket=0; $bucket<=$maxBucket[$disk]; $bucket++) {
            if (defined($histogram[$disk][$bucket]) ) {
                printf("%d-%d ms:\t %5.2f %%\n", $bucket, $bucket+1, 
                       100.0 * $histogram[$disk][$bucket]/$entries[$disk]);
            } else { 
                printf("%d-%d ms:\t %5.2f\n", $bucket, $bucket+1, 0.0);
            }
        }
    } else {
        print "NO REQUESTS\n";
    }
}