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