All pastes #913502 Raw Edit

Something

public text v1 · immutable
·published 2008-02-22 03:12 UTC
rendered paste body
open LOG, "<", "topmod.txt" or die $!;
	my @logLines = <LOG>;
	close LOG;
	
	
	%totalCPU = {};
	%totalMemory = {};
	%processCount = {};
	
	#Stores the start time of this 30 second interval
	my $StartTime = 0;
	#The calculated end time of this 30 second interval
	my $EndTime = 0;
	
	#Set the first value...
	if ($logLines[0] =~ /^resc\s+(\d+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+)\s+(\d+\.\d+)\s+\d+:\d+\.\d+(\S+)/)
	{
		#Start time is equal to the time of the first entry
		$StartTime = $1;
		#End time is 30 seconds from the start time
		$EndTime = $1 + 30;
	}
	
	foreach(@logLines)
	{
		#$1 is the time, $2 is the CPU, $3 is the memory, $4 is the process name
		if (/^resc\s+(\d+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+)\s+(\d+\.\d+)\s+\d+:\d+\.\d+(\S+)/)
		{	
				#if true then 30 seconds is up
				if($StartTime >= $EndTime)
				{
					#print out or store average for 30 second interval here
					
					#set new start and end values
					$StartTime = $1;
					$EndTime = $1 + 30;
					
					#Clear values
					%totalCPU = {};
					%totalMemory = {};
					%processCount = {};
				}
				
				$totalCPU{$4} += $2;
				$totalMemory{$4} += $3;
				$processCount{$4}++;
				
		}
	}