power.pl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 cstate ftrace output into a SVG graphic that shows
  25. # historic C-state information
  26. #
  27. #
  28. # cat /sys/kernel/debug/tracing/trace | perl power.pl > out.svg
  29. #
  30. my @styles;
  31. my $base = 0;
  32. my @pstate_last;
  33. my @pstate_level;
  34. $styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  35. $styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  36. $styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  37. $styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  38. $styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  39. $styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  40. $styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  41. $styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  42. $styles[8] = "fill:rgb(0,25,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
  43. print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
  44. print "<svg width=\"10000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
  45. my $scale = 30000.0;
  46. while (<>) {
  47. my $line = $_;
  48. if ($line =~ /([0-9\.]+)\] CSTATE: Going to C([0-9]) on cpu ([0-9]+) for ([0-9\.]+)/) {
  49. if ($base == 0) {
  50. $base = $1;
  51. }
  52. my $time = $1 - $base;
  53. $time = $time * $scale;
  54. my $C = $2;
  55. my $cpu = $3;
  56. my $y = 400 * $cpu;
  57. my $duration = $4 * $scale;
  58. my $msec = int($4 * 100000)/100.0;
  59. my $height = $C * 20;
  60. $style = $styles[$C];
  61. $y = $y + 140 - $height;
  62. $x2 = $time + 4;
  63. $y2 = $y + 4;
  64. print "<rect x=\"$time\" width=\"$duration\" y=\"$y\" height=\"$height\" style=\"$style\"/>\n";
  65. print "<text transform=\"translate($x2,$y2) rotate(90)\">C$C $msec</text>\n";
  66. }
  67. if ($line =~ /([0-9\.]+)\] PSTATE: Going to P([0-9]) on cpu ([0-9]+)/) {
  68. my $time = $1 - $base;
  69. my $state = $2;
  70. my $cpu = $3;
  71. if (defined($pstate_last[$cpu])) {
  72. my $from = $pstate_last[$cpu];
  73. my $oldstate = $pstate_state[$cpu];
  74. my $duration = ($time-$from) * $scale;
  75. $from = $from * $scale;
  76. my $to = $from + $duration;
  77. my $height = 140 - ($oldstate * (140/8));
  78. my $y = 400 * $cpu + 200 + $height;
  79. my $y2 = $y+4;
  80. my $style = $styles[8];
  81. print "<rect x=\"$from\" y=\"$y\" width=\"$duration\" height=\"5\" style=\"$style\"/>\n";
  82. print "<text transform=\"translate($from,$y2)\">P$oldstate (cpu $cpu)</text>\n";
  83. };
  84. $pstate_last[$cpu] = $time;
  85. $pstate_state[$cpu] = $state;
  86. }
  87. }
  88. print "</svg>\n";