blob: 7e808efb6ac152089732d3f5387a60bd67d9ba65 [file] [log] [blame]
Markus Armbrusterf0c03c82013-06-07 12:59:17 +02001#!/usr/bin/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
14use warnings;
15use strict;
16
17my $buf = '';
18my %seen = ();
19
20sub out {
21 print $buf;
22 $buf = '';
23 %seen = ();
24}
25
26while (<>) {
27 if (/^(disable )?([a-z_0-9]+)\(/) {
Markus Armbruster88ed34f2014-09-23 14:53:28 +020028 open GREP, '-|', 'git', 'grep', '-lw', "trace_$2"
Markus Armbrusterf0c03c82013-06-07 12:59:17 +020029 or die "run git grep: $!";
30 my $fname;
31 while ($fname = <GREP>) {
32 chomp $fname;
33 next if $seen{$fname} || $fname eq 'trace-events';
34 $seen{$fname} = 1;
35 $buf = "# $fname\n" . $buf;
36 }
37 unless (close GREP) {
38 die "close git grep: $!"
39 if $!;
40 next;
41 }
42 } elsif (/^# ([^ ]*\.[ch])$/) {
43 out;
44 next;
45 } elsif (!/^#|^$/) {
46 warn "unintelligible line";
47 }
48 $buf .= $_;
49}
50
51out;