tools/jprof/split-profile.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/jprof/split-profile.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +#!/usr/bin/perl
     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 +# split-profile.pl Documentation:
    1.11 +# 
    1.12 +# This script uses jprof's includes (-i) and excludes (-e) options to
    1.13 +# split profiles into segments.  It takes as input a single text file,
    1.14 +# and from that text file creates a series of jprof profiles in the
    1.15 +# directory in which it is run.  It expects the application binaries
    1.16 +# with which the profile was made, including jprof, and the jprof
    1.17 +# profile data, to be in a directory called "bin" that is a subdirectory
    1.18 +# of the current directory, and it will output the profiles into the
    1.19 +# current directory.
    1.20 +#
    1.21 +# The input file format looks like the following:
    1.22 +#
    1.23 +#   poll g_main_poll
    1.24 +#   GetRuleCascade CSSRuleProcessor::GetRuleCascade(nsPresContext *, nsIAtom *)
    1.25 +#   RuleProcessorData RuleProcessorData::RuleProcessorData(nsPresContext *, nsIContent *, nsRuleWalker *, nsCompatibility *)
    1.26 +#
    1.27 +# From this input file, the script will construct a profile called
    1.28 +# 00.html that contains the whole profile, a profile called 01-poll.html
    1.29 +# that includes only stacks with g_main_poll, a profile called
    1.30 +# 02-GetRuleCascade.html that includes only stacks that have
    1.31 +# GetRuleCascade and do not have g_main_poll, a profile called
    1.32 +# 03-RuleProcessorData.html that includes only stacks that have the
    1.33 +# RuleProcessorData constructor and do not have GetRuleCascade or
    1.34 +# g_main_poll, and a profile called 04.html that includes only stacks
    1.35 +# that do not have any of the three functions in them.
    1.36 +#
    1.37 +# This means that all of the segments of the profile, except 00.html,
    1.38 +# are mutually exclusive.  Thus clever ordering of the functions in the
    1.39 +# input file can lead to a logical splitting of the profile into
    1.40 +# segments.
    1.41 +
    1.42 +
    1.43 +use strict;
    1.44 +
    1.45 +my @names;
    1.46 +my @sigs;
    1.47 +
    1.48 +sub read_info($) {
    1.49 +    my ($fname) = @_;
    1.50 +
    1.51 +    open(INFO, "<$fname");
    1.52 +    my $i = 0;
    1.53 +    while (<INFO>) {
    1.54 +        chop;
    1.55 +        my $line = $_;
    1.56 +        my $idx = index($line, " ");
    1.57 +        my $name = substr($line, 0, $idx);
    1.58 +        my $sig = substr($line, $idx+1);
    1.59 +
    1.60 +        $names[$i] = $name;
    1.61 +        $sigs[$i] = $sig;
    1.62 +        ++$i;
    1.63 +    }
    1.64 +}
    1.65 +
    1.66 +sub run_profile($$) {
    1.67 +    my ($options, $outfile) = @_;
    1.68 +
    1.69 +    print  "./jprof$options mozilla-bin jprof-log > ../$outfile.html\n";
    1.70 +    system "./jprof$options mozilla-bin jprof-log > ../$outfile.html";
    1.71 +}
    1.72 +
    1.73 +sub run_profiles() {
    1.74 +    run_profile("", "00");
    1.75 +
    1.76 +    for (my $i = 0; $i <= $#names + 1; ++$i) {
    1.77 +        my $options = "";
    1.78 +        for (my $j = 0; $j < $i; ++$j) {
    1.79 +            $options .= " -e\"$sigs[$j]\"";
    1.80 +        }
    1.81 +        if ($i <= $#names) {
    1.82 +            $options .= " -i\"$sigs[$i]\"";
    1.83 +        }
    1.84 +        my $num;
    1.85 +        my $n = $i + 1;
    1.86 +        if ($n < 10) {
    1.87 +            $num = "0$n";
    1.88 +        } else {
    1.89 +            $num = "$n";
    1.90 +        }
    1.91 +        if ($i <= $#names) {
    1.92 +            run_profile($options, "$num-$names[$i]");
    1.93 +        } else {
    1.94 +            run_profile($options, "$num");
    1.95 +        }
    1.96 +    }
    1.97 +}
    1.98 +
    1.99 +($#ARGV == 0) || die "Usage: split-profile.pl <info-file>\n";
   1.100 +
   1.101 +read_info($ARGV[0]);
   1.102 +chdir "bin" || die "Can't change directory to bin.";
   1.103 +run_profiles();

mercurial