summaryrefslogtreecommitdiff
path: root/ghc/utils/parallel/sn_filter.pl
blob: 4bfc2d17214216e47d1e1238e10699aa537f393e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/local/bin/perl
# ############################################################################
# Time-stamp: <Wed Jun 19 1996 12:26:21 Stardate: [-31]7682.38 hwloidl>
#
# Usage: sn_filter [options] <gr-file> <sn>
#
# Extract all events out of <gr-file> that are related to threads whose 
# spark name component is <sn>.
# 
# Options:
#  -H       ... Print header of the <gr-file>, too
#  -h       ... print help message (this text)
#  -v       ... be talkative
#
# ############################################################################

$gran_dir = $ENV{'GRANDIR'};
if ( $gran_dir eq "" ) {
    print STDERR "Warning: Env variable GRANDIR is undefined\n";
}

push(@INC, $gran_dir, $gran_dir . "/bin");
# print STDERR "INC: " . join(':',@INC) . "\n";

require "get_SN";
require "getopts.pl";

&Getopts('hvH');  

do process_options();
if ( $opt_v ) { do print_verbose_message(); }

# ----------------------------------------------------------------------------

do get_SN($input);

open (FILE,$input) || die "Can't open $file\n";

$in_header = 1;
while (<FILE>) {
    print  if $in_header && $opt_H;
    $in_header = 0 if /^\++$/;
    next if $in_header;
    next unless /^PE\s*\d+\s*\[\d+\]:\s*\w*\s*([0-9a-fx]+)/;
    $id = $1;
    # print STDERR "$id --> " . $id2sn{hex($id)} . " sn: $sn  ==> " . ($sn eq $id2sn{hex($id)}) . "\n";
    print if $sn == $id2sn{hex($id)};
}
	
close (FILE);

exit 0;

# ----------------------------------------------------------------------------

sub process_options { 

    if ( $#ARGV != 1 ) {
	die "Usage: sn_filter <gr-file> <sn>\n";
    }
	
    $input = $ARGV[0];
    $sn = $ARGV[1];

    print STDERR "File: |$file|; sn: |$sn|\n"  if $opt_v;

 if ( $opt_h ) {
     open (ME,$0) || die "!$: $0";
     while (<ME>) {
	 last if /^$/;
	 print;
     }
     close (ME);
     exit 1;
 }
}

# ----------------------------------------------------------------------------

sub print_verbose_message { 

    print "Input: $input\tOutput: stdout\tSN: $sn\n";
    if ( $opt_H ) {
	print "Prepending .gr header to the output.\n";
    }

}

# ----------------------------------------------------------------------------