fadfdd7f9b9df21b365069de6d2941181526f406
[tridge/openchange.git] / branches / plugfest / utils / mapitrace / mapitrace
1 #!/usr/bin/perl -w
2
3 ##############################################
4 # package to dump the mapi call hierarchy and
5 # add IDL regression support
6 #
7 # Copyright Julien Kerihuel 2007.
8 # <j.kerihuel@openchange.org>
9 #
10 # released under GNU GPL v3 or later
11
12 use strict;
13
14 use FindBin qw($RealBin $Script);
15 use lib "$RealBin";
16 use lib "$RealBin/lib";
17 #use lib "lib";
18 use MAPI::EcDoRpc;
19 use Getopt::Long;
20
21 my ($opt_help) = 0;
22 my ($opt_outputdir) = '.';
23 my ($opt_graph) = 0;
24 my ($opt_highlight) = 0;
25 my ($opt_trace) = 0;
26 my ($opt_search_call) = 0;
27 my ($opt_dump_call) = 0;
28 my ($opt_inout) = 0;
29 my ($opt_error) = 0;
30 my ($opt_stats) = 0;
31 my ($opt_verbose) = 0;
32 ############################################
33 # display help text
34 sub ShowHelp()
35 {
36     print "mapi call hierarchy tracing tool and IDL regression support
37 Copyright (C) Julien Kerihuel <j.kerihuel\@openchange.org>
38
39 Usage: $Script [options]
40
41 Generic Options:
42 --help                 this help page
43 --outputdir=OUTDIR     put output in OUTDIR/ []
44 --graph                create a png graph
45 --trace                dump the mapi call hierarchy on command line
46 --verbose              verbose output
47
48 Tracing Options:
49 --search-call=CALL     trace a single call through a scenario
50 --dump-call            dump all the packets containing the call specified
51 --highlight=CALL       highlight a call in the generated graph
52 --inout=INOUT          filter either requests (in) or response (out)
53
54 Regression Options:
55 --error_report=in,out  Investigate invalid packets
56 --stats                Display statistics for a given scenario
57
58 \n";
59     exit (0);
60 }
61
62 # main program
63 my $result = GetOptions (
64                          'help|h|?' => \$opt_help,
65                          'outputdir=s' => \$opt_outputdir,
66                          'graph|g' => \$opt_graph,
67                          'highlight=s'=> \$opt_highlight,
68                          'trace|t' => \$opt_trace,
69                          'search-call=s' => \$opt_search_call,
70                          'dump-call|d' => \$opt_dump_call,
71                          'inout=s' => \$opt_inout,
72                          'error_report=s' => \$opt_error,
73                          'stats|s' => \$opt_stats,
74                          'verbose|v' => \$opt_verbose
75                          );
76
77 if (not $result) {
78     exit (1);
79 }
80
81 if ($opt_help) {
82     ShowHelp();
83     exit (0);
84 }
85
86 sub process_tracing($)
87 {
88     my $directory = shift;
89     my $outputdir = $opt_outputdir;
90     
91
92     opendir(DIR,$directory) or die "Unable to process $directory";
93     closedir(DIR);
94
95     my $EcDoRpc = MAPI::EcDoRpc->new($directory, $outputdir, $opt_verbose);
96
97     $EcDoRpc->ndrdump();
98     $EcDoRpc->analyze($opt_trace);
99
100     if ($opt_error) {
101         my @inout = split(/,/, $opt_error);
102
103         foreach (sort @inout) {
104             $EcDoRpc->error_report($_);
105         }
106     }
107     
108     $EcDoRpc->stats() if ($opt_stats);
109     $EcDoRpc->search_call($opt_search_call, $opt_dump_call, $opt_inout) if ($opt_search_call);
110     $EcDoRpc->graph($outputdir, $opt_highlight) if ($opt_graph);
111 }
112
113 if (scalar(@ARGV) == 0) {
114     print "$Script: no input directory\n";
115     exit (1);
116 }
117
118 process_tracing($_) foreach (@ARGV);