workqueue-stats.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/bin/perl -w
  2. # (c) 2009, Tom Zanussi <tzanussi@gmail.com>
  3. # Licensed under the terms of the GNU GPL License version 2
  4. # Displays workqueue stats
  5. #
  6. # Usage:
  7. #
  8. # perf record -c 1 -f -a -R -e workqueue:workqueue_creation -e
  9. # workqueue:workqueue_destruction -e workqueue:workqueue_execution
  10. # -e workqueue:workqueue_insertion
  11. #
  12. # perf script -p -s tools/perf/scripts/perl/workqueue-stats.pl
  13. use 5.010000;
  14. use strict;
  15. use warnings;
  16. use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
  17. use lib "./Perf-Trace-Util/lib";
  18. use Perf::Trace::Core;
  19. use Perf::Trace::Util;
  20. my @cpus;
  21. sub workqueue::workqueue_destruction
  22. {
  23. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  24. $common_pid, $common_comm,
  25. $thread_comm, $thread_pid) = @_;
  26. $cpus[$common_cpu]{$thread_pid}{destroyed}++;
  27. $cpus[$common_cpu]{$thread_pid}{comm} = $thread_comm;
  28. }
  29. sub workqueue::workqueue_creation
  30. {
  31. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  32. $common_pid, $common_comm,
  33. $thread_comm, $thread_pid, $cpu) = @_;
  34. $cpus[$common_cpu]{$thread_pid}{created}++;
  35. $cpus[$common_cpu]{$thread_pid}{comm} = $thread_comm;
  36. }
  37. sub workqueue::workqueue_execution
  38. {
  39. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  40. $common_pid, $common_comm,
  41. $thread_comm, $thread_pid, $func) = @_;
  42. $cpus[$common_cpu]{$thread_pid}{executed}++;
  43. $cpus[$common_cpu]{$thread_pid}{comm} = $thread_comm;
  44. }
  45. sub workqueue::workqueue_insertion
  46. {
  47. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  48. $common_pid, $common_comm,
  49. $thread_comm, $thread_pid, $func) = @_;
  50. $cpus[$common_cpu]{$thread_pid}{inserted}++;
  51. $cpus[$common_cpu]{$thread_pid}{comm} = $thread_comm;
  52. }
  53. sub trace_end
  54. {
  55. print "workqueue work stats:\n\n";
  56. my $cpu = 0;
  57. printf("%3s %6s %6s\t%-20s\n", "cpu", "ins", "exec", "name");
  58. printf("%3s %6s %6s\t%-20s\n", "---", "---", "----", "----");
  59. foreach my $pidhash (@cpus) {
  60. while ((my $pid, my $wqhash) = each %$pidhash) {
  61. my $ins = $$wqhash{'inserted'} || 0;
  62. my $exe = $$wqhash{'executed'} || 0;
  63. my $comm = $$wqhash{'comm'} || "";
  64. if ($ins || $exe) {
  65. printf("%3u %6u %6u\t%-20s\n", $cpu, $ins, $exe, $comm);
  66. }
  67. }
  68. $cpu++;
  69. }
  70. $cpu = 0;
  71. print "\nworkqueue lifecycle stats:\n\n";
  72. printf("%3s %6s %6s\t%-20s\n", "cpu", "created", "destroyed", "name");
  73. printf("%3s %6s %6s\t%-20s\n", "---", "-------", "---------", "----");
  74. foreach my $pidhash (@cpus) {
  75. while ((my $pid, my $wqhash) = each %$pidhash) {
  76. my $created = $$wqhash{'created'} || 0;
  77. my $destroyed = $$wqhash{'destroyed'} || 0;
  78. my $comm = $$wqhash{'comm'} || "";
  79. if ($created || $destroyed) {
  80. printf("%3u %6u %6u\t%-20s\n", $cpu, $created, $destroyed,
  81. $comm);
  82. }
  83. }
  84. $cpu++;
  85. }
  86. print_unhandled();
  87. }
  88. my %unhandled;
  89. sub print_unhandled
  90. {
  91. if ((scalar keys %unhandled) == 0) {
  92. return;
  93. }
  94. print "\nunhandled events:\n\n";
  95. printf("%-40s %10s\n", "event", "count");
  96. printf("%-40s %10s\n", "----------------------------------------",
  97. "-----------");
  98. foreach my $event_name (keys %unhandled) {
  99. printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
  100. }
  101. }
  102. sub trace_unhandled
  103. {
  104. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  105. $common_pid, $common_comm) = @_;
  106. $unhandled{$event_name}++;
  107. }