source: gs2-extensions/parallel-building/trunk/src/bin/script/poll-report.pl@ 30354

Last change on this file since 30354 was 24844, checked in by jmt12, 12 years ago

Script to take the raw output from poll-gsdl.pl and collate the figures into a useful CSV file

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6print '===== Analyze poll-gsdl.pl Output =====' . "\n";
7
8if (!defined($ARGV[0]) || !-f 'memory-' . $ARGV[0] . '.log')
9{
10 print 'Error! Memory report not specified or file not found.' . "\n";
11 print 'Usage: poll-report.pl <pid>' . "\n\n";
12 exit(0);
13}
14
15my $polling_pid = 0;
16if ($ARGV[0] =~ /^(\d+)$/)
17{
18 $polling_pid = $1;
19}
20else
21{
22 print 'Error! Memory report filename not valid.' . "\n";
23 print 'Usage: memreport.pl <pid>' . "\n\n";
24 exit(0);
25}
26
27open(FIN, '<:utf8', 'memory-' . $polling_pid . '.log') or die('Error! Failed to open file for reading: memory-' . $ARGV[0] . '.log');
28
29# We'll write out the results to a CSV for easy graphing!
30my $filename = 'memory-' . $polling_pid . '.csv';
31open(FOUT, '>:utf8', $filename) or die('Error! Failed to open file for writing: ' . $filename);
32print FOUT "Time,Type,CPU,PCPU,PMEM,Type,CPU,PCPU,PMEM\n";
33
34# We'll store the details for both interesting child processes of Greenstone
35# importing, namely import.pl and txt2tdb.
36my $starttime = 0;
37my $timestamp = -1;
38my $import_data = {'cpu'=>-1,'pcpu'=>0.0, 'pmem'=>0.0};
39my $tdb_data = {'cpu'=>-1,'pcpu'=>0.0, 'pmem'=>0.0};
40my $line = '';
41print 'Parsing log: ';
42while ($line = <FIN>)
43{
44 # Look for a timestamp to begin a polling entry
45 if ($line =~ /\[(\d+.\d+)\]/)
46 {
47 # Write any existing data to file
48 if ($import_data->{'cpu'} > -1)
49 {
50 &printRecord($timestamp, $import_data, $tdb_data);
51 }
52 if ($starttime == 0)
53 {
54 $starttime = $1;
55 }
56 $timestamp = $1 - $starttime;
57 print 'T';
58 # Reset the data
59 $import_data = {'cpu'=>-1,'pcpu'=>0.0, 'pmem'=>0.0};
60 $tdb_data = {'cpu'=>-1,'pcpu'=>0.0, 'pmem'=>0.0};
61 }
62 # We only process other lines if we are in an entry
63 # - lines of the form: <pid> <cpu> <%cpu> <%mem> <cmd>
64 elsif ($timestamp >= 0 && $line =~ /^\s*(\d+)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(.*)\r?\n$/)
65 {
66 my $pid = $1;
67 my $cpu = $2;
68 my $pcpu = $3;
69 my $pmem = $4;
70 my $cmd = $5;
71
72 # There are two processes we are interested in:
73 # 1. The import process itself
74 if ($cmd =~ /^\/usr\/bin\/perl\s+.*import\.pl.+/)
75 {
76 print '.';
77 $import_data->{'cpu'} = $cpu;
78 $import_data->{'pcpu'} += $pcpu;
79 $import_data->{'pmem'} += $pmem;
80 }
81 # 2. The TDB process
82 elsif ($cmd =~ /^txt2tdb/)
83 {
84 print '.';
85 $tdb_data->{'cpu'} = $cpu;
86 $tdb_data->{'pcpu'} += $pcpu;
87 $tdb_data->{'pmem'} += $pmem;
88 }
89 }
90}
91print "\n";
92# Write any remaining data to file
93if ($import_data->{'cpu'} > -1)
94{
95 &printRecord($timestamp, $import_data, $tdb_data);
96}
97
98close(FOUT);
99close(FIN);
100
101print '===== Complete =====' . "\n";
102exit(0);
103
104# /**
105# */
106sub printRecord
107{
108 my ($timestamp, $import_data, $tdb_data) = @_;
109 print FOUT sprintf('% 5.1f', $timestamp) . ',';
110 print FOUT 'IMPORT,';
111 print FOUT sprintf('% 2d', $import_data->{'cpu'}) . ',';
112 print FOUT sprintf('% 5.1f', $import_data->{'pcpu'}) . ',';
113 print FOUT sprintf('% 5.1f', $import_data->{'pmem'}) . ',';
114 print FOUT 'TDB,';
115 print FOUT sprintf('% 2d', $tdb_data->{'cpu'}) . ',';
116 print FOUT sprintf('% 5.1f', $tdb_data->{'pcpu'}) . ',';
117 print FOUT sprintf('% 5.1f', $tdb_data->{'pmem'}) . "\n";
118
119}
120# /** printRecord() **/
Note: See TracBrowser for help on using the repository browser.