cleanup-trace-events.pl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env 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. use File::Basename;
  15. my $buf = '';
  16. my %seen = ();
  17. sub out {
  18. print $buf;
  19. $buf = '';
  20. %seen = ();
  21. }
  22. $#ARGV == 0 or die "usage: $0 FILE";
  23. my $in = $ARGV[0];
  24. my $dir = dirname($in);
  25. open(IN, $in) or die "open $in: $!";
  26. chdir($dir) or die "chdir $dir: $!";
  27. while (<IN>) {
  28. if (/^(disable |(tcg) |vcpu )*([a-z_0-9]+)\(/i) {
  29. my $pat = "trace_$3";
  30. $pat .= '_tcg' if (defined $2);
  31. open GREP, '-|', 'git', 'grep', '-lw', '--max-depth', '1', $pat
  32. or die "run git grep: $!";
  33. while (my $fname = <GREP>) {
  34. chomp $fname;
  35. next if $seen{$fname} || $fname eq 'trace-events';
  36. $seen{$fname} = 1;
  37. $buf = "# $fname\n" . $buf;
  38. }
  39. unless (close GREP) {
  40. die "close git grep: $!"
  41. if $!;
  42. next;
  43. }
  44. } elsif (/^# ([^ ]*\.[ch])$/) {
  45. out;
  46. next;
  47. } elsif (!/^#|^$/) {
  48. warn "unintelligible line";
  49. }
  50. $buf .= $_;
  51. }
  52. out;
  53. close(IN) or die "close $in: $!";