Skip to content

Commit

Permalink
bin/bmark_pq: refactor for multiple output formats
Browse files Browse the repository at this point in the history
For now, CSV is the only output format, but we now have a reasonable place
to add more formats (once we also have enough support code to make the
format selectable from the command line).
  • Loading branch information
arc committed Jan 8, 2012
1 parent b9d87ba commit 7b922be
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions bin/bmark_pq
Expand Up @@ -32,33 +32,48 @@ $out_fh = IO::File->new($out_file, 'w')
or die "Can't open $out_file for writing: $!\n"
if defined $out_file;

STDERR->autoflush(1);

{
my @results = run_workloads(
tasks => @tasks && \@tasks,
backends => @backends && \@backends,
ranks => \@ranks,
timeout => $timeout,
progress => $verbose && sub {
my %format_op = (
csv => {
start => sub { STDERR->autoflush(1) },
generate => sub {
my @results = @_;

print STDERR "\n" if $verbose;

# XXX: probably better to use a real CSV-generating module
local $\ = "\x0D\x0A"; # CSV uses CRLF
print $out_fh join ',',
qw<Task Backend Version Rank Iterations Seconds>;
for my $result (@results) {
print $out_fh join ',', map { $result->$_ }
qw<task backend backend_version rank iterations seconds>;
}
},
progress => sub {
my ($task, $backend, $rank) = @_;
return if !$verbose;
state $prev_task = '';
state $prev_backend = '';
print STDERR "\nRunning $task on $backend "
if $task ne $prev_task || $backend ne $prev_backend;
print STDERR '.';
($prev_task, $prev_backend) = ($task, $backend);
},
},
);

my ($format) = keys %format_op; # temporarily

{
$format_op{$format}{start}->();
my @results = run_workloads(
tasks => @tasks && \@tasks,
backends => @backends && \@backends,
ranks => \@ranks,
timeout => $timeout,
progress => $format_op{$format}{progress},
);
print STDERR "\n" if $verbose;

# XXX: probably better to use a real CSV-generating module
local $\ = "\x0D\x0A"; # CSV uses CRLF
print $out_fh join ',', qw<Task Backend Version Rank Iterations Seconds>;
for my $result (@results) {
print $out_fh join ',', map { $result->$_ }
qw<task backend backend_version rank iterations seconds>;
}
$format_op{$format}{generate}->(@results);
}

close $out_fh
Expand Down

0 comments on commit 7b922be

Please sign in to comment.