Kamil Rytarowski | b7d5a9c | 2017-04-26 15:16:04 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 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 | |
| 10 | # Usage: cleanup-trace-events.pl trace-events |
| 11 | # |
| 12 | # Print cleaned up trace-events to standard output. |
| 13 | |
| 14 | use warnings; |
| 15 | use strict; |
Markus Armbruster | a44cf52 | 2019-03-14 19:09:27 +0100 | [diff] [blame] | 16 | use File::Basename; |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 17 | |
Markus Armbruster | f7dc89c | 2020-08-06 16:13:32 +0200 | [diff] [blame] | 18 | my @files = (); |
| 19 | my $events = ''; |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 20 | my %seen = (); |
| 21 | |
| 22 | sub out { |
Markus Armbruster | f7dc89c | 2020-08-06 16:13:32 +0200 | [diff] [blame] | 23 | print sort @files; |
| 24 | print $events; |
| 25 | @files = (); |
| 26 | $events = ''; |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 27 | %seen = (); |
| 28 | } |
| 29 | |
Markus Armbruster | a44cf52 | 2019-03-14 19:09:27 +0100 | [diff] [blame] | 30 | $#ARGV == 0 or die "usage: $0 FILE"; |
| 31 | my $in = $ARGV[0]; |
| 32 | my $dir = dirname($in); |
| 33 | open(IN, $in) or die "open $in: $!"; |
| 34 | chdir($dir) or die "chdir $dir: $!"; |
| 35 | |
| 36 | while (<IN>) { |
Markus Armbruster | 164e7dd | 2020-08-06 16:13:31 +0200 | [diff] [blame] | 37 | if (/^(disable |(tcg) |(vcpu) )*([a-z_0-9]+)\(/i) { |
| 38 | my $pat = "trace_$4"; |
| 39 | $pat .= '_tcg' if defined $2; |
| 40 | open GREP, '-|', 'git', 'grep', '-lw', |
| 41 | defined $3 ? () : ('--max-depth', '1'), |
| 42 | $pat |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 43 | or die "run git grep: $!"; |
Markus Armbruster | a44cf52 | 2019-03-14 19:09:27 +0100 | [diff] [blame] | 44 | while (my $fname = <GREP>) { |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 45 | chomp $fname; |
| 46 | next if $seen{$fname} || $fname eq 'trace-events'; |
| 47 | $seen{$fname} = 1; |
Markus Armbruster | f7dc89c | 2020-08-06 16:13:32 +0200 | [diff] [blame] | 48 | push @files, "# $fname\n"; |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 49 | } |
| 50 | unless (close GREP) { |
| 51 | die "close git grep: $!" |
| 52 | if $!; |
| 53 | next; |
| 54 | } |
| 55 | } elsif (/^# ([^ ]*\.[ch])$/) { |
| 56 | out; |
| 57 | next; |
| 58 | } elsif (!/^#|^$/) { |
| 59 | warn "unintelligible line"; |
| 60 | } |
Markus Armbruster | f7dc89c | 2020-08-06 16:13:32 +0200 | [diff] [blame] | 61 | $events .= $_; |
Markus Armbruster | f0c03c8 | 2013-06-07 12:59:17 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | out; |
Markus Armbruster | a44cf52 | 2019-03-14 19:09:27 +0100 | [diff] [blame] | 65 | close(IN) or die "close $in: $!"; |