blob: d2c61efc216f4bd413dd271faa3aa62c736c6203 [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
Alan Jenkins2a813f82008-10-14 14:18:07 +010040use strict;
41
42my %start;
43my %end;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070044my $done = 0;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070045my $maxtime = 0;
Arjan van de Ven80a398a2008-09-14 15:30:52 -070046my $firsttime = 100;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070047my $count = 0;
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020048my %pids;
49
Arjan van de Venaa5d9152008-09-13 09:36:06 -070050while (<>) {
51 my $line = $_;
Arnaud Patard5c542362008-09-19 20:16:25 -070052 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) {
Arjan van de Venaa5d9152008-09-13 09:36:06 -070053 my $func = $2;
54 if ($done == 0) {
55 $start{$func} = $1;
Arjan van de Ven80a398a2008-09-14 15:30:52 -070056 if ($1 < $firsttime) {
57 $firsttime = $1;
58 }
Arjan van de Venaa5d9152008-09-13 09:36:06 -070059 }
Arjan van de Venaa5d9152008-09-13 09:36:06 -070060 if ($line =~ /\@ ([0-9]+)/) {
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +020061 $pids{$func} = $1;
Arjan van de Venaa5d9152008-09-13 09:36:06 -070062 }
63 $count = $count + 1;
64 }
65
Arnaud Patard5c542362008-09-19 20:16:25 -070066 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
Arjan van de Venaa5d9152008-09-13 09:36:06 -070067 if ($done == 0) {
68 $end{$2} = $1;
69 $maxtime = $1;
70 }
71 }
72 if ($line =~ /Write protecting the/) {
73 $done = 1;
74 }
Arjan van de Ven80a398a2008-09-14 15:30:52 -070075 if ($line =~ /Freeing unused kernel memory/) {
76 $done = 1;
77 }
Arjan van de Venaa5d9152008-09-13 09:36:06 -070078}
79
80if ($count == 0) {
Arnaud Patard5c542362008-09-19 20:16:25 -070081 print "No data found in the dmesg. Make sure that 'printk.time=1' and\n";
82 print "'initcall_debug' are passed on the kernel command line.\n\n";
Arjan van de Venaa5d9152008-09-13 09:36:06 -070083 print "Usage: \n";
84 print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
85 exit;
86}
87
88print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
89print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
90
91my @styles;
92
93$styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
94$styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
95$styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
96$styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
97$styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
98$styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
99$styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
100$styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
101$styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
102$styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
103$styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
104$styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
105
Arjan van de Ven80a398a2008-09-14 15:30:52 -0700106my $mult = 950.0 / ($maxtime - $firsttime);
107my $threshold = ($maxtime - $firsttime) / 60.0;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700108my $stylecounter = 0;
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +0200109my %rows;
110my $rowscount = 1;
Alan Jenkins06d1cd22008-10-14 14:19:15 +0100111my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
Alan Jenkins2a813f82008-10-14 14:18:07 +0100112my $key;
Alan Jenkins06d1cd22008-10-14 14:19:15 +0100113foreach $key (@initcalls) {
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700114 my $duration = $end{$key} - $start{$key};
115
116 if ($duration >= $threshold) {
Alan Jenkins2a813f82008-10-14 14:18:07 +0100117 my ($s, $s2, $e, $w, $y, $y2, $style);
118 my $pid = $pids{$key};
Frederic Weisbecker07d18902008-10-04 21:35:48 +0200119
120 if (!defined($rows{$pid})) {
121 $rows{$pid} = $rowscount;
122 $rowscount = $rowscount + 1;
123 }
Alan Jenkins06d1cd22008-10-14 14:19:15 +0100124 $s = ($start{$key} - $firsttime) * $mult;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700125 $s2 = $s + 6;
Arjan van de Ven80a398a2008-09-14 15:30:52 -0700126 $e = ($end{$key} - $firsttime) * $mult;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700127 $w = $e - $s;
128
Frederic Weisbeckerddc7a012008-10-04 21:35:48 +0200129 $y = $rows{$pid} * 150;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700130 $y2 = $y + 4;
131
132 $style = $styles[$stylecounter];
133 $stylecounter = $stylecounter + 1;
134 if ($stylecounter > 11) {
135 $stylecounter = 0;
136 };
137
138 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
139 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
140 }
141}
142
143
144# print the time line on top
Arjan van de Ven80a398a2008-09-14 15:30:52 -0700145my $time = $firsttime;
146my $step = ($maxtime - $firsttime) / 15;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700147while ($time < $maxtime) {
Alan Jenkins2a813f82008-10-14 14:18:07 +0100148 my $s3 = ($time - $firsttime) * $mult;
Arjan van de Ven80a398a2008-09-14 15:30:52 -0700149 my $tm = int($time * 100) / 100.0;
Alan Jenkins2a813f82008-10-14 14:18:07 +0100150 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
Arjan van de Ven80a398a2008-09-14 15:30:52 -0700151 $time = $time + $step;
Arjan van de Venaa5d9152008-09-13 09:36:06 -0700152}
153
154print "</svg>\n";