xpcom/tools/analyze-xpcom-log.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/tools/analyze-xpcom-log.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     1.4 +#!/usr/local/bin/perl -w
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +
    1.10 +# Perl script to analyze the xpcom output file
    1.11 +#
    1.12 +# To create xpcom output file :
    1.13 +#
    1.14 +# setenv NSPR_LOG_MODULES nsComponentManager:5
    1.15 +# setenv NSPR_LOG_FILE xpcom.out
    1.16 +# ./mozilla
    1.17 +#
    1.18 +# Also to try to convert CID -> contractID this program looks for
    1.19 +# a file reg.out in the current directory. To generate this file
    1.20 +#
    1.21 +# $ regExport > reg.out
    1.22 +#
    1.23 +# Usage: analyze-xpcom-log.pl < xpcom.out
    1.24 +# [does better if ./reg.out is available]
    1.25 +#
    1.26 +# Suresh Duddi <dpsuresh@netscape.net>
    1.27 +
    1.28 +
    1.29 +use strict;
    1.30 +
    1.31 +# forward declarations
    1.32 +sub getContractID($);
    1.33 +sub sum($);
    1.34 +
    1.35 +# Configuration parameters
    1.36 +# Print all ?
    1.37 +my $all = 0;
    1.38 +
    1.39 +# hash of cid -> contractid
    1.40 +my %contractid;
    1.41 +my %contractid_n;
    1.42 +my %failedContractid_n;
    1.43 +
    1.44 +# count of instances of objects created
    1.45 +my (%objs, %objs_contractid, %failedObjs) = ();
    1.46 +
    1.47 +# dlls loaded
    1.48 +my @dlls;
    1.49 +
    1.50 +# temporaries
    1.51 +my ($cid, $n, $str);
    1.52 +
    1.53 +while (<>) {
    1.54 +    chomp;
    1.55 +
    1.56 +    # dlls loaded
    1.57 +    if (/loading \"(.*)\"/) {
    1.58 +        push @dlls, $1;
    1.59 +        next;
    1.60 +    }
    1.61 +
    1.62 +    # FAILED ContractIDToClassID
    1.63 +    if (/ContractIDToClassID\((.*)\).*\[FAILED\]/) {
    1.64 +        $failedContractid_n{$1}++;
    1.65 +        next;
    1.66 +    }
    1.67 +
    1.68 +    # ContractIDToClassID
    1.69 +    if (/ContractIDToClassID\((.*)\).*\{(.*)\}/) {
    1.70 +        $contractid{$2} = $1;
    1.71 +        $contractid_n{$2}++;
    1.72 +        next;
    1.73 +    }
    1.74 +
    1.75 +    # CreateInstance()
    1.76 +    if (/CreateInstance\(\{(.*)\}\) succeeded/) {
    1.77 +        $objs{$1}++;
    1.78 +        next;
    1.79 +    }
    1.80 +
    1.81 +    # CreateInstanceByContractID()
    1.82 +    if (/CreateInstanceByContractID\((.*)\) succeeded/) {
    1.83 +        $objs_contractid{$1}++;
    1.84 +        next;
    1.85 +    }
    1.86 +
    1.87 +    # FAILED CreateInstance()
    1.88 +    if (/CreateInstance\(\{(.*)\}\) FAILED/) {
    1.89 +        $failedObjs{$1}++;
    1.90 +        next;
    1.91 +    }
    1.92 +}
    1.93 +
    1.94 +# if there is a file named reg.out in the current dir
    1.95 +# then use that to fill in the ContractIDToClassID mapping.
    1.96 +my $REG;
    1.97 +open REG, "<reg.out";
    1.98 +while (<REG>) {
    1.99 +    chomp;
   1.100 +    if (/contractID -  (.*)$/) {
   1.101 +        my $id = $1;
   1.102 +        $cid = <REG>;
   1.103 +        chomp($cid);
   1.104 +        $cid =~ s/^.*\{(.*)\}.*$/$1/;
   1.105 +        $contractid{$cid} = $id;
   1.106 +    }
   1.107 +}
   1.108 +
   1.109 +# print results
   1.110 +# ----------------------------------------------------------------------
   1.111 +
   1.112 +# dlls loaded
   1.113 +print "dlls loaded [", scalar @dlls, "]\n";
   1.114 +print "----------------------------------------------------------------------\n";
   1.115 +for ($n = 0; $n < scalar @dlls; $n++) {
   1.116 +    printf "%2d. %s\n", $n+1, $dlls[$n];
   1.117 +}
   1.118 +print "\n";
   1.119 +
   1.120 +# Objects created
   1.121 +print "Object creations from CID [", sum(\%objs), "]\n";
   1.122 +print "----------------------------------------------------------------------\n";
   1.123 +foreach $cid (sort {$objs{$b} <=> $objs{$a} } keys %objs) {
   1.124 +    last if (!$all && $objs{$cid} < 50);
   1.125 +    printf "%5d. %s - %s\n", $objs{$cid}, $cid, getContractID($cid);
   1.126 +}
   1.127 +print "\n";
   1.128 +
   1.129 +print "Object creations from ContractID [", sum(\%objs_contractid), "]\n";
   1.130 +print "----------------------------------------------------------------------\n";
   1.131 +foreach $cid (sort {$objs_contractid{$b} <=> $objs_contractid{$a} } keys %objs_contractid) {
   1.132 +    last if (!$all && $objs_contractid{$cid} < 50);
   1.133 +    printf "%5d. %s - %s\n", $objs_contractid{$cid}, $cid, getContractID($cid);
   1.134 +}
   1.135 +print "\n";
   1.136 +
   1.137 +# FAILED Objects created
   1.138 +print "FAILED Objects creations [", sum(\%failedObjs), "]\n";
   1.139 +print "----------------------------------------------------------------------\n";
   1.140 +foreach $cid (sort {$failedObjs{$b} <=> $failedObjs{$a} } keys %failedObjs) {
   1.141 +    last if (!$all && $failedObjs{$cid} < 50);
   1.142 +    printf "%5d. %s - %s", $failedObjs{$cid}, $cid, getContractID($cid);
   1.143 +}
   1.144 +print "\n";
   1.145 +
   1.146 +# ContractIDToClassID calls
   1.147 +print "ContractIDToClassID() calls [", sum(\%contractid_n),"]\n";
   1.148 +print "----------------------------------------------------------------------\n";
   1.149 +foreach $cid (sort {$contractid_n{$b} <=> $contractid_n{$a} } keys %contractid_n) {
   1.150 +    last if (!$all && $contractid_n{$cid} < 50);
   1.151 +    printf "%5d. %s - %s\n", $contractid_n{$cid}, $cid, getContractID($cid);
   1.152 +}
   1.153 +print "\n";
   1.154 +
   1.155 +
   1.156 +# FAILED ContractIDToClassID calls
   1.157 +print "FAILED ContractIDToClassID() calls [", sum(\%failedContractid_n), "]\n";
   1.158 +print "----------------------------------------------------------------------\n";
   1.159 +foreach $cid (sort {$failedContractid_n{$b} <=> $failedContractid_n{$a} } keys %failedContractid_n) {
   1.160 +    last if (!$all && $failedContractid_n{$cid} < 50);
   1.161 +    printf "%5d. %s\n", $failedContractid_n{$cid}, $cid;
   1.162 +}
   1.163 +print "\n";
   1.164 +
   1.165 +
   1.166 +# Subroutines
   1.167 +
   1.168 +sub getContractID($) {
   1.169 +    my $cid = shift;
   1.170 +    my $ret = "";
   1.171 +    $ret = $contractid{$cid} if (exists $contractid{$cid});
   1.172 +    return $ret;
   1.173 +}
   1.174 +
   1.175 +sub sum($) {
   1.176 +    my $hash_ref = shift;
   1.177 +    my %hash = %$hash_ref;
   1.178 +    my $total = 0;
   1.179 +    my $key;
   1.180 +    foreach $key (keys %hash) {
   1.181 +        $total += $hash{$key};
   1.182 +    }
   1.183 +    return $total;
   1.184 +}

mercurial