#! /usr/local/bin/perl -n

# Run with
#    doc/junk/speeds-summary.pl atr-debug-logs/* > speeds.csv

use strict;
our ($last_created, $last_type);

# nb. we're in a "perl -n" loop

next unless s/^(\d+)\b.*Info: Speed//;
my $when = $1;

if (/^: (\w+) (recycled|created)$/) {
    $last_type = $1;
    $last_created = ($2 eq 'recycled') ? 1 : 0;
    next;
}

next unless /go_string\(([^()]+)\) ([\d.]+) wallclock.*\s([\d.]+) CPU\)/;
my ($str, $wall, $cpu) = ($1, $2, $3);
my @local = localtime($when);
my $date = sprintf("%d-%02d-%02d", (1900+$local[5]), (1+$local[4]), $local[3]);
my $time = sprintf("%02d:%02d:%02d", @local[2,1,0]);

BEGIN { print qq{unixtime,date,time,widget,"recycled?",string,"wall/sec","cpu/sec"\n} }

print qq{$when,$date,$time,"$last_type",$last_created,"$str",$wall,$cpu\n};
