-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap-analyser.pl
executable file
·81 lines (64 loc) · 1.93 KB
/
heap-analyser.pl
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
use strict;
use warnings;
my @node_types = ("hidden","array","string","object","code","closure","regexp","number","native","synthetic","concatenated_string","sliced_string");
# "type","name","id","self_size","edge_count","trace_node_id"
# "nodes":[9,1,1,0,5,0
# ,9,2,3,0,17,0
# ,9,3,5,0,2452,0
my @edge_types = ("context","element","property","internal","hidden","shortcut","weak");
# "type","name_or_index","to_node"
# "edges":[1,1,6
# ,5,4021,9546
# "strings":["<dummy>",
# "",
my $state = 0;
my $size = {};
my $count = {};
my $names = {};
my $strings = [];
my $total_size = 0;
while(<>) {
if (/^"nodes":\[/) {
$state = 1;
s/^"nodes":\[//;
}
if (/^\],/) {
$state = 0;
}
if (/^"strings":\[/) {
$state = 3;
s/^"strings":\[//;
}
if ($state == 1) {
s/^,//;
my @fields = split(/,/);
$count->{$fields[0]}++;
$size->{$fields[0]} += $fields[3];
$total_size += $fields[3];
$names->{$fields[0]}->{$fields[1]}->{count}++;
$names->{$fields[0]}->{$fields[1]}->{size} += $fields[3];
}
elsif ($state == 3) {
if (/^"(.*)"(,|\]})$/) {
push @$strings, $1;
}
else {
warn "couldn't parse $_";
}
}
}
print "type\tcount\ttotal_size\tname\n";
print "----\t-----\t----------\t----\n";
foreach my $type (sort {$names->{$b} <=> $names->{$a}} keys %$names) {
foreach my $name (sort {$names->{$type}->{$b}->{count} <=> $names->{$type}->{$a}->{count}} keys %{$names->{$type}}) {
print($node_types[$type]."\t".
$names->{$type}->{$name}->{count}."\t".
$names->{$type}->{$name}->{size}."\t".
substr($strings->[$name], 0, 64)."\n");
}
}
# foreach (sort {$size->{$b} <=> $size->{$a}} keys %$size) {
# print($_."\t".$node_types[$_]."\t".$size->{$_}."\t".$count->{$_}."\n");
# }
# print "total_size: $total_size\n";