tools/jprof/split-profile.pl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/perl
michael@0 2 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5
michael@0 6
michael@0 7 # split-profile.pl Documentation:
michael@0 8 #
michael@0 9 # This script uses jprof's includes (-i) and excludes (-e) options to
michael@0 10 # split profiles into segments. It takes as input a single text file,
michael@0 11 # and from that text file creates a series of jprof profiles in the
michael@0 12 # directory in which it is run. It expects the application binaries
michael@0 13 # with which the profile was made, including jprof, and the jprof
michael@0 14 # profile data, to be in a directory called "bin" that is a subdirectory
michael@0 15 # of the current directory, and it will output the profiles into the
michael@0 16 # current directory.
michael@0 17 #
michael@0 18 # The input file format looks like the following:
michael@0 19 #
michael@0 20 # poll g_main_poll
michael@0 21 # GetRuleCascade CSSRuleProcessor::GetRuleCascade(nsPresContext *, nsIAtom *)
michael@0 22 # RuleProcessorData RuleProcessorData::RuleProcessorData(nsPresContext *, nsIContent *, nsRuleWalker *, nsCompatibility *)
michael@0 23 #
michael@0 24 # From this input file, the script will construct a profile called
michael@0 25 # 00.html that contains the whole profile, a profile called 01-poll.html
michael@0 26 # that includes only stacks with g_main_poll, a profile called
michael@0 27 # 02-GetRuleCascade.html that includes only stacks that have
michael@0 28 # GetRuleCascade and do not have g_main_poll, a profile called
michael@0 29 # 03-RuleProcessorData.html that includes only stacks that have the
michael@0 30 # RuleProcessorData constructor and do not have GetRuleCascade or
michael@0 31 # g_main_poll, and a profile called 04.html that includes only stacks
michael@0 32 # that do not have any of the three functions in them.
michael@0 33 #
michael@0 34 # This means that all of the segments of the profile, except 00.html,
michael@0 35 # are mutually exclusive. Thus clever ordering of the functions in the
michael@0 36 # input file can lead to a logical splitting of the profile into
michael@0 37 # segments.
michael@0 38
michael@0 39
michael@0 40 use strict;
michael@0 41
michael@0 42 my @names;
michael@0 43 my @sigs;
michael@0 44
michael@0 45 sub read_info($) {
michael@0 46 my ($fname) = @_;
michael@0 47
michael@0 48 open(INFO, "<$fname");
michael@0 49 my $i = 0;
michael@0 50 while (<INFO>) {
michael@0 51 chop;
michael@0 52 my $line = $_;
michael@0 53 my $idx = index($line, " ");
michael@0 54 my $name = substr($line, 0, $idx);
michael@0 55 my $sig = substr($line, $idx+1);
michael@0 56
michael@0 57 $names[$i] = $name;
michael@0 58 $sigs[$i] = $sig;
michael@0 59 ++$i;
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 sub run_profile($$) {
michael@0 64 my ($options, $outfile) = @_;
michael@0 65
michael@0 66 print "./jprof$options mozilla-bin jprof-log > ../$outfile.html\n";
michael@0 67 system "./jprof$options mozilla-bin jprof-log > ../$outfile.html";
michael@0 68 }
michael@0 69
michael@0 70 sub run_profiles() {
michael@0 71 run_profile("", "00");
michael@0 72
michael@0 73 for (my $i = 0; $i <= $#names + 1; ++$i) {
michael@0 74 my $options = "";
michael@0 75 for (my $j = 0; $j < $i; ++$j) {
michael@0 76 $options .= " -e\"$sigs[$j]\"";
michael@0 77 }
michael@0 78 if ($i <= $#names) {
michael@0 79 $options .= " -i\"$sigs[$i]\"";
michael@0 80 }
michael@0 81 my $num;
michael@0 82 my $n = $i + 1;
michael@0 83 if ($n < 10) {
michael@0 84 $num = "0$n";
michael@0 85 } else {
michael@0 86 $num = "$n";
michael@0 87 }
michael@0 88 if ($i <= $#names) {
michael@0 89 run_profile($options, "$num-$names[$i]");
michael@0 90 } else {
michael@0 91 run_profile($options, "$num");
michael@0 92 }
michael@0 93 }
michael@0 94 }
michael@0 95
michael@0 96 ($#ARGV == 0) || die "Usage: split-profile.pl <info-file>\n";
michael@0 97
michael@0 98 read_info($ARGV[0]);
michael@0 99 chdir "bin" || die "Can't change directory to bin.";
michael@0 100 run_profiles();

mercurial