cleanup-trace-events.pl 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/perl
  2. # Copyright (C) 2013 Red Hat, Inc.
  3. #
  4. # Authors:
  5. # Markus Armbruster <armbru@redhat.com>
  6. #
  7. # This work is licensed under the terms of the GNU GPL, version 2 or
  8. # later. See the COPYING file in the top-level directory.
  9. # Usage: cleanup-trace-events.pl trace-events
  10. #
  11. # Print cleaned up trace-events to standard output.
  12. use warnings;
  13. use strict;
  14. my $buf = '';
  15. my %seen = ();
  16. sub out {
  17. print $buf;
  18. $buf = '';
  19. %seen = ();
  20. }
  21. while (<>) {
  22. if (/^(disable )?([a-z_0-9]+)\(/) {
  23. open GREP, '-|', 'git', 'grep', '-lw', "trace_$2"
  24. or die "run git grep: $!";
  25. my $fname;
  26. while ($fname = <GREP>) {
  27. chomp $fname;
  28. next if $seen{$fname} || $fname eq 'trace-events';
  29. $seen{$fname} = 1;
  30. $buf = "# $fname\n" . $buf;
  31. }
  32. unless (close GREP) {
  33. die "close git grep: $!"
  34. if $!;
  35. next;
  36. }
  37. } elsif (/^# ([^ ]*\.[ch])$/) {
  38. out;
  39. next;
  40. } elsif (!/^#|^$/) {
  41. warn "unintelligible line";
  42. }
  43. $buf .= $_;
  44. }
  45. out;