blob: c40d2fcc5016d6acd2caa7f7a8677220fac2ca65 [file] [log] [blame]
Kamil Rytarowskib7d5a9c2017-04-26 15:16:04 +02001#!/usr/bin/env perl
Markus Armbrusterf0c03c82013-06-07 12:59:17 +02002# 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
14use warnings;
15use strict;
Markus Armbrustera44cf522019-03-14 19:09:27 +010016use File::Basename;
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020017
Markus Armbrusterf7dc89c2020-08-06 16:13:32 +020018my @files = ();
19my $events = '';
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020020my %seen = ();
21
22sub out {
Markus Armbrusterf7dc89c2020-08-06 16:13:32 +020023 print sort @files;
24 print $events;
25 @files = ();
26 $events = '';
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020027 %seen = ();
28}
29
Markus Armbrustera44cf522019-03-14 19:09:27 +010030$#ARGV == 0 or die "usage: $0 FILE";
31my $in = $ARGV[0];
32my $dir = dirname($in);
33open(IN, $in) or die "open $in: $!";
34chdir($dir) or die "chdir $dir: $!";
35
36while (<IN>) {
Markus Armbruster164e7dd2020-08-06 16:13:31 +020037 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 Armbrusterf0c03c82013-06-07 12:59:17 +020043 or die "run git grep: $!";
Markus Armbrustera44cf522019-03-14 19:09:27 +010044 while (my $fname = <GREP>) {
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020045 chomp $fname;
46 next if $seen{$fname} || $fname eq 'trace-events';
47 $seen{$fname} = 1;
Markus Armbrusterf7dc89c2020-08-06 16:13:32 +020048 push @files, "# $fname\n";
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020049 }
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 Armbrusterf7dc89c2020-08-06 16:13:32 +020061 $events .= $_;
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020062}
63
64out;
Markus Armbrustera44cf522019-03-14 19:09:27 +010065close(IN) or die "close $in: $!";