wakeup-latency.pl 2.7 KB

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