michael@0: #!/usr/bin/perl michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: michael@0: # split-profile.pl Documentation: michael@0: # michael@0: # This script uses jprof's includes (-i) and excludes (-e) options to michael@0: # split profiles into segments. It takes as input a single text file, michael@0: # and from that text file creates a series of jprof profiles in the michael@0: # directory in which it is run. It expects the application binaries michael@0: # with which the profile was made, including jprof, and the jprof michael@0: # profile data, to be in a directory called "bin" that is a subdirectory michael@0: # of the current directory, and it will output the profiles into the michael@0: # current directory. michael@0: # michael@0: # The input file format looks like the following: michael@0: # michael@0: # poll g_main_poll michael@0: # GetRuleCascade CSSRuleProcessor::GetRuleCascade(nsPresContext *, nsIAtom *) michael@0: # RuleProcessorData RuleProcessorData::RuleProcessorData(nsPresContext *, nsIContent *, nsRuleWalker *, nsCompatibility *) michael@0: # michael@0: # From this input file, the script will construct a profile called michael@0: # 00.html that contains the whole profile, a profile called 01-poll.html michael@0: # that includes only stacks with g_main_poll, a profile called michael@0: # 02-GetRuleCascade.html that includes only stacks that have michael@0: # GetRuleCascade and do not have g_main_poll, a profile called michael@0: # 03-RuleProcessorData.html that includes only stacks that have the michael@0: # RuleProcessorData constructor and do not have GetRuleCascade or michael@0: # g_main_poll, and a profile called 04.html that includes only stacks michael@0: # that do not have any of the three functions in them. michael@0: # michael@0: # This means that all of the segments of the profile, except 00.html, michael@0: # are mutually exclusive. Thus clever ordering of the functions in the michael@0: # input file can lead to a logical splitting of the profile into michael@0: # segments. michael@0: michael@0: michael@0: use strict; michael@0: michael@0: my @names; michael@0: my @sigs; michael@0: michael@0: sub read_info($) { michael@0: my ($fname) = @_; michael@0: michael@0: open(INFO, "<$fname"); michael@0: my $i = 0; michael@0: while () { michael@0: chop; michael@0: my $line = $_; michael@0: my $idx = index($line, " "); michael@0: my $name = substr($line, 0, $idx); michael@0: my $sig = substr($line, $idx+1); michael@0: michael@0: $names[$i] = $name; michael@0: $sigs[$i] = $sig; michael@0: ++$i; michael@0: } michael@0: } michael@0: michael@0: sub run_profile($$) { michael@0: my ($options, $outfile) = @_; michael@0: michael@0: print "./jprof$options mozilla-bin jprof-log > ../$outfile.html\n"; michael@0: system "./jprof$options mozilla-bin jprof-log > ../$outfile.html"; michael@0: } michael@0: michael@0: sub run_profiles() { michael@0: run_profile("", "00"); michael@0: michael@0: for (my $i = 0; $i <= $#names + 1; ++$i) { michael@0: my $options = ""; michael@0: for (my $j = 0; $j < $i; ++$j) { michael@0: $options .= " -e\"$sigs[$j]\""; michael@0: } michael@0: if ($i <= $#names) { michael@0: $options .= " -i\"$sigs[$i]\""; michael@0: } michael@0: my $num; michael@0: my $n = $i + 1; michael@0: if ($n < 10) { michael@0: $num = "0$n"; michael@0: } else { michael@0: $num = "$n"; michael@0: } michael@0: if ($i <= $#names) { michael@0: run_profile($options, "$num-$names[$i]"); michael@0: } else { michael@0: run_profile($options, "$num"); michael@0: } michael@0: } michael@0: } michael@0: michael@0: ($#ARGV == 0) || die "Usage: split-profile.pl \n"; michael@0: michael@0: read_info($ARGV[0]); michael@0: chdir "bin" || die "Can't change directory to bin."; michael@0: run_profiles();