cleanup-trace-events.pl 1.5 KB

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