Kamil Rytarowski | cb77f0d | 2017-05-07 23:25:26 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 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 Jenkins | 2a813f8 | 2008-10-14 14:18:07 +0100 | [diff] [blame] | 40 | use strict; |
Fabian Frederick | 67554fa | 2014-04-02 21:39:52 +0200 | [diff] [blame] | 41 | use Getopt::Long; |
| 42 | my $header = 0; |
| 43 | |
| 44 | sub help { |
| 45 | my $text = << "EOM"; |
| 46 | Usage: |
| 47 | 1) dmesg | perl scripts/bootgraph.pl [OPTION] > output.svg |
| 48 | 2) perl scripts/bootgraph.pl -h |
| 49 | |
| 50 | Options: |
| 51 | -header Insert kernel version and date |
| 52 | EOM |
| 53 | my $std=shift; |
| 54 | if ($std == 1) { |
| 55 | print STDERR $text; |
| 56 | } else { |
| 57 | print $text; |
| 58 | } |
| 59 | exit; |
| 60 | } |
| 61 | |
| 62 | GetOptions( |
| 63 | 'h|help' =>\&help, |
| 64 | 'header' =>\$header |
| 65 | ); |
Alan Jenkins | 2a813f8 | 2008-10-14 14:18:07 +0100 | [diff] [blame] | 66 | |
| 67 | my %start; |
| 68 | my %end; |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 69 | my %type; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 70 | my $done = 0; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 71 | my $maxtime = 0; |
Andrew Murray | c443453 | 2011-06-09 22:40:10 +0100 | [diff] [blame] | 72 | my $firsttime = 99999; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 73 | my $count = 0; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 74 | my %pids; |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 75 | my %pidctr; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 76 | |
Fabian Frederick | 67554fa | 2014-04-02 21:39:52 +0200 | [diff] [blame] | 77 | my $headerstep = 20; |
| 78 | my $xheader = 15; |
| 79 | my $yheader = 25; |
| 80 | my $cyheader = 0; |
| 81 | |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 82 | while (<>) { |
| 83 | my $line = $_; |
Michael Neuling | 0bb98e2 | 2009-02-15 10:20:30 +0100 | [diff] [blame] | 84 | if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_\.]+)\+/) { |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 85 | my $func = $2; |
| 86 | if ($done == 0) { |
| 87 | $start{$func} = $1; |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 88 | $type{$func} = 0; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 89 | if ($1 < $firsttime) { |
| 90 | $firsttime = $1; |
| 91 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 92 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 93 | if ($line =~ /\@ ([0-9]+)/) { |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 94 | $pids{$func} = $1; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 95 | } |
| 96 | $count = $count + 1; |
| 97 | } |
| 98 | |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 99 | if ($line =~ /([0-9\.]+)\] async_waiting @ ([0-9]+)/) { |
| 100 | my $pid = $2; |
| 101 | my $func; |
| 102 | if (!defined($pidctr{$pid})) { |
| 103 | $func = "wait_" . $pid . "_1"; |
| 104 | $pidctr{$pid} = 1; |
| 105 | } else { |
| 106 | $pidctr{$pid} = $pidctr{$pid} + 1; |
| 107 | $func = "wait_" . $pid . "_" . $pidctr{$pid}; |
| 108 | } |
| 109 | if ($done == 0) { |
| 110 | $start{$func} = $1; |
| 111 | $type{$func} = 1; |
| 112 | if ($1 < $firsttime) { |
| 113 | $firsttime = $1; |
| 114 | } |
| 115 | } |
| 116 | $pids{$func} = $pid; |
| 117 | $count = $count + 1; |
| 118 | } |
| 119 | |
Michael Neuling | 0bb98e2 | 2009-02-15 10:20:30 +0100 | [diff] [blame] | 120 | if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_\.]+)\+.*returned/) { |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 121 | if ($done == 0) { |
| 122 | $end{$2} = $1; |
| 123 | $maxtime = $1; |
| 124 | } |
| 125 | } |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 126 | |
| 127 | if ($line =~ /([0-9\.]+)\] async_continuing @ ([0-9]+)/) { |
| 128 | my $pid = $2; |
| 129 | my $func = "wait_" . $pid . "_" . $pidctr{$pid}; |
| 130 | $end{$func} = $1; |
| 131 | $maxtime = $1; |
| 132 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 133 | if ($line =~ /Write protecting the/) { |
| 134 | $done = 1; |
| 135 | } |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 136 | if ($line =~ /Freeing unused kernel memory/) { |
| 137 | $done = 1; |
| 138 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if ($count == 0) { |
Stephen Hemminger | d1aaf8c | 2008-11-13 08:33:00 -0800 | [diff] [blame] | 142 | print STDERR <<END; |
| 143 | No data found in the dmesg. Make sure that 'printk.time=1' and |
| 144 | 'initcall_debug' are passed on the kernel command line. |
Stephen Hemminger | d1aaf8c | 2008-11-13 08:33:00 -0800 | [diff] [blame] | 145 | END |
Fabian Frederick | 67554fa | 2014-04-02 21:39:52 +0200 | [diff] [blame] | 146 | help(1); |
Stephen Hemminger | d1aaf8c | 2008-11-13 08:33:00 -0800 | [diff] [blame] | 147 | exit 1; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | print "<?xml version=\"1.0\" standalone=\"no\"?> \n"; |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 151 | print "<svg width=\"2000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n"; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 152 | |
Fabian Frederick | 67554fa | 2014-04-02 21:39:52 +0200 | [diff] [blame] | 153 | |
| 154 | if ($header) { |
| 155 | my $version = `uname -a`; |
| 156 | my $date = `date`; |
| 157 | print "<text transform=\"translate($xheader,$yheader)\">Kernel version: $version</text>\n"; |
| 158 | $cyheader = $yheader+$headerstep; |
| 159 | print "<text transform=\"translate($xheader,$cyheader)\">Date: $date</text>\n"; |
| 160 | } |
| 161 | |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 162 | my @styles; |
| 163 | |
| 164 | $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 165 | $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 166 | $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 167 | $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 168 | $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 169 | $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 170 | $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 171 | $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 172 | $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 173 | $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 174 | $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 175 | $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 176 | |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 177 | my $style_wait = "fill:rgb(128,128,128);fill-opacity:0.5;stroke-width:0;stroke:rgb(0,0,0)"; |
| 178 | |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 179 | my $mult = 1950.0 / ($maxtime - $firsttime); |
| 180 | my $threshold2 = ($maxtime - $firsttime) / 120.0; |
| 181 | my $threshold = $threshold2/10; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 182 | my $stylecounter = 0; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 183 | my %rows; |
| 184 | my $rowscount = 1; |
Alan Jenkins | 06d1cd2 | 2008-10-14 14:19:15 +0100 | [diff] [blame] | 185 | my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start); |
Stephen Hemminger | 68f96c0 | 2008-11-12 10:21:01 -0800 | [diff] [blame] | 186 | |
| 187 | foreach my $key (@initcalls) { |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 188 | my $duration = $end{$key} - $start{$key}; |
| 189 | |
| 190 | if ($duration >= $threshold) { |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 191 | my ($s, $s2, $s3, $e, $w, $y, $y2, $style); |
Alan Jenkins | 2a813f8 | 2008-10-14 14:18:07 +0100 | [diff] [blame] | 192 | my $pid = $pids{$key}; |
Frederic Weisbecker | 07d1890 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 193 | |
| 194 | if (!defined($rows{$pid})) { |
| 195 | $rows{$pid} = $rowscount; |
| 196 | $rowscount = $rowscount + 1; |
| 197 | } |
Alan Jenkins | 06d1cd2 | 2008-10-14 14:19:15 +0100 | [diff] [blame] | 198 | $s = ($start{$key} - $firsttime) * $mult; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 199 | $s2 = $s + 6; |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 200 | $s3 = $s + 1; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 201 | $e = ($end{$key} - $firsttime) * $mult; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 202 | $w = $e - $s; |
| 203 | |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 204 | $y = $rows{$pid} * 150; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 205 | $y2 = $y + 4; |
| 206 | |
| 207 | $style = $styles[$stylecounter]; |
| 208 | $stylecounter = $stylecounter + 1; |
| 209 | if ($stylecounter > 11) { |
| 210 | $stylecounter = 0; |
| 211 | }; |
| 212 | |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 213 | if ($type{$key} == 1) { |
| 214 | $y = $y + 15; |
| 215 | print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"115\" style=\"$style_wait\"/>\n"; |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 216 | } else { |
Arjan van de Ven | d3f8dde | 2009-01-10 10:03:05 -0800 | [diff] [blame] | 217 | print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n"; |
| 218 | if ($duration >= $threshold2) { |
| 219 | print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n"; |
| 220 | } else { |
| 221 | print "<text transform=\"translate($s3,$y2) rotate(90)\" font-size=\"3pt\">$key</text>\n"; |
| 222 | } |
Arjan van de Ven | 40c8c85 | 2009-01-04 07:16:38 -0800 | [diff] [blame] | 223 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | |
| 228 | # print the time line on top |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 229 | my $time = $firsttime; |
| 230 | my $step = ($maxtime - $firsttime) / 15; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 231 | while ($time < $maxtime) { |
Alan Jenkins | 2a813f8 | 2008-10-14 14:18:07 +0100 | [diff] [blame] | 232 | my $s3 = ($time - $firsttime) * $mult; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 233 | my $tm = int($time * 100) / 100.0; |
Alan Jenkins | 2a813f8 | 2008-10-14 14:18:07 +0100 | [diff] [blame] | 234 | print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n"; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame] | 235 | $time = $time + $step; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | print "</svg>\n"; |