1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | print '===== Analyze poll-gsdl.pl Output =====' . "\n";
|
---|
7 |
|
---|
8 | if (!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 |
|
---|
15 | my $sort = 0;
|
---|
16 | if (defined $ARGV[1] && $ARGV[1] eq 'sort')
|
---|
17 | {
|
---|
18 | $sort = 1;
|
---|
19 | }
|
---|
20 |
|
---|
21 | my $polling_pid = 0;
|
---|
22 | if ($ARGV[0] =~ /^(\d+)$/)
|
---|
23 | {
|
---|
24 | $polling_pid = $1;
|
---|
25 | }
|
---|
26 | else
|
---|
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 |
|
---|
33 | open(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!
|
---|
36 | my $filename = 'processor-' . $polling_pid . '.csv';
|
---|
37 | open(FOUT, '>:utf8', $filename) or die('Error! Failed to open file for writing: ' . $filename);
|
---|
38 | print FOUT "Time,CPU0,CPU1,CPU2,CPU3,CPU4,CPU5,CPU6,CPU7\n";
|
---|
39 |
|
---|
40 | my $starttime = 0;
|
---|
41 | my $timestamp = -1;
|
---|
42 | my $found_data = 0;
|
---|
43 | my $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};
|
---|
44 | my $line = '';
|
---|
45 | print 'Parsing log: ';
|
---|
46 | while ($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 | }
|
---|
77 | print "\n";
|
---|
78 | # Write any remaining data to file
|
---|
79 | if ($found_data == 1)
|
---|
80 | {
|
---|
81 | &printRecord($timestamp, $processor_data);
|
---|
82 | $found_data = 0;
|
---|
83 | }
|
---|
84 |
|
---|
85 | close(FOUT);
|
---|
86 | close(FIN);
|
---|
87 |
|
---|
88 | print '===== Complete =====' . "\n";
|
---|
89 | exit(0);
|
---|
90 |
|
---|
91 | # /**
|
---|
92 | # */
|
---|
93 | sub 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() **/
|
---|