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

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

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

  • Property svn:executable set to *
File size: 3.7 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 'processor-' . $ARGV[0] . '.log')
9{
10 print 'Error! Processor report not specified or file not found.' . "\n";
11 print 'Usage: poll-processor-report.pl <pid>' . "\n\n";
12 exit(0);
13}
14
15my $sort = 0;
16if (defined $ARGV[1] && $ARGV[1] eq 'sort')
17{
18 $sort = 1;
19}
20
21my $polling_pid = 0;
22if ($ARGV[0] =~ /^(\d+)$/)
23{
24 $polling_pid = $1;
25}
26else
27{
28 print 'Error! Processor report filename not valid.' . "\n";
29 print 'Usage: poll-processor-report.pl <pid>' . "\n\n";
30 exit(0);
31}
32
33open(FIN, '<:utf8', 'processor-' . $polling_pid . '.log') or die('Error! Failed to open file for reading: processor-' . $ARGV[0] . '.log');
34
35# We'll write out the results to a CSV for easy graphing!
36my $filename = 'processor-' . $polling_pid . '.csv';
37open(FOUT, '>:utf8', $filename) or die('Error! Failed to open file for writing: ' . $filename);
38print FOUT "Time,CPU0,CPU1,CPU2,CPU3,CPU4,CPU5,CPU6,CPU7\n";
39
40my $starttime = 0;
41my $timestamp = -1;
42my $found_data = 0;
43my $processor_data = {'cpu0'=>0.0,'cpu1'=>0.0,'cpu2'=>0.0,'cpu3'=>0.0,'cpu4'=>0.0,'cpu5'=>0.0,'cpu6'=>0.0,'cpu7'=>0.0};
44my $line = '';
45print 'Parsing log: ';
46while ($line = <FIN>)
47{
48 # Look for a timestamp to begin a polling entry
49 if ($line =~ /^(\d+):(\d+):(\d+)\s+(?:AM|PM)\s+0/)
50 {
51 # Write any existing data to file
52 if ($found_data == 1)
53 {
54 &printRecord($timestamp, $processor_data);
55 $found_data = 0;
56 }
57 if ($starttime == 0)
58 {
59 $starttime = $1 * 3600 + $2 * 60 + $3;
60 }
61 $timestamp = ($1 * 3600 + $2 * 60 + $3) - $starttime;
62 print 'T';
63 # Reset the data
64 $processor_data = {'cpu0'=>0.0,'cpu1'=>0.0,'cpu2'=>0.0,'cpu3'=>0.0,'cpu4'=>0.0,'cpu5'=>0.0,'cpu6'=>0.0,'cpu7'=>0.0};
65 }
66 # We only process other lines if we are in an entry
67 if ($timestamp >= 0 && $line =~ /^(?:\d+:\d+:\d+)\s+(?:AM|PM)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+.*\r?\n$/)
68 {
69 my $cpu = $1;
70 my $pusr = $2;
71 my $pnice = $3;
72 my $psys = $4;
73 $processor_data->{'cpu' . $cpu} = $pusr + $pnice + $psys;
74 $found_data = 1;
75 }
76}
77print "\n";
78# Write any remaining data to file
79if ($found_data == 1)
80{
81 &printRecord($timestamp, $processor_data);
82 $found_data = 0;
83}
84
85close(FOUT);
86close(FIN);
87
88print '===== Complete =====' . "\n";
89exit(0);
90
91# /**
92# */
93sub printRecord
94{
95 my ($time_elapsed, $processor_data) = @_;
96 print FOUT sprintf('% 5.1f', $time_elapsed) . ',';
97 # Unsorted just prints out the actual CPU loads
98 if (!$sort)
99 {
100 print FOUT sprintf('% 5.1f', $processor_data->{'cpu0'}) . ',';
101 print FOUT sprintf('% 5.1f', $processor_data->{'cpu1'}) . ',';
102 print FOUT sprintf('% 5.1f', $processor_data->{'cpu2'}) . ',';
103 print FOUT sprintf('% 5.1f', $processor_data->{'cpu3'}) . ',';
104 print FOUT sprintf('% 5.1f', $processor_data->{'cpu4'}) . ',';
105 print FOUT sprintf('% 5.1f', $processor_data->{'cpu5'}) . ',';
106 print FOUT sprintf('% 5.1f', $processor_data->{'cpu6'}) . ',';
107 print FOUT sprintf('% 5.1f', $processor_data->{'cpu7'});
108 print FOUT "\n";
109 }
110 else
111 {
112 my @values = (sprintf('% 5.1f', $processor_data->{'cpu0'}),
113 sprintf('% 5.1f', $processor_data->{'cpu1'}),
114 sprintf('% 5.1f', $processor_data->{'cpu2'}),
115 sprintf('% 5.1f', $processor_data->{'cpu3'}),
116 sprintf('% 5.1f', $processor_data->{'cpu4'}),
117 sprintf('% 5.1f', $processor_data->{'cpu5'}),
118 sprintf('% 5.1f', $processor_data->{'cpu6'}),
119 sprintf('% 5.1f', $processor_data->{'cpu7'})
120 );
121 print FOUT join(',', sort {$b <=> $a} @values) . "\n";
122 }
123}
124# /** printRecord() **/
Note: See TracBrowser for help on using the repository browser.