Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 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 | |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 40 | my %start, %end; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 41 | my $done = 0; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 42 | my $maxtime = 0; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 43 | my $firsttime = 100; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 44 | my $count = 0; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 45 | my %pids; |
| 46 | |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 47 | while (<>) { |
| 48 | my $line = $_; |
| 49 | if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z\_]+)\+/) { |
| 50 | my $func = $2; |
| 51 | if ($done == 0) { |
| 52 | $start{$func} = $1; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 53 | if ($1 < $firsttime) { |
| 54 | $firsttime = $1; |
| 55 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 56 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 57 | if ($line =~ /\@ ([0-9]+)/) { |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 58 | $pids{$func} = $1; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 59 | } |
| 60 | $count = $count + 1; |
| 61 | } |
| 62 | |
| 63 | if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z\_]+)\+.*returned/) { |
| 64 | if ($done == 0) { |
| 65 | $end{$2} = $1; |
| 66 | $maxtime = $1; |
| 67 | } |
| 68 | } |
| 69 | if ($line =~ /Write protecting the/) { |
| 70 | $done = 1; |
| 71 | } |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 72 | if ($line =~ /Freeing unused kernel memory/) { |
| 73 | $done = 1; |
| 74 | } |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | if ($count == 0) { |
| 78 | print "No data found in the dmesg. Make sure CONFIG_PRINTK_TIME is enabled and\n"; |
| 79 | print "that initcall_debug is passed on the kernel command line.\n\n"; |
| 80 | print "Usage: \n"; |
| 81 | print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n"; |
| 82 | exit; |
| 83 | } |
| 84 | |
| 85 | print "<?xml version=\"1.0\" standalone=\"no\"?> \n"; |
| 86 | print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n"; |
| 87 | |
| 88 | my @styles; |
| 89 | |
| 90 | $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 91 | $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 92 | $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 93 | $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 94 | $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 95 | $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 96 | $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 97 | $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 98 | $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 99 | $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 100 | $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 101 | $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)"; |
| 102 | |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 103 | my $mult = 950.0 / ($maxtime - $firsttime); |
| 104 | my $threshold = ($maxtime - $firsttime) / 60.0; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 105 | my $stylecounter = 0; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 106 | my %rows; |
| 107 | my $rowscount = 1; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 108 | while (($key,$value) = each %start) { |
| 109 | my $duration = $end{$key} - $start{$key}; |
| 110 | |
| 111 | if ($duration >= $threshold) { |
| 112 | my $s, $s2, $e, $y; |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 113 | $s = ($value - $firsttime) * $mult; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 114 | $s2 = $s + 6; |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 115 | $e = ($end{$key} - $firsttime) * $mult; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 116 | $w = $e - $s; |
| 117 | |
Frederic Weisbecker | ddc7a01 | 2008-10-04 21:35:48 +0200 | [diff] [blame] | 118 | $y = $rows{$pid} * 150; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 119 | $y2 = $y + 4; |
| 120 | |
| 121 | $style = $styles[$stylecounter]; |
| 122 | $stylecounter = $stylecounter + 1; |
| 123 | if ($stylecounter > 11) { |
| 124 | $stylecounter = 0; |
| 125 | }; |
| 126 | |
| 127 | print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n"; |
| 128 | print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n"; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
| 133 | # print the time line on top |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 134 | my $time = $firsttime; |
| 135 | my $step = ($maxtime - $firsttime) / 15; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 136 | while ($time < $maxtime) { |
Arjan van de Ven | 80a398a | 2008-09-14 15:30:52 -0700 | [diff] [blame^] | 137 | my $s2 = ($time - $firsttime) * $mult; |
| 138 | my $tm = int($time * 100) / 100.0; |
| 139 | print "<text transform=\"translate($s2,89) rotate(90)\">$tm</text>\n"; |
| 140 | $time = $time + $step; |
Arjan van de Ven | aa5d915 | 2008-09-13 09:36:06 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | print "</svg>\n"; |