bootgraph.pl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/usr/bin/perl
  2. # Copyright 2008, Intel Corporation
  3. #
  4. # This file is part of the Linux kernel
  5. #
  6. # This program file is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by the
  8. # Free Software Foundation; version 2 of the License.
  9. #
  10. # This program is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. # for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program in a file named COPYING; if not, write to the
  17. # Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor,
  19. # Boston, MA 02110-1301 USA
  20. #
  21. # Authors:
  22. # Arjan van de Ven <arjan@linux.intel.com>
  23. #
  24. # This script turns a dmesg output into a SVG graphic that shows which
  25. # functions take how much time. You can view SVG graphics with various
  26. # programs, including Inkscape, The Gimp and Firefox.
  27. #
  28. #
  29. # For this script to work, the kernel needs to be compiled with the
  30. # CONFIG_PRINTK_TIME configuration option enabled, and with
  31. # "initcall_debug" passed on the kernel command line.
  32. #
  33. # usage:
  34. # dmesg | perl scripts/bootgraph.pl > output.svg
  35. #
  36. my @rows;
  37. my %start, %end, %row;
  38. my $done = 0;
  39. my $rowcount = 0;
  40. my $maxtime = 0;
  41. my $count = 0;
  42. while (<>) {
  43. my $line = $_;
  44. if ($line =~ /([0-9\.]+)\] calling ([a-zA-Z\_]+)\+/) {
  45. my $func = $2;
  46. if ($done == 0) {
  47. $start{$func} = $1;
  48. }
  49. $row{$func} = 1;
  50. if ($line =~ /\@ ([0-9]+)/) {
  51. my $pid = $1;
  52. if (!defined($rows[$pid])) {
  53. $rowcount = $rowcount + 1;
  54. $rows[$pid] = $rowcount;
  55. }
  56. $row{$func} = $rows[$pid];
  57. }
  58. $count = $count + 1;
  59. }
  60. if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z\_]+)\+.*returned/) {
  61. if ($done == 0) {
  62. $end{$2} = $1;
  63. $maxtime = $1;
  64. }
  65. }
  66. if ($line =~ /Write protecting the/) {
  67. $done = 1;
  68. }
  69. }
  70. if ($count == 0) {
  71. print "No data found in the dmesg. Make sure CONFIG_PRINTK_TIME is enabled and\n";
  72. print "that initcall_debug is passed on the kernel command line.\n\n";
  73. print "Usage: \n";
  74. print " dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
  75. exit;
  76. }
  77. print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
  78. print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
  79. my @styles;
  80. $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  81. $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  82. $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  83. $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  84. $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  85. $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  86. $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  87. $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  88. $styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  89. $styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  90. $styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  91. $styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  92. my $mult = 950.0 / $maxtime;
  93. my $threshold = 0.0500 / $maxtime;
  94. my $stylecounter = 0;
  95. while (($key,$value) = each %start) {
  96. my $duration = $end{$key} - $start{$key};
  97. if ($duration >= $threshold) {
  98. my $s, $s2, $e, $y;
  99. $s = $value * $mult;
  100. $s2 = $s + 6;
  101. $e = $end{$key} * $mult;
  102. $w = $e - $s;
  103. $y = $row{$key} * 150;
  104. $y2 = $y + 4;
  105. $style = $styles[$stylecounter];
  106. $stylecounter = $stylecounter + 1;
  107. if ($stylecounter > 11) {
  108. $stylecounter = 0;
  109. };
  110. print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
  111. print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
  112. }
  113. }
  114. # print the time line on top
  115. my $time = 0.0;
  116. while ($time < $maxtime) {
  117. my $s2 = $time * $mult;
  118. print "<text transform=\"translate($s2,89) rotate(90)\">$time</text>\n";
  119. $time = $time + 0.1;
  120. }
  121. print "</svg>\n";