3 # Copyright 2008, Intel Corporation
5 # This file is part of the Linux kernel
7 # This program file is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program in a file named COPYING; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301 USA
23 # Arjan van de Ven <arjan@linux.intel.com>
27 # This script turns a dmesg output into a SVG graphic that shows which
28 # functions take how much time. You can view SVG graphics with various
29 # programs, including Inkscape, The Gimp and Firefox.
32 # For this script to work, the kernel needs to be compiled with the
33 # CONFIG_PRINTK_TIME configuration option enabled, and with
34 # "initcall_debug" passed on the kernel command line.
37 # dmesg | perl scripts/bootgraph.pl > output.svg
47 1) dmesg | perl scripts/bootgraph.pl [OPTION] > output.svg
48 2) perl scripts/bootgraph.pl -h
51 -header Insert kernel version and date
72 my $firsttime = 99999;
84 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_\.]+)\+/) {
89 if ($1 < $firsttime) {
93 if ($line =~ /\@ ([0-9]+)/) {
99 if ($line =~ /([0-9\.]+)\] async_waiting @ ([0-9]+)/) {
102 if (!defined($pidctr{$pid})) {
103 $func = "wait_" . $pid . "_1";
106 $pidctr{$pid} = $pidctr{$pid} + 1;
107 $func = "wait_" . $pid . "_" . $pidctr{$pid};
112 if ($1 < $firsttime) {
120 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_\.]+)\+.*returned/) {
127 if ($line =~ /([0-9\.]+)\] async_continuing @ ([0-9]+)/) {
129 my $func = "wait_" . $pid . "_" . $pidctr{$pid};
133 if ($line =~ /Write protecting the/) {
136 if ($line =~ /Freeing unused kernel memory/) {
143 No data found in the dmesg. Make sure that 'printk.time=1' and
144 'initcall_debug' are passed on the kernel command line.
150 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
151 print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
155 my $version = `uname -a`;
157 print "<text transform=\"translate($xheader,$yheader)\">Kernel version: $version</text>\n";
158 $cyheader = $yheader+$headerstep;
159 print "<text transform=\"translate($xheader,$cyheader)\">Date: $date</text>\n";
164 $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
165 $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
166 $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
167 $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
168 $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
169 $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
170 $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
171 $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
172 $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
173 $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
174 $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
175 $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
177 my $style_wait = "fill:rgb(128,128,128);fill-opacity:0.5;stroke-width:0;stroke:rgb(0,0,0)";
179 my $mult = 1950.0 / ($maxtime - $firsttime);
180 my $threshold2 = ($maxtime - $firsttime) / 120.0;
181 my $threshold = $threshold2/10;
182 my $stylecounter = 0;
185 my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
187 foreach my $key (@initcalls) {
188 my $duration = $end{$key} - $start{$key};
190 if ($duration >= $threshold) {
191 my ($s, $s2, $s3, $e, $w, $y, $y2, $style);
192 my $pid = $pids{$key};
194 if (!defined($rows{$pid})) {
195 $rows{$pid} = $rowscount;
196 $rowscount = $rowscount + 1;
198 $s = ($start{$key} - $firsttime) * $mult;
201 $e = ($end{$key} - $firsttime) * $mult;
204 $y = $rows{$pid} * 150;
207 $style = $styles[$stylecounter];
208 $stylecounter = $stylecounter + 1;
209 if ($stylecounter > 11) {
213 if ($type{$key} == 1) {
215 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"115\" style=\"$style_wait\"/>\n";
217 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
218 if ($duration >= $threshold2) {
219 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
221 print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n";
228 # print the time line on top
229 my $time = $firsttime;
230 my $step = ($maxtime - $firsttime) / 15;
231 while ($time < $maxtime) {
232 my $s3 = ($time - $firsttime) * $mult;
233 my $tm = int($time * 100) / 100.0;
234 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
235 $time = $time + $step;