# Perl script to analyze the xpcom output file
#
# To create xpcom output file :
#
# setenv NSPR_LOG_MODULES nsComponentManager:5
# setenv NSPR_LOG_FILE xpcom.out
# ./mozilla
#
# Also to try to convert CID -> contractID this program looks for
# a file reg.out in the current directory. To generate this file
#
# $ regExport > reg.out
#
# Usage: analyze-xpcom-log.pl < xpcom.out
# [does better if ./reg.out is available]
#
# Suresh Duddi <dpsuresh@netscape.net>
use strict;
# forward declarations
sub getContractID($);
sub sum($);
# Configuration parameters
# Print all ?
my $all = 0;
# hash of cid -> contractid
my %contractid;
my %contractid_n;
my %failedContractid_n;
# count of instances of objects created
# dlls loaded
my @dlls;
# temporaries
while (<>) {
chomp;
# dlls loaded
if (/loading \"(.*)\"/) {
push @dlls, $1;
next;
}
# FAILED ContractIDToClassID
if (/ContractIDToClassID\((.*)\).*\[FAILED\]/) {
$failedContractid_n{$1}++;
next;
}
# ContractIDToClassID
if (/ContractIDToClassID\((.*)\).*\{(.*)\}/) {
$contractid_n{$2}++;
next;
}
# CreateInstance()
if (/CreateInstance\(\{(.*)\}\) succeeded/) {
$objs{$1}++;
next;
}
# CreateInstanceByContractID()
if (/CreateInstanceByContractID\((.*)\) succeeded/) {
$objs_contractid{$1}++;
next;
}
# FAILED CreateInstance()
if (/CreateInstance\(\{(.*)\}\) FAILED/) {
$failedObjs{$1}++;
next;
}
}
# if there is a file named reg.out in the current dir
# then use that to fill in the ContractIDToClassID mapping.
my $REG;
open REG, "<reg.out";
while (<REG>) {
chomp;
if (/contractID - (.*)$/) {
my $id = $1;
chomp($cid);
$cid =~ s/^.*\{(.*)\}.*$/$1/;
}
}
# print results
# ----------------------------------------------------------------------
# dlls loaded
print "----------------------------------------------------------------------\n";
for ($n = 0; $n < scalar @dlls; $n++) {
}
print "\n";
# Objects created
print "----------------------------------------------------------------------\n";
}
print "\n";
print "----------------------------------------------------------------------\n";
}
print "\n";
# FAILED Objects created
print "----------------------------------------------------------------------\n";
}
print "\n";
# ContractIDToClassID calls
print "----------------------------------------------------------------------\n";
}
print "\n";
# FAILED ContractIDToClassID calls
print "----------------------------------------------------------------------\n";
foreach $cid (sort {$failedContractid_n{$b} <=> $failedContractid_n{$a} } keys %failedContractid_n) {
}
print "\n";
# Subroutines
sub getContractID($) {
my $cid = shift;
my $ret = "";
return $ret;
}
sub sum($) {
my $hash_ref = shift;
my $total = 0;
my $key;
}
return $total;
}