]> git.proxmox.com Git - mirror_qemu.git/blob - scripts/cleanup-trace-events.pl
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[mirror_qemu.git] / scripts / cleanup-trace-events.pl
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
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;
16 use File::Basename;
17
18 my $buf = '';
19 my %seen = ();
20
21 sub out {
22 print $buf;
23 $buf = '';
24 %seen = ();
25 }
26
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
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;
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;
60 close(IN) or die "close $in: $!";