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