Changeset 9fcaba3 for memlog_analyze


Ignore:
Timestamp:
06/01/15 05:56:52 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
0109b01
Parents:
3533094
git-author:
Hal Finkel <hfinkel@…> (06/01/15 05:56:52)
git-committer:
Hal Finkel <hfinkel@…> (06/01/15 05:56:52)
Message:

add leak-finding mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog_analyze

    r3533094 r9fcaba3  
    44use Getopt::Long; 
    55 
     6my $find_leaks = 0; 
    67my $print_raw_proc_name = 0; 
    78my $quiet = 0; 
     
    1314Usage: $0 [options] <memlog file> [<output directory>] 
    1415  options: 
     16    --leaks 
     17      Provide information on leaks instead of peak usage 
    1518    --print-symbol-names 
    1619      Include symbol names and offsets in the output 
     
    2427 
    2528GetOptions("help|h|?" => \$help, 
     29           "leaks" => \$find_leaks, 
    2630           "print-symbol-names" => \$print_raw_proc_name, 
    2731           "quiet|q" => \$quiet) 
     
    6973# Scan the log for malloc/free pairings. We're interested only in active 
    7074# allocations at the time when the rss reaches the final maxrss. 
    71 my $max_rss_time = 0; 
     75# If we're finding leaks, then go to the very end. 
     76my $active_alloc_time = 0; 
    7277my %malloc_lines; 
    7378foreach my $line (<MEMLOG>) { 
     
    8893  } 
    8994 
    90   # If we've reached the max rss, we've seen all we need to see. 
    9195  my ($time, $then_max_rss, $tid) = split(/\s+/, $state); 
    92   $max_rss_time = $time; 
    93   if ($then_max_rss == $max_rss) { 
    94     last; 
     96  $active_alloc_time = $time; 
     97 
     98  if (!$find_leaks) { 
     99    # If we've reached the max rss, we've seen all we need to see. 
     100    if ($then_max_rss == $max_rss) { 
     101      last; 
     102    } 
    95103  } 
    96104} 
     
    207215print DOT ("node [width=0.375,height=0.25];\n"); 
    208216 
     217my $find_type = $find_leaks ? " (leaks)" : ""; 
    209218printf DOT ("Legend [shape=box, fontsize=100, shape=oval," . 
    210             "label=\"Total: %s active at maxrss = %s after %s s\"];\n", 
    211             format_bytes($total_size), format_bytes($max_rss), $max_rss_time); 
    212  
    213 printf TXT ("memlog: Total: %s active at maxrss = %s after %s s\n\n", 
    214             format_bytes($total_size), format_bytes($max_rss), $max_rss_time); 
     219            "label=\"Total: %s active$find_type at maxrss = %s after %s s\"];\n", 
     220            format_bytes($total_size), format_bytes($max_rss), 
     221            $active_alloc_time); 
     222 
     223printf TXT ("memlog: Total: %s active$find_type at maxrss = %s after %s s\n\n", 
     224            format_bytes($total_size), format_bytes($max_rss), 
     225            $active_alloc_time); 
    215226 
    216227my %cached_names; 
Note: See TracChangeset for help on using the changeset viewer.