Blackfin arch: move the PORT registers down
[linux-2.6/mini2440.git] / scripts / bootgraph.pl
blobf0af9aa9b243bcb1892ede765a44b2b225921046
1 #!/usr/bin/perl
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
14 # for more details.
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
22 # Authors:
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.
36 # usage:
37 # dmesg | perl scripts/bootgraph.pl > output.svg
40 use strict;
42 my %start;
43 my %end;
44 my $done = 0;
45 my $maxtime = 0;
46 my $firsttime = 100;
47 my $count = 0;
48 my %pids;
50 while (<>) {
51 my $line = $_;
52 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) {
53 my $func = $2;
54 if ($done == 0) {
55 $start{$func} = $1;
56 if ($1 < $firsttime) {
57 $firsttime = $1;
60 if ($line =~ /\@ ([0-9]+)/) {
61 $pids{$func} = $1;
63 $count = $count + 1;
66 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
67 if ($done == 0) {
68 $end{$2} = $1;
69 $maxtime = $1;
72 if ($line =~ /Write protecting the/) {
73 $done = 1;
75 if ($line =~ /Freeing unused kernel memory/) {
76 $done = 1;
80 if ($count == 0) {
81 print STDERR <<END;
82 No data found in the dmesg. Make sure that 'printk.time=1' and
83 'initcall_debug' are passed on the kernel command line.
84 Usage:
85 dmesg | perl scripts/bootgraph.pl > output.svg
86 END
87 exit 1;
90 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
91 print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
93 my @styles;
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 = 950.0 / ($maxtime - $firsttime);
109 my $threshold = ($maxtime - $firsttime) / 60.0;
110 my $stylecounter = 0;
111 my %rows;
112 my $rowscount = 1;
113 my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
115 foreach my $key (@initcalls) {
116 my $duration = $end{$key} - $start{$key};
118 if ($duration >= $threshold) {
119 my ($s, $s2, $e, $w, $y, $y2, $style);
120 my $pid = $pids{$key};
122 if (!defined($rows{$pid})) {
123 $rows{$pid} = $rowscount;
124 $rowscount = $rowscount + 1;
126 $s = ($start{$key} - $firsttime) * $mult;
127 $s2 = $s + 6;
128 $e = ($end{$key} - $firsttime) * $mult;
129 $w = $e - $s;
131 $y = $rows{$pid} * 150;
132 $y2 = $y + 4;
134 $style = $styles[$stylecounter];
135 $stylecounter = $stylecounter + 1;
136 if ($stylecounter > 11) {
137 $stylecounter = 0;
140 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
141 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
146 # print the time line on top
147 my $time = $firsttime;
148 my $step = ($maxtime - $firsttime) / 15;
149 while ($time < $maxtime) {
150 my $s3 = ($time - $firsttime) * $mult;
151 my $tm = int($time * 100) / 100.0;
152 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
153 $time = $time + $step;
156 print "</svg>\n";