wakeup-latency.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. # Display avg/min/max wakeup latency
  5. # The common_* event handler fields are the most useful fields common to
  6. # all events. They don't necessarily correspond to the 'common_*' fields
  7. # in the status files. Those fields not available as handler params can
  8. # be retrieved via script functions of the form get_common_*().
  9. use 5.010000;
  10. use strict;
  11. use warnings;
  12. use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
  13. use lib "./Perf-Trace-Util/lib";
  14. use Perf::Trace::Core;
  15. use Perf::Trace::Util;
  16. my %last_wakeup;
  17. my $max_wakeup_latency;
  18. my $min_wakeup_latency;
  19. my $total_wakeup_latency;
  20. my $total_wakeups;
  21. sub sched::sched_switch
  22. {
  23. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  24. $common_pid, $common_comm,
  25. $prev_comm, $prev_pid, $prev_prio, $prev_state, $next_comm, $next_pid,
  26. $next_prio) = @_;
  27. my $wakeup_ts = $last_wakeup{$common_cpu}{ts};
  28. if ($wakeup_ts) {
  29. my $switch_ts = nsecs($common_secs, $common_nsecs);
  30. my $wakeup_latency = $switch_ts - $wakeup_ts;
  31. if ($wakeup_latency > $max_wakeup_latency) {
  32. $max_wakeup_latency = $wakeup_latency;
  33. }
  34. if ($wakeup_latency < $min_wakeup_latency) {
  35. $min_wakeup_latency = $wakeup_latency;
  36. }
  37. $total_wakeup_latency += $wakeup_latency;
  38. $total_wakeups++;
  39. }
  40. $last_wakeup{$common_cpu}{ts} = 0;
  41. }
  42. sub sched::sched_wakeup
  43. {
  44. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  45. $common_pid, $common_comm,
  46. $comm, $pid, $prio, $success, $target_cpu) = @_;
  47. $last_wakeup{$target_cpu}{ts} = nsecs($common_secs, $common_nsecs);
  48. }
  49. sub trace_begin
  50. {
  51. $min_wakeup_latency = 1000000000;
  52. $max_wakeup_latency = 0;
  53. }
  54. sub trace_end
  55. {
  56. printf("wakeup_latency stats:\n\n");
  57. print "total_wakeups: $total_wakeups\n";
  58. printf("avg_wakeup_latency (ns): %u\n",
  59. avg($total_wakeup_latency, $total_wakeups));
  60. printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency);
  61. printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency);
  62. print_unhandled();
  63. }
  64. my %unhandled;
  65. sub print_unhandled
  66. {
  67. if ((scalar keys %unhandled) == 0) {
  68. return;
  69. }
  70. print "\nunhandled events:\n\n";
  71. printf("%-40s %10s\n", "event", "count");
  72. printf("%-40s %10s\n", "----------------------------------------",
  73. "-----------");
  74. foreach my $event_name (keys %unhandled) {
  75. printf("%-40s %10d\n", $event_name, $unhandled{$event_name});
  76. }
  77. }
  78. sub trace_unhandled
  79. {
  80. my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
  81. $common_pid, $common_comm) = @_;
  82. $unhandled{$event_name}++;
  83. }