~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/bootgraph.pl

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/bootgraph.pl (Version linux-6.11.5) and /scripts/bootgraph.pl (Version linux-4.9.337)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php