summaryrefslogtreecommitdiffstats
path: root/tools/memory_watcher/scripts/finditem.pl
blob: e1171ef81fc9000d37365d0f36f25ef7162d5019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl

sub process_raw($$) {
  my $file = shift;
  my $search = shift;

  my %leaks = ();

  my $save = 0;
  my $print = 0;
  my $bytes = 0;
  my $calls = 0;
  my $sum_bytes = 0;
  my $sum_calls = 0;

  open (LOGFILE, "$file") or die("could not open $file");
  while(<LOGFILE>) {
    my $line = $_;
    if ($line =~ m/([0-9]*) bytes, ([0-9]*) items/) {
      $save = "";
      $print = 0;
      $bytes = $1;
      $calls = $2;
    }
    elsif ($line =~ m/$search/) {
      $print = 1;
    }
    elsif ($line =~ m/=============/) {
      $save .= $line;
      if ($print) {
        print "$bytes bytes ($calls calls)\n";
        print $save;
        $sum_bytes += $bytes;
        $sum_calls += $calls;
        $save = "";
        $print = 0;
        $calls = 0;
      }
    }
    $save .= $line;
  }
  print("TOTAL: $sum_bytes bytes ($sum_calls calls)\n");
}


# ----- Main ------------------------------------------------

# Get the command line argument
my $filename = shift;
my $search = shift;

# Process the file.
process_raw($filename, $search);