1#!/usr/local/bin/perl
2#
3# analyze_flowmonitor_debug
4#
5# analyze_flowmonitor_debug will parse the DEBUG_MONITOR_C debug file
6# created by FlowMonitor_Collector to search for segments of the code
7# that are taking longer than the specified cutoff time period. One
8# must specify the file name within this script ($search_file).
9
10use FlowViewer_Configuration;
11use FlowViewer_Utilities;
12use File::stat;
13use lib $cgi_bin_directory;
14
15$cutoff = $ARGV[0];  # defaults to 0.3 seconds
16$type   = $ARGV[1];  # "s" will limit to SiLK, "f" to flow-tools, "b" for both
17$out    = $ARGV[2];  # "all" will print every time_check line
18$high_cutoff  = 20;  # will skip any segment taking longer than this value
19
20if ($cutoff == 0) { $cutoff = 0.3; }
21
22$search_file = "/var/www/cgi-bin/FlowViewer_4.5/Flow_Working/DEBUG_MONITOR_C";
23
24$string = "\"SiLK|flow|FlowMonitor_Filters\"";
25$grep_command = "egrep $string $search_file";
26
27print "  \n  Analyzing file: $search_file\n";
28print "    Using cutoff: $cutoff\n\n";
29
30$first_running = 1;
31open(GREP,"$grep_command 2>&1|");
32while (<GREP>) {
33	chop;
34	if (/running:/) {
35		($left_part,$running_secs) = split(/running: /);
36		if ($first_running) { $start_running = $running_secs; $first_running = 0; }
37	}
38
39	if (/FlowMonitor_Filters/) {
40		($left_part,$right_part) = split(/\./);
41		$filter_name = substr($left_part,-30,30);
42	}
43	($left_half,$right_half) = split(/elapsed seconds:/,$_);
44	($left_part,$elapsed_secs,$right_part) = split(/\s+/,$right_half);
45	($start,$end) = split(/ to: /,$left_half);
46	if ($type eq "s") {
47		if (!($start =~ /SiLK/) || !($end =~ /SiLK/)) { next; }
48	} elsif ($type eq "f") {
49		if (!($start =~ /flow/) || !($end =~ /flow/)) { next; }
50	}
51	if ($out eq "all") {
52		print "  $filter_name  ";
53		print "  $_";
54		if ($elapsed_secs > $high_cutoff) { next; }
55		$excess = $elapsed_secs - $cutoff;
56		if ($elapsed_secs > $cutoff) { print " ***\n"; $total_secs += $elapsed_secs; $total_excess += $excess; } else { print "\n"; }
57	} else {
58		if ($elapsed_secs > $high_cutoff) { next; }
59		$excess = $elapsed_secs - $cutoff;
60		if ($elapsed_secs > $cutoff) { print "  $filter_name  "; print $_; $total_secs += $elapsed_secs; $total_excess += $excess; print "\n";}
61	}
62}
63$end_running = $running_secs;
64$total_running = $end_running - $start_running;
65
66$total_secs   = int($total_secs + 0.5);
67$total_excess = int($total_excess + 0.5);
68$total_running = int($total_running + 0.5);
69print "\n  Sum of elapsed times greater than cutoff: $total_secs secs.";
70print "\n   Sum of excess of cutoff for above times: $total_excess secs.\n";
71print "\n                            Total run time: $total_running secs.\n\n";
72