Takumi Akiyama 🍙🍙🍙
and 2 contributors

NAME

Plack::ServerTiming - Frontend for Plack::Middleware::ServerTiming

SYNOPSIS

    use Plack::ServerTiming;

    builder {
        enable 'ServerTiming';
        sub {
            my $env = shift;
            my $t = Plack::ServerTiming->new($env);
            sleep 1;
            $t->record_timing('miss');
            $t->record_timing(sleep => {dur => 1000, desc => 'Sleep one second...'});
            [200, ['Content-Type','text/html'], ["OK"]];
        };
    };

DESCRIPTION

This module provides high level API for Plack::Middleware::ServerTiming.

METHODS

$timing = Plack::ServerTiming->new($env)

This will create a new instance of Plack::SeverTiming.

$timing->record_timing($name, {dur => $duration, desc => $description})

record_timing() adds a metric consisting of name, duration and description.

    $timing->record_timing('total', {dur => 123.4});
$timing->guard($name, $description)

guard() creates a guard instance to record a duration. This will add a elapsed time until exit the scope as metric.

    {
        my $g = $timing->guard('elapsed', 'sleep 1');
        sleep 1;
    }
    # `elapsed;dur=1000.224;desc="sleep 1"`

SEE ALSO

Plack::Middleware::ServerTiming

LICENSE

Copyright (C) Takumi Akiyama.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Takumi Akiyama <t.akiym@gmail.com>