File: make_csv.pl

package info (click to toggle)
bmt 0.6-1
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 324 kB
  • sloc: perl: 1,711; sh: 828; makefile: 90
file content (272 lines) | stat: -rwxr-xr-x 9,920 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/perl -w
#
# Copyright (c) 2011 Michael Tautschnig <michael.tautschnig@comlab.ox.ac.uk>
#               2015 Michael Tautschnig <michael.tautschnig@qmul.ac.uk>
# 
# All rights reserved. Redistribution and use in source and binary forms, with
# or without modification, are permitted provided that the following
# conditions are met:
# 
#   1. Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
# 
#   2. Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
# 
#   3. All advertising materials mentioning features or use of this software
#      must display the following acknowledgement:
# 
#      This product includes software developed by Michael Tautschnig,
#      Queen Mary University of London
# 
#   4. Neither the name of the University nor the names of its contributors
#      may be used to endorse or promote products derived from this software
#      without specific prior written permission.
# 
#    
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS `AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


# build a CSV table of results

use strict;
use warnings FATAL => qw(uninitialized);

sub usage {
  print <<"EOF";
Usage: $0 TOOL RESULTS
  where TOOL specifies the log parser to be used an RESULTS lists log files
  produced by verify.sh

EOF
}

if (scalar(@ARGV) != 2) {
  usage;
  exit 1;
}

my $config = $ARGV[0];
my $file = $ARGV[1];

use File::Basename qw(dirname);
use lib dirname($0);
use lib "cprover/";
require "parse-$config.pl";

sub parse_description {
  my ($LOG, $hash) = @_;
  my $mode = "";

  while (<$LOG>) {
    chomp;
    return 1 if (/^###############################################################################$/);

    $mode = "uname", next if (/^### uname -a:$/);
    $mode = "cpuinfo", next if (/^### cat \/proc\/cpuinfo:$/);
    $mode = "cpuinfo_osx", next if (/^### \/usr\/sbin\/system_profiler -detailLevel full SPHardwareDataType:$/);
    $mode = "meminfo", next if (/^### cat \/proc\/meminfo:$/);
    $mode = "meminfo_osx", next if (/^### \/usr\/sbin\/system_profiler -detailLevel full SPMemoryDataType:$/);
    $mode = "date", next if (/^### date:$/);
    $mode = "user", next if (/^### user:$/);
    $mode = "ulimit", next if (/^### ulimit -a:$/);
    $mode = "timeout", next if (/^### timeout:$/);
    $mode = "version", next if (/^### tool version info:$/);
    $mode = "command", next if (/^### tool command:$/);
    $mode = "commandline", next if (/^### full command line:$/);
    $mode = "expected", next if (/^### expected verification result:$/);

    if ($mode eq "uname") {
      /^(\S+)\s+(\S+)\s+(\S+)\s+/ or die "Unexpected uname output\n";
      $hash->{$mode} = "$1 $3";
    } elsif ($mode eq "cpuinfo") {
      defined($hash->{$mode}) or $hash->{$mode} = "0x XXX \@\@YYYMHz";
      /^(processor\s*:\s*(\d+))|(model name\s*:\s*(.*))|(cpu MHz\s*:\s*(.*))$/ or next;
      if (defined($2)) {
        ($hash->{$mode} =~ /^(\d+)(x .*)$/) or die "Invalid cpu def\n";
        $hash->{$mode} = ($1 + 1) . $2;
      } elsif (defined($4)) {
        my $model = $4;
        ($hash->{$mode} =~ /^(\d+)x (.*) @@(.*)MHz$/) or die "Invalid cpu def\n";
        ($2 eq "XXX") or ($2 eq $model) or die "NUMA system with both $model and $2 not supported\n";
        $hash->{$mode} = "$1x $model \@\@$3MHz";
      } elsif (defined($6)) {
        my $freq = $6;
        ($hash->{$mode} =~ /^(\d+)x (.*) @@(.*)MHz$/) or die "Invalid cpu def\n";
        $hash->{$mode} = "$1x $2 \@\@${freq}MHz";
      }
    } elsif ($mode eq "cpuinfo_osx") {
      defined($hash->{cpuinfo}) or $hash->{cpuinfo} = "1x XXX \@\@YYYMHz";
      if (/^\s+Processor Name: (.*)$/) {
        my $model = $1;
        $hash->{cpuinfo} =~ s/XXX/$model/;
      } elsif (/^\s+Processor Speed: (.*) GHz$/) {
        my $freq = $1 * 1000;
        $hash->{cpuinfo} =~ s/YYY/$freq/;
      } elsif (/^\s+(Number Of Processors|Total Number Of Cores): (\d+)$/) {
        my $count = $2;
        ($hash->{cpuinfo} =~ /^(\d+)(x .*)$/) or die "Invalid cpu def\n";
        $hash->{cpuinfo} = ($1 * $count) . $2;
      }
    } elsif ($mode eq "meminfo") {
      /^MemTotal:\s+(\d+) kB/ or next;
      $hash->{$mode} = "$1kb";
    } elsif ($mode eq "meminfo_osx") {
      defined($hash->{meminfo}) or $hash->{meminfo} = "0kb";
      /^\s+Size:\s+(\d+)\s+GB/ or next;
      my $banksize = $1 * 1024 * 1024;
      ($hash->{meminfo} =~ /^(\d+)kb$/) or die "Invalid mem info\n";
      $hash->{meminfo} = ($1 + $banksize) . "kb";
    } elsif ($mode eq "date") {
      $hash->{$mode} = "$_";
    } elsif ($mode eq "user") {
      $hash->{$mode} = "$_";
    } elsif ($mode eq "ulimit") {
      /^virtual memory\s+\(kbytes, -v\) (unlimited|\d+)$/ or next;
      $hash->{memlimit} = "$1kb";
    } elsif ($mode eq "timeout") {
      /^(\s*|timeout -(s SIGINT|2) (\d+))$/ or die "Unexpected timeout format\n";
      $hash->{$mode} = defined($3) ? "$3s" : "-";
    } elsif ($mode eq "version") {
      $hash->{$mode} = "$_";
    } elsif ($mode eq "command") {
      $hash->{$mode} = "$_";
    } elsif ($mode eq "commandline") {
      $hash->{$mode} = "$_";
    } elsif ($mode eq "expected") {
      $hash->{$mode} = "$_";
    } else {
      die "Don't know what to do in mode $mode\n";
    }
  }
}

sub parse_exit {
  my ($LOG, $hash) = @_;
  my $mode = "";

  while (<$LOG>) {
    chomp;

    $mode = "exitcode", next if (/^### exit code:$/);
    $mode = "time", next if (/^### \/usr\/bin\/time -v:$/);
    $mode = "time_osx", next if (/^### \/usr\/bin\/time -l:$/);

    if ($mode eq "exitcode") {
      #/^(\d+)$/ or die "Unexpected exit code format\n";
      /^(\d+)$/ or next;
      $hash->{$mode} = $1;
      if ($1 == 124) {
        $hash->{Result} = "TIMEOUT";
      }
    } elsif ($mode eq "time") {
      if (/^\s+User time \(seconds\): (\d+\.\d+)$/) {
        $hash->{usertime} = $1;
      } elsif (/^\s+Elapsed \(wall clock\) time \(h:mm:ss or m:ss\): ((\d+:)?\d+:\d+\.\d+)$/) {
        $hash->{wallclock} = $1;
      } elsif (/^\s+Maximum resident set size \(kbytes\): (\d+)$/) {
        $hash->{maxmem} = "$1kb";
      } elsif (/^SC_time:\s+(\d+\.\d+)$/) {
        $hash->{sc_time} = "$1";
        defined($hash->{usertime}) and
        $hash->{overhead} = $hash->{usertime}/$1;
      }
    } elsif ($mode eq "time_osx") {
      if (/^\s+(\d+\.\d+)\s+real\s+(\d+\.\d+)\s+user\s+(\d+\.\d+)\s+sys$/) {
        $hash->{usertime} = $2;
        $hash->{wallclock} = $1;
      } elsif (/^\s+(\d+)\s+maximum resident set size$/) {
        $hash->{maxmem} = ($1/1024) . "kb";
      }
    } else {
      die "Don't know what to do in mode $mode\n";
    }
  }
}

sub parse_file {
  my ($file, $hash) = @_;
  open my $LOG, "<$file" or die "Logfile $file not found\n";

  &parse_description($LOG, $hash);
  &parse_log($LOG, $hash);
  &parse_exit($LOG, $hash);

  close $LOG;
}

my %results = ();

open RESULTS, "<$file" or die "File $file not found\n";
while (<RESULTS>) {
  chomp;
  next unless (/^LOGFILE:\s+(\S+)$/);
  print STDERR "Parsing $1\n";
  defined($results{$1}) and die "Duplicate log file $1\n";
  my $fname = $1;
  $results{$fname} = ();
  my $bm_name = $fname;
  if ($bm_name =~ /^.*\/results\.[^\/]+\/(\S+)\.[a-z]+_(\S+)_\d{4}-\d\d-\d\d_\d{6}_.{6}\.log$/)
  {
    $bm_name = ($2 eq "ALL_CLAIMS") ? $1 : "$1:$2";
  }
  elsif ($bm_name =~ /^.*\/(tests|results\.[^\/]+)\/([^\/]+).*(\/[a-z]+\/([^\/_]+\d+|iriw[^\/_]+))_([a-z]+(.oepc)?).*_(\S+)_\d{4}-\d\d-\d\d_\d{6}_.{6}\.log$/)
  {
    $bm_name = ($7 eq "CLAIMS" || $7 eq "ALL_CLAIMS" || $7 eq "main.1") ? "$2$3($5)" : "$2$3($5):$7";
    defined($6) and $bm_name =~ s/\)/) 1d/;
  }
  elsif ($bm_name =~ /^.*\/(tests|results\.[^\/]+)\/([^\/]+).*(\/[a-z]+\/([^\/_]+\d+|iriw[^\/_]+))\.goto_(\S+)_\d{4}-\d\d-\d\d_\d{6}_.{6}\.log$/)
  {
    ($config eq "cbmc") or die "Benchmark name only acceptable for cbmc\n";
    my $mm = `grep memory-model $fname | sed 's/.*memory-model //' | awk '{ print \$1 }' | head -n 1`;
    chomp $mm;
    $bm_name = ($5 eq "CLAIMS" || $5 eq "ALL_CLAIMS" || $5 eq "main.1") ? "$2$3($mm)" : "$2$3($mm):$5";
    defined($4) and $bm_name =~ s/\)/) 1d/;
    ($mm =~ /^(sc|tso|pso|rmo|power)(\.oepc)?$/) or die "Invalid memory model $mm\n";
  }
  else
  {
    die "Don't know how to extract benchmark name from log file name $fname\n";
  }
  $results{$fname}{Benchmark} = $bm_name;
  # default to ERROR
  $results{$fname}{Result} = "ERROR";
  &parse_file($fname, \%{ $results{$fname} });
}
close RESULTS;

my %all_fields = ();
foreach my $f (keys %results) {
  $all_fields{$_} = 1 foreach (keys %{ $results{$f} });
}

use Text::CSV;
my $csv = Text::CSV->new();

my @headings = sort keys %all_fields;
unshift @headings, "Log File";
$csv->combine(@headings) or die "Error: ".$csv->error_input()."\n";
print $csv->string() . "\n";

foreach my $f (sort keys %results) {
  my @row = ();
  push @row, $f;
  foreach my $field (sort keys %all_fields) {
    push @row, defined($results{$f}{$field}) ? 
      $results{$f}{$field} : "";
  }
  $csv->combine(@row) or die "Error: ".$csv->error_input()."\n";
  print $csv->string() . "\n";
}