]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - scripts/bootgraph.pl
tracing/fastboot: fix initcalls disposition in bootgraph.pl
[linux-2.6-omap-h63xx.git] / scripts / bootgraph.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008, Intel Corporation
4 #
5 # This file is part of the Linux kernel
6 #
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.
10 #
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
14 # for more details.
15 #
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
21 #
22 # Authors:
23 #       Arjan van de Ven <arjan@linux.intel.com>
24
25
26 #
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.
30 #
31 #
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.
35 #
36 # usage:
37 #       dmesg | perl scripts/bootgraph.pl > output.svg
38 #
39
40 my %start, %end;
41 my $done = 0;
42 my $maxtime = 0;
43 my $count = 0;
44 my %pids;
45
46 while (<>) {
47         my $line = $_;
48         if ($line =~ /([0-9\.]+)\] calling  ([a-zA-Z\_]+)\+/) {
49                 my $func = $2;
50                 if ($done == 0) {
51                         $start{$func} = $1;
52                 }
53                 if ($line =~ /\@ ([0-9]+)/) {
54                         $pids{$func} = $1;
55                 }
56                 $count = $count + 1;
57         }
58
59         if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z\_]+)\+.*returned/) {
60                 if ($done == 0) {
61                         $end{$2} = $1;
62                         $maxtime = $1;
63                 }
64         }
65         if ($line =~ /Write protecting the/) {
66                 $done = 1;
67         }
68 }
69
70 if ($count == 0) {
71         print "No data found in the dmesg. Make sure CONFIG_PRINTK_TIME is enabled and\n";
72         print "that initcall_debug is passed on the kernel command line.\n\n";
73         print "Usage: \n";
74         print "      dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
75         exit;
76 }
77
78 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
79 print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
80
81 my @styles;
82
83 $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
84 $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
85 $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
86 $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
87 $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
88 $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
89 $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
90 $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
91 $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
92 $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
93 $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
94 $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
95
96 my $mult = 950.0 / $maxtime;
97 my $threshold = 0.0500 / $maxtime;
98 my $stylecounter = 0;
99 my %rows;
100 my $rowscount = 1;
101 while (($key,$value) = each %start) {
102         my $duration = $end{$key} - $start{$key};
103
104         if ($duration >= $threshold) {
105                 my $s, $s2, $e, $y;
106                 $pid = $pids{$key};
107
108                 if (!defined($rows{$pid})) {
109                         $rows{$pid} = $rowscount;
110                         $rowscount = $rowscount + 1;
111                 }
112                 $s = ($value - $firsttime) * $mult;
113                 $s2 = $s + 6;
114                 $e = $end{$key} * $mult;
115                 $w = $e - $s;
116
117                 $y = $rows{$pid} * 150;
118                 $y2 = $y + 4;
119
120                 $style = $styles[$stylecounter];
121                 $stylecounter = $stylecounter + 1;
122                 if ($stylecounter > 11) {
123                         $stylecounter = 0;
124                 };
125
126                 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
127                 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
128         }
129 }
130
131
132 # print the time line on top
133 my $time = 0.0;
134 while ($time < $maxtime) {
135         my $s2 = $time * $mult;
136         print "<text transform=\"translate($s2,89) rotate(90)\">$time</text>\n";
137         $time = $time + 0.1;
138 }
139
140 print "</svg>\n";