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
52 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) {
56 if ($1 < $firsttime) {
60 if ($line =~ /\@ ([0-9]+)/) {
66 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
72 if ($line =~ /Write protecting the/) {
75 if ($line =~ /Freeing unused kernel memory/) {
82 No data found in the dmesg. Make sure that 'printk.time=1' and
83 'initcall_debug' are passed on the kernel command line.
85 dmesg | perl scripts/bootgraph.pl > output.svg
90 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
91 print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
95 $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
96 $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
97 $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
98 $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
99 $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
100 $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
101 $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
102 $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
103 $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
104 $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
105 $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
106 $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
108 my $mult = 1950.0 / ($maxtime - $firsttime);
109 my $threshold2 = ($maxtime - $firsttime) / 120.0;
110 my $threshold = $threshold2/10;
111 my $stylecounter = 0;
114 my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
116 foreach my $key (@initcalls) {
117 my $duration = $end{$key} - $start{$key};
119 if ($duration >= $threshold) {
120 my ($s, $s2, $s3, $e, $w, $y, $y2, $style);
121 my $pid = $pids{$key};
123 if (!defined($rows{$pid})) {
124 $rows{$pid} = $rowscount;
125 $rowscount = $rowscount + 1;
127 $s = ($start{$key} - $firsttime) * $mult;
130 $e = ($end{$key} - $firsttime) * $mult;
133 $y = $rows{$pid} * 150;
136 $style = $styles[$stylecounter];
137 $stylecounter = $stylecounter + 1;
138 if ($stylecounter > 11) {
142 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
143 if ($duration >= $threshold2) {
144 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
146 print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n";
152 # print the time line on top
153 my $time = $firsttime;
154 my $step = ($maxtime - $firsttime) / 15;
155 while ($time < $maxtime) {
156 my $s3 = ($time - $firsttime) * $mult;
157 my $tm = int($time * 100) / 100.0;
158 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
159 $time = $time + $step;