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
41 my %start, %end, %row;
48 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z\_]+)\+/) {
54 if ($line =~ /\@ ([0-9]+)/) {
56 if (!defined($rows[$pid])) {
57 $rowcount = $rowcount + 1;
58 $rows[$pid] = $rowcount;
60 $row{$func} = $rows[$pid];
65 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z\_]+)\+.*returned/) {
71 if ($line =~ /Write protecting the/) {
77 print "No data found in the dmesg. Make sure CONFIG_PRINTK_TIME is enabled and\n";
78 print "that initcall_debug is passed on the kernel command line.\n\n";
80 print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
84 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
85 print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
89 $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
90 $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
91 $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
92 $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
93 $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
94 $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
95 $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
96 $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
97 $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
98 $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
99 $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
100 $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
102 my $mult = 950.0 / $maxtime;
103 my $threshold = 0.0500 / $maxtime;
104 my $stylecounter = 0;
105 while (($key,$value) = each %start) {
106 my $duration = $end{$key} - $start{$key};
108 if ($duration >= $threshold) {
112 $e = $end{$key} * $mult;
115 $y = $row{$key} * 150;
118 $style = $styles[$stylecounter];
119 $stylecounter = $stylecounter + 1;
120 if ($stylecounter > 11) {
124 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
125 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
130 # print the time line on top
132 while ($time < $maxtime) {
133 my $s2 = $time * $mult;
134 print "<text transform=\"translate($s2,89) rotate(90)\">$time</text>\n";