hist.pl




perl -e '

  $DEBUG=0;
  if  ( 1 == $DEBUG ) { $debug=1; }

  # set up maximum and minimum histogram buckets
  # buckets start at 1us
  # by setting the bucketmin to 5, the first bucket will contain 2^5, i3 32us, events and under
  # max bucket sets the time of the maximum bucket, everyting in this bucket will be that time or larger

  $bucketmin=8;
  $bucketmax=22;

  @buckett[0]="1us";
  @buckett[1]="2us";
  @buckett[2]="4us";
  @buckett[3]="8us";
  @buckett[4]="l6us";
  @buckett[5]="32us";
  @buckett[6]="64us";
  @buckett[7]=".1ms";   # 128us
  @buckett[8]=".2ms";   # 256us
  @buckett[9]=".5ms";   # 512us
  @buckett[10]="1ms";  # 1024us
  @buckett[11]="2ms";
  @buckett[12]="4ms";
  @buckett[13]="8ms";
  @buckett[14]="16ms";
  @buckett[15]="32ms";
  @buckett[16]="64ms";
  @buckett[17]="0.1s";
  @buckett[18]="0.2s";
  @buckett[19]="0.5s";
  @buckett[20]="1s";
  @buckett[21]="2s";
  @buckett[22]="5s";
  @buckett[23]="10s"; # 102
  @buckett[24]="25s"; # 256
  @buckett[25]="51s";
  @buckett[26]="102s";

 $| = 1;
  while (my $line = <STDIN>) {
       # printf("line: %s\n",  $line);
       $line=~ s/\s+//g;
       next if ($line =~ /^$/);
       if ( $line > 0 ) {
          $line=$line;
          $bucket=int(log($line)/log(2)+1);
          $buckets[$bucket]++;
          if ( $bucket >  $cur_max_bucket ) {
           $cur_max_bucket=$bucket
          }
          printf("line: %s\n",  $line)  if defined($debug) ;
          printf("bucket: %s\n",  $bucket)  if defined($debug) ;
       } else {
          printf("zeroline: %s\n",  $line) if defined($debug) ;
       }
  }

#
   for ($bucket = $bucketmin; $bucket < $bucketmax; $bucket++) {
      printf ("%6s", $buckett[$bucket] );
   }
 # highest bucket starts at last bucket up
   printf ("%6s+", $buckett[$bucketmax-1] );
   printf("\n");

        $sum_max=0;

         # sum up all the buckets below the minimum bucket
         for ($bucket = 0; $bucket <= $bucketmin; $bucket++) {
             $sum_min+= $buckets[$bucket] ;
             printf("sum_min: %d, bucket %d value %d\n",  $sum_min,  $bucket, $buckets[$bucket] )  if defined($debug) ;
         }

         # sum up all the buckets above the maximum bucket
         for ($bucket = $bucketmax; $bucket <= $cur_max_bucket; $bucket++) {
             $sum_max+= $buckets[$bucket] ;
             printf("sum_max: %d, bucket %d value %d\n",  $sum_max,  $bucket, $buckets[$bucket] )  if defined($debug) ;
         }

         # if maxbucket eq min bucket add the max and min
         if ( $bucketmin < $bucketmax ) {
              printf ("%6d",  $sum_min  );
              printf("\nfinal sum_min: %d \n",  $sum_min )  if defined($debug) ;
         } else  {
              printf ("%6d",  $sum_min + $sum_max  );
              printf("\n sum_max + sum_min : %d \n",  $sum_min + $sum_max )  if defined($debug) ;
         }

         # iterate through all the buckets between max and min bucket
         for ($bucket = $bucketmin+1; ( $bucket <= $cur_max_bucket && $bucket < $bucketmax ) ; $bucket++) {
             printf ("%6d",  $buckets[$bucket]  );
             $total+=$buckets[$bucket];
         }

         # print out max bucket if its below the maximum seen so far
         if ( $bucketmax <= $cur_max_bucket &&  $bucketmin  < $bucketmax ) {
            printf ("%6d",  $sum_max  );
         }

         printf("\n");

'





Comments