| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 |
|
| 25 |
|
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 |
|
| 40 | use strict;
|
| 41 |
|
| 42 | my %start;
|
| 43 | my %end;
|
| 44 | my $done = 0;
|
| 45 | my $maxtime = 0;
|
| 46 | my $firsttime = 100;
|
| 47 | my $count = 0;
|
| 48 | my %pids;
|
| 49 |
|
| 50 | while (<>) {
|
| 51 | my $line = $_;
|
| 52 | if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z0-9\_]+)\+/) {
|
| 53 | my $func = $2;
|
| 54 | if ($done == 0) {
|
| 55 | $start{$func} = $1;
|
| 56 | if ($1 < $firsttime) {
|
| 57 | $firsttime = $1;
|
| 58 | }
|
| 59 | }
|
| 60 | if ($line =~ /\@ ([0-9]+)/) {
|
| 61 | $pids{$func} = $1;
|
| 62 | }
|
| 63 | $count = $count + 1;
|
| 64 | }
|
| 65 |
|
| 66 | if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
|
| 67 | if ($done == 0) {
|
| 68 | $end{$2} = $1;
|
| 69 | $maxtime = $1;
|
| 70 | }
|
| 71 | }
|
| 72 | if ($line =~ /Write protecting the/) {
|
| 73 | $done = 1;
|
| 74 | }
|
| 75 | if ($line =~ /Freeing unused kernel memory/) {
|
| 76 | $done = 1;
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | if ($count == 0) {
|
| 81 | print "No data found in the dmesg. Make sure that 'printk.time=1' and\n";
|
| 82 | print "'initcall_debug' are passed on the kernel command line.\n\n";
|
| 83 | print "Usage: \n";
|
| 84 | print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
|
| 85 | exit;
|
| 86 | }
|
| 87 |
|
| 88 | print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
|
| 89 | print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
|
| 90 |
|
| 91 | my @styles;
|
| 92 |
|
| 93 | $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 94 | $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 95 | $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 96 | $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 97 | $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 98 | $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 99 | $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 100 | $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 101 | $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 102 | $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 103 | $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 104 | $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
|
| 105 |
|
| 106 | my $mult = 950.0 / ($maxtime - $firsttime);
|
| 107 | my $threshold = ($maxtime - $firsttime) / 60.0;
|
| 108 | my $stylecounter = 0;
|
| 109 | my %rows;
|
| 110 | my $rowscount = 1;
|
| 111 | my @initcalls = sort { $start{$a} <=> $start{$b} } keys(%start);
|
| 112 | my $key;
|
| 113 | foreach $key (@initcalls) {
|
| 114 | my $duration = $end{$key} - $start{$key};
|
| 115 |
|
| 116 | if ($duration >= $threshold) {
|
| 117 | my ($s, $s2, $e, $w, $y, $y2, $style);
|
| 118 | my $pid = $pids{$key};
|
| 119 |
|
| 120 | if (!defined($rows{$pid})) {
|
| 121 | $rows{$pid} = $rowscount;
|
| 122 | $rowscount = $rowscount + 1;
|
| 123 | }
|
| 124 | $s = ($start{$key} - $firsttime) * $mult;
|
| 125 | $s2 = $s + 6;
|
| 126 | $e = ($end{$key} - $firsttime) * $mult;
|
| 127 | $w = $e - $s;
|
| 128 |
|
| 129 | $y = $rows{$pid} * 150;
|
| 130 | $y2 = $y + 4;
|
| 131 |
|
| 132 | $style = $styles[$stylecounter];
|
| 133 | $stylecounter = $stylecounter + 1;
|
| 134 | if ($stylecounter > 11) {
|
| 135 | $stylecounter = 0;
|
| 136 | };
|
| 137 |
|
| 138 | print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
|
| 139 | print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
|
| 140 | }
|
| 141 | }
|
| 142 |
|
| 143 |
|
| 144 | |
| 145 | my $time = $firsttime;
|
| 146 | my $step = ($maxtime - $firsttime) / 15;
|
| 147 | while ($time < $maxtime) {
|
| 148 | my $s3 = ($time - $firsttime) * $mult;
|
| 149 | my $tm = int($time * 100) / 100.0;
|
| 150 | print "<text transform=\"translate($s3,89) rotate(90)\">$tm</text>\n";
|
| 151 | $time = $time + $step;
|
| 152 | }
|
| 153 |
|
| 154 | print "</svg>\n";
|