blob: c34b359c34a3ab7579d31fa916d11ebed531fef5 [file] [log] [blame]
Arjan van de Venaa5d9152008-09-13 09:36:06 -07001#!/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
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020040my %start, %end;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070041my $done = 0;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070042my $maxtime = 0;
43my $count = 0;
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020044my %pids;
45
Arjan van de Venaa5d9152008-09-13 09:36:06 -070046while (<>) {
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 }
Arjan van de Venaa5d9152008-09-13 09:36:06 -070053 if ($line =~ /\@ ([0-9]+)/) {
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020054 $pids{$func} = $1;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070055 }
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
70if ($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
78print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
79print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
80
81my @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
96my $mult = 950.0 / $maxtime;
97my $threshold = 0.0500 / $maxtime;
98my $stylecounter = 0;
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020099my %rows;
100my $rowscount = 1;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700101while (($key,$value) = each %start) {
102 my $duration = $end{$key} - $start{$key};
103
104 if ($duration >= $threshold) {
105 my $s, $s2, $e, $y;
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +0200106 $pid = $pids{$key};
107
108 if (!defined($rows{$pid})) {
109 $rows{$pid} = $rowscount;
110 $rowscount = $rowscount + 1;
111 }
112 $s = ($value - $firsttime) * $mult;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700113 $s2 = $s + 6;
114 $e = $end{$key} * $mult;
115 $w = $e - $s;
116
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +0200117 $y = $rows{$pid} * 150;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700118 $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
133my $time = 0.0;
134while ($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
140print "</svg>\n";