aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/bootgraph.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bootgraph.pl')
-rw-r--r--scripts/bootgraph.pl138
1 files changed, 138 insertions, 0 deletions
diff --git a/scripts/bootgraph.pl b/scripts/bootgraph.pl
new file mode 100644
index 000000000000..d459b8bdef02
--- /dev/null
+++ b/scripts/bootgraph.pl
@@ -0,0 +1,138 @@
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
40my @rows;
41my %start, %end, %row;
42my $done = 0;
43my $rowcount = 0;
44my $maxtime = 0;
45my $count = 0;
46while (<>) {
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 $row{$func} = 1;
54 if ($line =~ /\@ ([0-9]+)/) {
55 my $pid = $1;
56 if (!defined($rows[$pid])) {
57 $rowcount = $rowcount + 1;
58 $rows[$pid] = $rowcount;
59 }
60 $row{$func} = $rows[$pid];
61 }
62 $count = $count + 1;
63 }
64
65 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z\_]+)\+.*returned/) {
66 if ($done == 0) {
67 $end{$2} = $1;
68 $maxtime = $1;
69 }
70 }
71 if ($line =~ /Write protecting the/) {
72 $done = 1;
73 }
74}
75
76if ($count == 0) {
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";
79 print "Usage: \n";
80 print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
81 exit;
82}
83
84print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
85print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
86
87my @styles;
88
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)";
101
102my $mult = 950.0 / $maxtime;
103my $threshold = 0.0500 / $maxtime;
104my $stylecounter = 0;
105while (($key,$value) = each %start) {
106 my $duration = $end{$key} - $start{$key};
107
108 if ($duration >= $threshold) {
109 my $s, $s2, $e, $y;
110 $s = $value * $mult;
111 $s2 = $s + 6;
112 $e = $end{$key} * $mult;
113 $w = $e - $s;
114
115 $y = $row{$key} * 150;
116 $y2 = $y + 4;
117
118 $style = $styles[$stylecounter];
119 $stylecounter = $stylecounter + 1;
120 if ($stylecounter > 11) {
121 $stylecounter = 0;
122 };
123
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";
126 }
127}
128
129
130# print the time line on top
131my $time = 0.0;
132while ($time < $maxtime) {
133 my $s2 = $time * $mult;
134 print "<text transform=\"translate($s2,89) rotate(90)\">$time</text>\n";
135 $time = $time + 0.1;
136}
137
138print "</svg>\n";