Changeset 0edbc98


Ignore:
Timestamp:
05/28/15 18:45:11 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
65ecf6c
Parents:
6bfe6a1
git-author:
Hal Finkel <hfinkel@…> (05/28/15 18:45:11)
git-committer:
Hal Finkel <hfinkel@…> (05/28/15 18:45:11)
Message:

only process allocations at the high-water mark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog2dot

    r6bfe6a1 r0edbc98  
    1515open(MEMLOG, $memlog_fn) || die "Can't open $memlog_fn: $!"; 
    1616 
     17# The first step is to determine the high-water mark. 
     18my $max_rss = 0; 
     19foreach my $line (<MEMLOG>) { 
     20  chomp($line); 
     21  my @parts = split(/\t/, $line); 
     22 
     23  my $op = shift(@parts); 
     24  my $state = shift(@parts); 
     25 
     26  my ($time, $then_max_rss, $tid) = split(/\s+/, $state); 
     27  if ($max_rss < $then_max_rss) { 
     28    $max_rss = $then_max_rss; 
     29  } 
     30} 
     31 
     32seek(MEMLOG, 0, 0); 
     33 
     34# Scan the log for malloc/free pairings. We're interested only in active 
     35# allocations at the time when the rss reaches the final maxrss. 
     36my $max_rss_time = 0; 
     37my %malloc_lines; 
     38foreach my $line (<MEMLOG>) { 
     39  chomp($line); 
     40  my @parts = split(/\t/, $line); 
     41 
     42  my $op = shift(@parts); 
     43  my $state = shift(@parts); 
     44 
     45  if ($op =~ /^M:/) { 
     46    my ($size, $ptr) = ($op =~ /^M: (\d+) 0x(\w+)/); 
     47    $malloc_lines{$ptr} = $line; 
     48  } elsif ($op =~ /^F:/) { 
     49    my ($ptr) = ($op =~ /^F: 0x(\w+)/); 
     50    delete $malloc_lines{$ptr}; 
     51  } else { 
     52    next; 
     53  } 
     54 
     55  # If we've reached the max rss, we've seen all we need to see. 
     56  my ($time, $then_max_rss, $tid) = split(/\s+/, $state); 
     57  $max_rss_time = $time; 
     58  if ($then_max_rss == $max_rss) { 
     59    last; 
     60  } 
     61} 
     62 
     63close(MEMLOG); 
     64 
     65# Convert maxrss, currently in KB, to bytes. 
     66$max_rss *= 1024; 
     67 
    1768my $total_size = 0; 
    1869my %roots; 
    1970my %all_nodes; 
    20 foreach my $line (<MEMLOG>) { 
    21   chomp($line); 
     71foreach my $line (values %malloc_lines) { 
    2272  my @parts = split(/\t/, $line); 
    2373 
     
    3181 
    3282  my ($size, $ptr) = ($op =~ /^M: (\d+) 0x(\w+)/); 
    33   my ($time, $maxrss, $tid) = split(/\s+/, $state); 
     83  my ($time, $then_max_rss, $tid) = split(/\s+/, $state); 
    3484 
    3585  $total_size += $size; 
     
    88138} 
    89139 
    90 close(MEMLOG); 
    91  
    92140my $dot_fn = "$out_dir/" . basename($memlog_fn) . ".dot"; 
    93141my $ps_fn = "$out_dir/" . basename($memlog_fn) . ".ps"; 
     
    109157} 
    110158 
    111 printf DOT ("digraph \"memlog %s\" {\n", format_bytes($total_size)); 
     159printf DOT ("digraph \"memlog %s (maxrss = %s after %s s)\" {\n", 
     160            format_bytes($total_size), format_bytes($max_rss), $max_rss_time); 
    112161print DOT ("size=\"8,11\";\n"); 
    113162print DOT ("node [width=0.375,height=0.25];\n"); 
Note: See TracChangeset for help on using the changeset viewer.