Devel-StatProfiler

 view release on metacpan or  search on metacpan

t/365_timeboxing.t  view on Meta::CPAN

#!/usr/bin/env perl

use t::lib::Test;
use t::lib::Slowops;

use Devel::StatProfiler::Aggregator;
use Time::HiRes qw(time);

my ($profile_dir, $template);
BEGIN { ($profile_dir, $template) = temp_profile_dir(); }

use Devel::StatProfiler -template => $template, -interval => 1000;

for (my $count = 1000; ; $count *= 2) {
    my $start = time;
    note("Trying with $count iterations");
    t::lib::Slowops::foo($count);
    -d '.' for 1..$count;
    last if time - $start >= 0.5;
}

Devel::StatProfiler::stop_profile();

my @files = glob "$template.*";
my ($process_id, $samples);

my $r1 = Devel::StatProfiler::Report->new(
    slowops => [qw(ftdir unstack)],
);
$r1->add_trace_file($_) for @files;

my $a1 = Devel::StatProfiler::Aggregator->new(
    root_directory  => File::Spec::Functions::catdir($profile_dir, 'aggr1'),
    shard           => 'shard1',
    slowops         => [qw(ftdir unstack)],
);
for my $file (@files) {
    my $r = Devel::StatProfiler::Reader->new($file);
    ($process_id) = @{$r->get_genealogy_info};
    for (;;) {
        my $sr = t::lib::Test::SingleReader->new($r);
        $a1->process_trace_files($sr);
        ++$samples;
        last if $sr->done;
    }
}
$a1->save_part;
my $r2 = $a1->merge_report('__main__');

my $a2 = Devel::StatProfiler::Aggregator->new(
    root_directory  => File::Spec::Functions::catdir($profile_dir, 'aggr2'),
    shard           => 'shard1',
    slowops         => [qw(ftdir unstack)],
    timebox         => 1,
);
my $sample_split = int($samples / 2);
my $sample_count;
for my $file (@files) {
    my $r = Devel::StatProfiler::Reader->new($file);
    for (;;) {
        my $sr = t::lib::Test::SingleReader->new($r);
        $a2->process_trace_files($sr);
        if ($sample_count++ == $sample_split) {
            $a2->save_part;
            $a2->merge_report('__main__');
            sleep 2; # different box
            $a2 = Devel::StatProfiler::Aggregator->new(
                root_directory  => File::Spec::Functions::catdir($profile_dir, 'aggr2'),
                shard           => 'shard1',
                slowops         => [qw(ftdir unstack)],
                timebox         => 1,
            );
        }
        last if $sr->done;
    }
}



( run in 1.166 second using v1.01-cache-2.11-cpan-4ab04211f4c )