NOHZ: unify the nohz function calls in irq_enter()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / scripts / bootgraph.pl
blob2243353fe55dc00058cc9b96613a7a092e26226b
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 my @rows;
41 my %start, %end, %row;
42 my $done = 0;
43 my $rowcount = 0;
44 my $maxtime = 0;
45 my $firsttime = 100;
46 my $count = 0;
47 while (<>) {
48 my $line = $_;
49 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) {
50 my $func = $2;
51 if ($done == 0) {
52 $start{$func} = $1;
53 if ($1 < $firsttime) {
54 $firsttime = $1;
57 $row{$func} = 1;
58 if ($line =~ /\@ ([0-9]+)/) {
59 my $pid = $1;
60 if (!defined($rows[$pid])) {
61 $rowcount = $rowcount + 1;
62 $rows[$pid] = $rowcount;
64 $row{$func} = $rows[$pid];
66 $count = $count + 1;
69 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
70 if ($done == 0) {
71 $end{$2} = $1;
72 $maxtime = $1;
75 if ($line =~ /Write protecting the/) {
76 $done = 1;
78 if ($line =~ /Freeing unused kernel memory/) {
79 $done = 1;
83 if ($count == 0) {
84 print "No data found in the dmesg. Make sure that 'printk.time=1' and\n";
85 print "'initcall_debug' are passed on the kernel command line.\n\n";
86 print "Usage: \n";
87 print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
88 exit;
91 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
92 print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
94 my @styles;
96 $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
97 $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
98 $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
99 $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
100 $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
101 $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
102 $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
103 $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
104 $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
105 $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
106 $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
107 $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
109 my $mult = 950.0 / ($maxtime - $firsttime);
110 my $threshold = ($maxtime - $firsttime) / 60.0;
111 my $stylecounter = 0;
112 while (($key,$value) = each %start) {
113 my $duration = $end{$key} - $start{$key};
115 if ($duration >= $threshold) {
116 my $s, $s2, $e, $y;
117 $s = ($value - $firsttime) * $mult;
118 $s2 = $s + 6;
119 $e = ($end{$key} - $firsttime) * $mult;
120 $w = $e - $s;
122 $y = $row{$key} * 150;
123 $y2 = $y + 4;
125 $style = $styles[$stylecounter];
126 $stylecounter = $stylecounter + 1;
127 if ($stylecounter > 11) {
128 $stylecounter = 0;
131 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
132 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
137 # print the time line on top
138 my $time = $firsttime;
139 my $step = ($maxtime - $firsttime) / 15;
140 while ($time < $maxtime) {
141 my $s2 = ($time - $firsttime) * $mult;
142 my $tm = int($time * 100) / 100.0;
143 print "<text transform=\"translate($s2,89) rotate(90)\">$tm</text>\n";
144 $time = $time + $step;
147 print "</svg>\n";