monitor: Split monitor_init in HMP and QMP function
[qemu/ar7.git] / scripts / cleanup-trace-events.pl
blobd4f0e4cab53019e56f86b92c97e0e081ddb8a216
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 $buf = '';
19 my %seen = ();
21 sub out {
22 print $buf;
23 $buf = '';
24 %seen = ();
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: $!";
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
38 or die "run git grep: $!";
39 while (my $fname = <GREP>) {
40 chomp $fname;
41 next if $seen{$fname} || $fname eq 'trace-events';
42 $seen{$fname} = 1;
43 $buf = "# $fname\n" . $buf;
45 unless (close GREP) {
46 die "close git grep: $!"
47 if $!;
48 next;
50 } elsif (/^# ([^ ]*\.[ch])$/) {
51 out;
52 next;
53 } elsif (!/^#|^$/) {
54 warn "unintelligible line";
56 $buf .= $_;
59 out;
60 close(IN) or die "close $in: $!";