fbs/fontandbitmapserver/utils/fbsbitmap_memory.pl
changeset 178 89bd4cfee505
parent 160 969102054596
equal deleted inserted replaced
171:414d4b727fd9 178:89bd4cfee505
    24 #  GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS and GRAPHICS_CONTROL_FUNCTIONS in
    24 #  GRAPHICS_RESOURCE_MANAGEMENT_FUNCTIONS and GRAPHICS_CONTROL_FUNCTIONS in
    25 #  FBSCLI OST dictionary. Once tracing is gathered, save trace output as ascii 
    25 #  FBSCLI OST dictionary. Once tracing is gathered, save trace output as ascii 
    26 #  and run this script against it. The resulting file can then be imported into
    26 #  and run this script against it. The resulting file can then be imported into
    27 #  a spreadsheet application to be visually processed.
    27 #  a spreadsheet application to be visually processed.
    28 #  
    28 #  
    29 #  KNOWN DEFECTS:
       
    30 #  Once the log time goes beyond midnight, snapshots will stop being taken.
       
    31 #
       
    32 
    29 
    33 use strict;
    30 use strict;
    34 
    31 
    35 # Sanity checking of the command line parameters...
    32 # Sanity checking of the command line parameters...
    36 if ($#ARGV == -1 || $ARGV[0] eq "help" || $ARGV[0] eq "/?")
    33 if ($#ARGV == -1 || $ARGV[0] eq "help" || $ARGV[0] eq "/?")
    55 ##
    52 ##
    56 ## Internal structures...
    53 ## Internal structures...
    57 ##
    54 ##
    58 my $heartBeatCount = 0;
    55 my $heartBeatCount = 0;
    59 my $nextHeartBeatMS = -1;
    56 my $nextHeartBeatMS = -1;
       
    57 my $logLastLineTimeMS = 0;
    60 
    58 
    61 # A hash of thread names to the amount of bitmap memory they 
    59 # A hash of thread names to the amount of bitmap memory they 
    62 # have used since the start of the trace.
    60 # have used since the start of the trace.
    63 my %bmpMemoryPerThread = ();
    61 my %bmpMemoryPerThread = ();
    64 
    62 
    96 }
    94 }
    97 
    95 
    98 ## Read from the file.
    96 ## Read from the file.
    99 ## Read the log into an array line by line.
    97 ## Read the log into an array line by line.
   100 my $TRACE_FILENAME = $ARGV[0];
    98 my $TRACE_FILENAME = $ARGV[0];
   101 open(INPUT_FILE, $TRACE_FILENAME) or die $!;
    99 open(INPUT_FILE, '<', $TRACE_FILENAME) or die $!;
   102 my @traceLines = <INPUT_FILE>;
   100 binmode(INPUT_FILE);
   103 
       
   104 
   101 
   105 ##
   102 ##
   106 ## Parse each line sequentially...
   103 ## Parse each line sequentially...
   107 ##
   104 ##
   108 foreach my $line (@traceLines)
   105 while ( my $line = <INPUT_FILE> )
   109 {
   106 {
   110    my $timeFromMidnightMS;
   107    my $timeFromMidnightMS;
   111 
   108 
   112    ## 
   109    ## 
   113    ## If this line is about a new process, make a note of the name and the
   110    ## If this line is about a new process, make a note of the name and the
   142    ## take a snapshot and 
   139    ## take a snapshot and 
   143    ##
   140    ##
   144    if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/)
   141    if ($line =~ /^(\d\d):(\d\d):(\d\d)\.(\d{3})/)
   145    {
   142    {
   146       $timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4;
   143       $timeFromMidnightMS = ((($1 * 3600) + ($2 * 60) + $3) * 1000) + $4;
   147       # Set up the time for the first snapshot.
       
   148       if ($nextHeartBeatMS == -1) 
   144       if ($nextHeartBeatMS == -1) 
   149       {
   145       {
   150          $nextHeartBeatMS = $timeFromMidnightMS + $firstHeartBeatTimeMS;
   146          $nextHeartBeatMS = $firstHeartBeatTimeMS;
   151       }
   147          $logLastLineTimeMS = $timeFromMidnightMS;
   152    }
   148       }
   153 
   149       ## We have wrapped around midnight!
   154    ##
   150       ## Add a 1000ms cushion to the comparison to avoid wrapping around 
   155    ## If heartbeat reached, take snapshot of bmp memory per thread
   151       ## midnight if a trace is buffered too slowly.
   156    ## and set next heartbeat time.
   152       if (($timeFromMidnightMS+1000) < $logLastLineTimeMS)
   157    ##
   153       {
   158    while ($timeFromMidnightMS >= $nextHeartBeatMS)
   154          $timeFromMidnightMS += 86400000;
   159    {
   155       }
   160       $nextHeartBeatMS += $heartBeatMS;
   156       $nextHeartBeatMS -= ($timeFromMidnightMS - $logLastLineTimeMS);
   161       # take a snapshot of the current bitmap memory usage per thread
   157       $logLastLineTimeMS = $timeFromMidnightMS;
   162       while ((my $thread, my $bmpMemory) = each(%bmpMemoryPerThread))
   158 
   163       {
   159       ##
   164            $arrayOfSnapshots[$heartBeatCount]{$thread} = $bmpMemory;
   160       ## If heartbeat reached, take snapshot of bmp memory per thread
   165       }
   161       ## and set next heartbeat time.
   166       $heartBeatCount++;
   162       ##
       
   163       while ($nextHeartBeatMS <= 0)
       
   164       {
       
   165          $nextHeartBeatMS += $heartBeatMS;
       
   166          # take a snapshot of the current bitmap memory usage per thread
       
   167          while ((my $thread, my $bmpMemory) = each(%bmpMemoryPerThread))
       
   168          {
       
   169               $arrayOfSnapshots[$heartBeatCount]{$thread} = $bmpMemory;
       
   170          }
       
   171          $heartBeatCount++;
       
   172       }
   167    }
   173    }
   168 
   174 
   169    ## FBS Client-side traces.
   175    ## FBS Client-side traces.
   170    if ($line =~ m/\tFBSCLI: /)
   176    if ($line =~ m/\tFBSCLI: /)
   171    {
   177    {