Loading...
1#!/usr/bin/env perl
2# SPDX-License-Identifier: GPL-2.0-only
3
4# Copyright 2008, Intel Corporation
5#
6# This file is part of the Linux kernel
7#
8# Authors:
9# Arjan van de Ven <arjan@linux.intel.com>
10
11
12#
13# This script turns a dmesg output into a SVG graphic that shows which
14# functions take how much time. You can view SVG graphics with various
15# programs, including Inkscape, The Gimp and Firefox.
16#
17#
18# For this script to work, the kernel needs to be compiled with the
19# CONFIG_PRINTK_TIME configuration option enabled, and with
20# "initcall_debug" passed on the kernel command line.
21#
22# usage:
23# dmesg | perl scripts/bootgraph.pl > output.svg
24#
25
26use strict;
27use Getopt::Long;
28my $header = 0;
29
30sub help {
31 my $text = << "EOM";
32Usage:
331) dmesg | perl scripts/bootgraph.pl [OPTION] > output.svg
342) perl scripts/bootgraph.pl -h
35
36Options:
37 -header Insert kernel version and date
38EOM
39 my $std=shift;
40 if ($std == 1) {
41 print STDERR $text;
42 } else {
43 print $text;
44 }
45 exit;
46}
47
48GetOptions(
49 'h|help' =>\&help,
50 'header' =>\$header
51);
52
53my %start;
54my %end;
55my %type;
56my $done = 0;
57my $maxtime = 0;
58my $firsttime = 99999;
59my $count = 0;
60my %pids;
61my %pidctr;
62
63my $headerstep = 20;
64my $xheader = 15;
65my $yheader = 25;
66my $cyheader = 0;
67
68while (<>) {
69 my $line = $_;
70 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_\.]+)\+/) {
71 my $func = $2;
72 if ($done == 0) {
73 $start{$func} = $1;
74 $type{$func} = 0;
75 if ($1 < $firsttime) {
76 $firsttime = $1;
77 }
78 }
79 if ($line =~ /\@ ([0-9]+)/) {
80 $pids{$func} = $1;
81 }
82 $count = $count + 1;
83 }
84
85 if ($line =~ /([0-9\.]+)\] async_waiting @ ([0-9]+)/) {
86 my $pid = $2;
87 my $func;
88 if (!defined($pidctr{$pid})) {
89 $func = "wait_" . $pid . "_1";
90 $pidctr{$pid} = 1;
91 } else {
92 $pidctr{$pid} = $pidctr{$pid} + 1;
93 $func = "wait_" . $pid . "_" . $pidctr{$pid};
94 }
95 if ($done == 0) {
96 $start{$func} = $1;
97 $type{$func} = 1;
98 if ($1 < $firsttime) {
99 $firsttime = $1;
100 }
101 }
102 $pids{$func} = $pid;
103 $count = $count + 1;
104 }
105
106 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_\.]+)\+.*returned/) {
107 if ($done == 0) {
108 $end{$2} = $1;
109 $maxtime = $1;
110 }
111 }
112
113 if ($line =~ /([0-9\.]+)\] async_continuing @ ([0-9]+)/) {
114 my $pid = $2;
115 my $func = "wait_" . $pid . "_" . $pidctr{$pid};
116 $end{$func} = $1;
117 $maxtime = $1;
118 }
119 if ($line =~ /Write protecting the/) {
120 $done = 1;
121 }
122 if ($line =~ /Freeing unused kernel memory/) {
123 $done = 1;
124 }
125}
126
127if ($count == 0) {
128 print STDERR <<END;
129No data found in the dmesg. Make sure that 'printk.time=1' and
130'initcall_debug' are passed on the kernel command line.
131END
132 help(1);
133 exit 1;
134}
135
136print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
137print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
138
139
140if ($header) {
141 my $version = `uname -a`;
142 my $date = `date`;
143 print "<text transform=\"translate($xheader,$yheader)\">Kernel version: $version</text>\n";
144 $cyheader = $yheader+$headerstep;
145 print "<text transform=\"translate($xheader,$cyheader)\">Date: $date</text>\n";
146}
147
148my @styles;
149
150$styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
151$styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
152$styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
153$styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
154$styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
155$styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
156$styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
157$styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
158$styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
159$styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
160$styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
161$styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
162
163my $style_wait = "fill:rgb(128,128,128);fill-opacity:0.5;stroke-width:0;stroke:rgb(0,0,0)";
164
165my $mult = 1950.0 / ($maxtime - $firsttime);
166my $threshold2 = ($maxtime - $firsttime) / 120.0;
167my $threshold = $threshold2/10;
168my $stylecounter = 0;
169my %rows;
170my $rowscount = 1;
171my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
172
173foreach my $key (@initcalls) {
174 my $duration = $end{$key} - $start{$key};
175
176 if ($duration >= $threshold) {
177 my ($s, $s2, $s3, $e, $w, $y, $y2, $style);
178 my $pid = $pids{$key};
179
180 if (!defined($rows{$pid})) {
181 $rows{$pid} = $rowscount;
182 $rowscount = $rowscount + 1;
183 }
184 $s = ($start{$key} - $firsttime) * $mult;
185 $s2 = $s + 6;
186 $s3 = $s + 1;
187 $e = ($end{$key} - $firsttime) * $mult;
188 $w = $e - $s;
189
190 $y = $rows{$pid} * 150;
191 $y2 = $y + 4;
192
193 $style = $styles[$stylecounter];
194 $stylecounter = $stylecounter + 1;
195 if ($stylecounter > 11) {
196 $stylecounter = 0;
197 };
198
199 if ($type{$key} == 1) {
200 $y = $y + 15;
201 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"115\" style=\"$style_wait\"/>\n";
202 } else {
203 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
204 if ($duration >= $threshold2) {
205 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
206 } else {
207 print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n";
208 }
209 }
210 }
211}
212
213
214# print the time line on top
215my $time = $firsttime;
216my $step = ($maxtime - $firsttime) / 15;
217while ($time < $maxtime) {
218 my $s3 = ($time - $firsttime) * $mult;
219 my $tm = int($time * 100) / 100.0;
220 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
221 $time = $time + $step;
222}
223
224print "</svg>\n";
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
40use strict;
41
42my %start;
43my %end;
44my %type;
45my $done = 0;
46my $maxtime = 0;
47my $firsttime = 99999;
48my $count = 0;
49my %pids;
50my %pidctr;
51
52while (<>) {
53 my $line = $_;
54 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_\.]+)\+/) {
55 my $func = $2;
56 if ($done == 0) {
57 $start{$func} = $1;
58 $type{$func} = 0;
59 if ($1 < $firsttime) {
60 $firsttime = $1;
61 }
62 }
63 if ($line =~ /\@ ([0-9]+)/) {
64 $pids{$func} = $1;
65 }
66 $count = $count + 1;
67 }
68
69 if ($line =~ /([0-9\.]+)\] async_waiting @ ([0-9]+)/) {
70 my $pid = $2;
71 my $func;
72 if (!defined($pidctr{$pid})) {
73 $func = "wait_" . $pid . "_1";
74 $pidctr{$pid} = 1;
75 } else {
76 $pidctr{$pid} = $pidctr{$pid} + 1;
77 $func = "wait_" . $pid . "_" . $pidctr{$pid};
78 }
79 if ($done == 0) {
80 $start{$func} = $1;
81 $type{$func} = 1;
82 if ($1 < $firsttime) {
83 $firsttime = $1;
84 }
85 }
86 $pids{$func} = $pid;
87 $count = $count + 1;
88 }
89
90 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_\.]+)\+.*returned/) {
91 if ($done == 0) {
92 $end{$2} = $1;
93 $maxtime = $1;
94 }
95 }
96
97 if ($line =~ /([0-9\.]+)\] async_continuing @ ([0-9]+)/) {
98 my $pid = $2;
99 my $func = "wait_" . $pid . "_" . $pidctr{$pid};
100 $end{$func} = $1;
101 $maxtime = $1;
102 }
103 if ($line =~ /Write protecting the/) {
104 $done = 1;
105 }
106 if ($line =~ /Freeing unused kernel memory/) {
107 $done = 1;
108 }
109}
110
111if ($count == 0) {
112 print STDERR <<END;
113No data found in the dmesg. Make sure that 'printk.time=1' and
114'initcall_debug' are passed on the kernel command line.
115Usage:
116 dmesg | perl scripts/bootgraph.pl > output.svg
117END
118 exit 1;
119}
120
121print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
122print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
123
124my @styles;
125
126$styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
127$styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
128$styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
129$styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
130$styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
131$styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
132$styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
133$styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
134$styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
135$styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
136$styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
137$styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
138
139my $style_wait = "fill:rgb(128,128,128);fill-opacity:0.5;stroke-width:0;stroke:rgb(0,0,0)";
140
141my $mult = 1950.0 / ($maxtime - $firsttime);
142my $threshold2 = ($maxtime - $firsttime) / 120.0;
143my $threshold = $threshold2/10;
144my $stylecounter = 0;
145my %rows;
146my $rowscount = 1;
147my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
148
149foreach my $key (@initcalls) {
150 my $duration = $end{$key} - $start{$key};
151
152 if ($duration >= $threshold) {
153 my ($s, $s2, $s3, $e, $w, $y, $y2, $style);
154 my $pid = $pids{$key};
155
156 if (!defined($rows{$pid})) {
157 $rows{$pid} = $rowscount;
158 $rowscount = $rowscount + 1;
159 }
160 $s = ($start{$key} - $firsttime) * $mult;
161 $s2 = $s + 6;
162 $s3 = $s + 1;
163 $e = ($end{$key} - $firsttime) * $mult;
164 $w = $e - $s;
165
166 $y = $rows{$pid} * 150;
167 $y2 = $y + 4;
168
169 $style = $styles[$stylecounter];
170 $stylecounter = $stylecounter + 1;
171 if ($stylecounter > 11) {
172 $stylecounter = 0;
173 };
174
175 if ($type{$key} == 1) {
176 $y = $y + 15;
177 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"115\" style=\"$style_wait\"/>\n";
178 } else {
179 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
180 if ($duration >= $threshold2) {
181 print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
182 } else {
183 print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n";
184 }
185 }
186 }
187}
188
189
190# print the time line on top
191my $time = $firsttime;
192my $step = ($maxtime - $firsttime) / 15;
193while ($time < $maxtime) {
194 my $s3 = ($time - $firsttime) * $mult;
195 my $tm = int($time * 100) / 100.0;
196 print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
197 $time = $time + $step;
198}
199
200print "</svg>\n";