--- a/fbs/fontandbitmapserver/utils/fbsbitmap_memory.pl Fri Sep 17 08:36:49 2010 +0300
+++ b/fbs/fontandbitmapserver/utils/fbsbitmap_memory.pl Mon Oct 04 02:31:51 2010 +0300
@@ -26,9 +26,6 @@
# and run this script against it. The resulting file can then be imported into
# a spreadsheet application to be visually processed.
#
-# KNOWN DEFECTS:
-# Once the log time goes beyond midnight, snapshots will stop being taken.
-#
use strict;
@@ -57,6 +54,7 @@
##
my $heartBeatCount = 0;
my $nextHeartBeatMS = -1;
+my $logLastLineTimeMS = 0;
# A hash of thread names to the amount of bitmap memory they
# have used since the start of the trace.
@@ -98,14 +96,13 @@
## Read from the file.
## Read the log into an array line by line.
my $TRACE_FILENAME = $ARGV[0];
-open(INPUT_FILE, $TRACE_FILENAME) or die $!;
-my @traceLines = <INPUT_FILE>;
-
+open(INPUT_FILE, '<', $TRACE_FILENAME) or die $!;
+binmode(INPUT_FILE);
##
## Parse each line sequentially...
##
-foreach my $line (@traceLines)
+while ( my $line = <INPUT_FILE> )
{
my $timeFromMidnightMS;
@@ -144,26 +141,35 @@
if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/)
{
$timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4;
- # Set up the time for the first snapshot.
if ($nextHeartBeatMS == -1)
{
- $nextHeartBeatMS = $timeFromMidnightMS + $firstHeartBeatTimeMS;
+ $nextHeartBeatMS = $firstHeartBeatTimeMS;
+ $logLastLineTimeMS = $timeFromMidnightMS;
}
- }
+ ## We have wrapped around midnight!
+ ## Add a 1000ms cushion to the comparison to avoid wrapping around
+ ## midnight if a trace is buffered too slowly.
+ if (($timeFromMidnightMS+1000) < $logLastLineTimeMS)
+ {
+ $timeFromMidnightMS += 86400000;
+ }
+ $nextHeartBeatMS -= ($timeFromMidnightMS - $logLastLineTimeMS);
+ $logLastLineTimeMS = $timeFromMidnightMS;
- ##
- ## If heartbeat reached, take snapshot of bmp memory per thread
- ## and set next heartbeat time.
- ##
- while ($timeFromMidnightMS >= $nextHeartBeatMS)
- {
- $nextHeartBeatMS += $heartBeatMS;
- # take a snapshot of the current bitmap memory usage per thread
- while ((my $thread, my $bmpMemory) = each(%bmpMemoryPerThread))
+ ##
+ ## If heartbeat reached, take snapshot of bmp memory per thread
+ ## and set next heartbeat time.
+ ##
+ while ($nextHeartBeatMS <= 0)
{
- $arrayOfSnapshots[$heartBeatCount]{$thread} = $bmpMemory;
+ $nextHeartBeatMS += $heartBeatMS;
+ # take a snapshot of the current bitmap memory usage per thread
+ while ((my $thread, my $bmpMemory) = each(%bmpMemoryPerThread))
+ {
+ $arrayOfSnapshots[$heartBeatCount]{$thread} = $bmpMemory;
+ }
+ $heartBeatCount++;
}
- $heartBeatCount++;
}
## FBS Client-side traces.