Bug 596580: Fix mozJSSubScriptLoader's version finding. (r=brendan)
[mozilla-central.git] / xpcom / tools / analyze-xpcom-log.pl
blob81ccb2123024d52fe471d72b6e5396dfd8082d13
1 #!/usr/local/bin/perl -w
3 # Perl script to analyze the xpcom output file
5 # To create xpcom output file :
7 # setenv NSPR_LOG_MODULES nsComponentManager:5
8 # setenv NSPR_LOG_FILE xpcom.out
9 # ./mozilla
11 # Also to try to convert CID -> contractID this program looks for
12 # a file reg.out in the current directory. To generate this file
14 # $ regExport > reg.out
16 # Usage: analyze-xpcom-log.pl < xpcom.out
17 # [does better if ./reg.out is available]
19 # Suresh Duddi <dpsuresh@netscape.net>
22 use strict;
24 # forward declarations
25 sub getContractID($);
26 sub sum($);
28 # Configuration parameters
29 # Print all ?
30 my $all = 0;
32 # hash of cid -> contractid
33 my %contractid;
34 my %contractid_n;
35 my %failedContractid_n;
37 # count of instances of objects created
38 my (%objs, %objs_contractid, %failedObjs) = ();
40 # dlls loaded
41 my @dlls;
43 # temporaries
44 my ($cid, $n, $str);
46 while (<>) {
47 chomp;
49 # dlls loaded
50 if (/loading \"(.*)\"/) {
51 push @dlls, $1;
52 next;
55 # FAILED ContractIDToClassID
56 if (/ContractIDToClassID\((.*)\).*\[FAILED\]/) {
57 $failedContractid_n{$1}++;
58 next;
61 # ContractIDToClassID
62 if (/ContractIDToClassID\((.*)\).*\{(.*)\}/) {
63 $contractid{$2} = $1;
64 $contractid_n{$2}++;
65 next;
68 # CreateInstance()
69 if (/CreateInstance\(\{(.*)\}\) succeeded/) {
70 $objs{$1}++;
71 next;
74 # CreateInstanceByContractID()
75 if (/CreateInstanceByContractID\((.*)\) succeeded/) {
76 $objs_contractid{$1}++;
77 next;
80 # FAILED CreateInstance()
81 if (/CreateInstance\(\{(.*)\}\) FAILED/) {
82 $failedObjs{$1}++;
83 next;
87 # if there is a file named reg.out in the current dir
88 # then use that to fill in the ContractIDToClassID mapping.
89 my $REG;
90 open REG, "<reg.out";
91 while (<REG>) {
92 chomp;
93 if (/contractID - (.*)$/) {
94 my $id = $1;
95 $cid = <REG>;
96 chomp($cid);
97 $cid =~ s/^.*\{(.*)\}.*$/$1/;
98 $contractid{$cid} = $id;
102 # print results
103 # ----------------------------------------------------------------------
105 # dlls loaded
106 print "dlls loaded [", scalar @dlls, "]\n";
107 print "----------------------------------------------------------------------\n";
108 for ($n = 0; $n < scalar @dlls; $n++) {
109 printf "%2d. %s\n", $n+1, $dlls[$n];
111 print "\n";
113 # Objects created
114 print "Object creations from CID [", sum(\%objs), "]\n";
115 print "----------------------------------------------------------------------\n";
116 foreach $cid (sort {$objs{$b} <=> $objs{$a} } keys %objs) {
117 last if (!$all && $objs{$cid} < 50);
118 printf "%5d. %s - %s\n", $objs{$cid}, $cid, getContractID($cid);
120 print "\n";
122 print "Object creations from ContractID [", sum(\%objs_contractid), "]\n";
123 print "----------------------------------------------------------------------\n";
124 foreach $cid (sort {$objs_contractid{$b} <=> $objs_contractid{$a} } keys %objs_contractid) {
125 last if (!$all && $objs_contractid{$cid} < 50);
126 printf "%5d. %s - %s\n", $objs_contractid{$cid}, $cid, getContractID($cid);
128 print "\n";
130 # FAILED Objects created
131 print "FAILED Objects creations [", sum(\%failedObjs), "]\n";
132 print "----------------------------------------------------------------------\n";
133 foreach $cid (sort {$failedObjs{$b} <=> $failedObjs{$a} } keys %failedObjs) {
134 last if (!$all && $failedObjs{$cid} < 50);
135 printf "%5d. %s - %s", $failedObjs{$cid}, $cid, getContractID($cid);
137 print "\n";
139 # ContractIDToClassID calls
140 print "ContractIDToClassID() calls [", sum(\%contractid_n),"]\n";
141 print "----------------------------------------------------------------------\n";
142 foreach $cid (sort {$contractid_n{$b} <=> $contractid_n{$a} } keys %contractid_n) {
143 last if (!$all && $contractid_n{$cid} < 50);
144 printf "%5d. %s - %s\n", $contractid_n{$cid}, $cid, getContractID($cid);
146 print "\n";
149 # FAILED ContractIDToClassID calls
150 print "FAILED ContractIDToClassID() calls [", sum(\%failedContractid_n), "]\n";
151 print "----------------------------------------------------------------------\n";
152 foreach $cid (sort {$failedContractid_n{$b} <=> $failedContractid_n{$a} } keys %failedContractid_n) {
153 last if (!$all && $failedContractid_n{$cid} < 50);
154 printf "%5d. %s\n", $failedContractid_n{$cid}, $cid;
156 print "\n";
159 # Subroutines
161 sub getContractID($) {
162 my $cid = shift;
163 my $ret = "";
164 $ret = $contractid{$cid} if (exists $contractid{$cid});
165 return $ret;
168 sub sum($) {
169 my $hash_ref = shift;
170 my %hash = %$hash_ref;
171 my $total = 0;
172 my $key;
173 foreach $key (keys %hash) {
174 $total += $hash{$key};
176 return $total;