docs/system: riscv: Document AIA options for virt machine
[qemu/ar7.git] / scripts / cleanup-trace-events.pl
blobc40d2fcc5016d6acd2caa7f7a8677220fac2ca65
1 #!/usr/bin/env perl
2 # Copyright (C) 2013 Red Hat, Inc.
4 # Authors:
5 # Markus Armbruster <armbru@redhat.com>
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.
10 # Usage: cleanup-trace-events.pl trace-events
12 # Print cleaned up trace-events to standard output.
14 use warnings;
15 use strict;
16 use File::Basename;
18 my @files = ();
19 my $events = '';
20 my %seen = ();
22 sub out {
23 print sort @files;
24 print $events;
25 @files = ();
26 $events = '';
27 %seen = ();
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: $!";
36 while (<IN>) {
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
43 or die "run git grep: $!";
44 while (my $fname = <GREP>) {
45 chomp $fname;
46 next if $seen{$fname} || $fname eq 'trace-events';
47 $seen{$fname} = 1;
48 push @files, "# $fname\n";
50 unless (close GREP) {
51 die "close git grep: $!"
52 if $!;
53 next;
55 } elsif (/^# ([^ ]*\.[ch])$/) {
56 out;
57 next;
58 } elsif (!/^#|^$/) {
59 warn "unintelligible line";
61 $events .= $_;
64 out;
65 close(IN) or die "close $in: $!";