2 # SPDX-License-Identifier: GPL-2.0-only
4 # Copyright 2008, Intel Corporation
6 # This file is part of the Linux kernel
9 # Arjan van de Ven <arjan@linux.intel.com>
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.
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.
23 # dmesg | perl scripts/bootgraph.pl > output.svg
33 1) dmesg
| perl scripts
/bootgraph
.pl
[OPTION
] > output
.svg
34 2) perl scripts
/bootgraph
.pl
-h
37 -header Insert kernel version
and date
58 my $firsttime = 99999;
70 if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_\.]+)\+/) {
75 if ($1 < $firsttime) {
79 if ($line =~ /\@ ([0-9]+)/) {
85 if ($line =~ /([0-9\.]+)\] async_waiting @ ([0-9]+)/) {
88 if (!defined($pidctr{$pid})) {
89 $func = "wait_" . $pid . "_1";
92 $pidctr{$pid} = $pidctr{$pid} + 1;
93 $func = "wait_" . $pid . "_" . $pidctr{$pid};
98 if ($1 < $firsttime) {
106 if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_\.]+)\+.*returned/) {
113 if ($line =~ /([0-9\.]+)\] async_continuing @ ([0-9]+)/) {
115 my $func = "wait_" . $pid . "_" . $pidctr{$pid};
119 if ($line =~ /Write protecting the/) {
122 if ($line =~ /Freeing unused kernel memory/) {
129 No data found in the dmesg. Make sure that 'printk.time=1' and
130 'initcall_debug' are passed on the kernel command line.
136 print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
137 print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
141 my $version = `uname -a`;
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";
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)";
163 my $style_wait = "fill:rgb(128,128,128);fill-opacity:0.5;stroke-width:0;stroke:rgb(0,0,0)";
165 my $mult = 1950.0 / ($maxtime - $firsttime);
166 my $threshold2 = ($maxtime - $firsttime) / 120.0;
167 my $threshold = $threshold2/10;
168 my $stylecounter = 0;
171 my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
173 foreach my $key (@initcalls) {
174 my $duration = $end{$key} - $start{$key};
176 if ($duration >= $threshold) {
177 my ($s, $s2, $s3, $e, $w, $y, $y2, $style);
178 my $pid = $pids{$key};
180 if (!defined($rows{$pid})) {
181 $rows{$pid} = $rowscount;
182 $rowscount = $rowscount + 1;
184 $s = ($start{$key} - $firsttime) * $mult;
187 $e = ($end{$key} - $firsttime) * $mult;
190 $y = $rows{$pid} * 150;
193 $style = $styles[$stylecounter];
194 $stylecounter = $stylecounter + 1;
195 if ($stylecounter > 11) {
199 if ($type{$key} == 1) {
201 print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"115\" style=\"$style_wait\"/>\n";
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";
207 print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n";
214 # print the time line on top
215 my $time = $firsttime;
216 my $step = ($maxtime - $firsttime) / 15;
217 while ($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;