Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed POE::Resource::Performance to POE::Resource::Statistics. The

new form follows the POE::Resource::{plural thingy here} naming
convention, and it opens the door for gathering statistics that may
have nothing to do with performance.  TRACE_PERFORMANCE has also been
renamed TRACE_STATISTICS.
  • Loading branch information...
commit 4a691fdf7c8ce6b1120a1adab9ec140763219f83 1 parent 6f2eca9
@rcaputo authored
View
2  MANIFEST
@@ -46,10 +46,10 @@ POE/Resource/Aliases.pm
POE/Resource/Events.pm
POE/Resource/Extrefs.pm
POE/Resource/FileHandles.pm
-POE/Resource/Performance.pm
POE/Resource/SIDs.pm
POE/Resource/Sessions.pm
POE/Resource/Signals.pm
+POE/Resource/Statistics.pm
POE/Resources.pm
POE/Session.pm
POE/Wheel.pm
View
52 lib/POE/Kernel.pm
@@ -143,7 +143,7 @@ sub EN_SCPOLL () { '_sigchld_poll' }
sub EN_SIGNAL () { '_signal' }
sub EN_START () { '_start' }
sub EN_STOP () { '_stop' }
-sub EN_PERF () { '_perftick' }
+sub EN_STAT () { '_stat_tick' }
# These are POE's event classes (types). They often shadow the event
# names themselves, but they can encompass a large group of events.
@@ -162,10 +162,10 @@ sub ET_CHILD () { 0x0080 } # _child
sub ET_SCPOLL () { 0x0100 } # _sigchild_poll
sub ET_ALARM () { 0x0200 } # Alarm events.
sub ET_SELECT () { 0x0400 } # File activity events.
-sub ET_PERF () { 0x0800 } # Performance polling
+sub ET_STAT () { 0x0800 } # Statistics gathering
# A mask for all events generated by/for users.
-sub ET_MASK_USER () { ~(ET_GC | ET_SCPOLL | ET_PERF) }
+sub ET_MASK_USER () { ~(ET_GC | ET_SCPOLL | ET_STAT) }
# Temporary signal subtypes, used during signal dispatch semantics
# deprecation and reformation.
@@ -179,7 +179,7 @@ sub ET_SIGNAL_COMPATIBLE () { 0x1000 } # Backward-compatible semantics.
my %poes_own_events =
( EN_CHILD , 1, EN_GC , 1, EN_PARENT , 1, EN_SCPOLL , 1,
- EN_SIGNAL , 1, EN_START , 1, EN_STOP , 1, EN_PERF, 1,
+ EN_SIGNAL , 1, EN_START , 1, EN_STOP , 1, EN_STAT, 1,
);
# These are ways a child may come or go.
@@ -270,7 +270,7 @@ BEGIN {
defined &TRACE_DEFAULT or eval "sub TRACE_DEFAULT () { 0 }";
define_trace qw(
- EVENTS FILES PERFORMANCE PROFILE REFCNT RETVALS SESSIONS SIGNALS
+ EVENTS FILES PROFILE REFCNT RETVALS SESSIONS SIGNALS STATISTICS
);
# See the notes for TRACE_DEFAULT, except read ASSERT and assert
@@ -281,7 +281,7 @@ BEGIN {
define_assert qw(DATA EVENTS FILES RETVALS USAGE);
}
-# This is a second BEGIN block so TRACE_PERFORMANCE may be defined
+# This is a second BEGIN block so TRACE_STATISTICS may be defined
# already.
BEGIN {
@@ -653,11 +653,11 @@ sub new {
# Initialize subsystems. The order is important.
# We need events before sessions, and the kernel's session before
- # it can start polling for signals. Performance gathering
- # requires a polling event as well, so it goes late.
+ # it can start polling for signals. Statistics gathering requires
+ # a polling event as well, so it goes late.
$self->_data_ev_initialize($kr_queue);
$self->_initialize_kernel_session();
- $self->_data_perf_initialize() if TRACE_PERFORMANCE;
+ $self->_data_stat_initialize() if TRACE_STATISTICS;
$self->_data_sig_initialize();
# These other subsystems don't have strange interactions.
@@ -699,7 +699,7 @@ sub _dispatch_event {
my $local_event = $event;
- $self->_perf_profile($event) if TRACE_PROFILE;
+ $self->_stat_profile($event) if TRACE_PROFILE;
# Pre-dispatch processing.
@@ -846,7 +846,7 @@ sub _dispatch_event {
# Dispatch the event, at long last.
my $before;
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
$before = time();
}
my $return;
@@ -859,12 +859,12 @@ sub _dispatch_event {
$session->_invoke_state($source_session, $event, $etc, $file, $line);
}
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
my $after = time();
my $elapsed = $after - $before;
if ($type & ET_MASK_USER) {
- $self->_data_perf_add('user_seconds', $elapsed);
- $self->_data_perf_add('user_events', 1);
+ $self->_data_stat_add('user_seconds', $elapsed);
+ $self->_data_stat_add('user_events', 1);
}
}
@@ -978,7 +978,7 @@ sub finalize_kernel {
$self->_data_handle_finalize();
$self->_data_ev_finalize();
$self->_data_ses_finalize();
- $self->_data_perf_finalize() if TRACE_PROFILE or TRACE_PERFORMANCE;
+ $self->_data_stat_finalize() if TRACE_PROFILE or TRACE_STATISTICS;
}
sub run_one_timeslice {
@@ -1168,8 +1168,8 @@ sub _invoke_state {
}
}
- elsif ($event eq EN_PERF) {
- $self->_data_perf_tick();
+ elsif ($event eq EN_STAT) {
+ $self->_data_stat_tick();
}
return 0;
@@ -1190,7 +1190,7 @@ sub session_alloc {
if ($kr_run_warning & KR_RUN_DONE) {
$kr_run_warning &= ~KR_RUN_DONE;
$self->_initialize_kernel_session();
- $self->_data_perf_initialize() if TRACE_PERFORMANCE;
+ $self->_data_stat_initialize() if TRACE_STATISTICS;
$self->_data_sig_initialize();
}
@@ -3655,16 +3655,18 @@ elsewhere, set TRACE_FILENAME to the file where they should go.
TRACE_FILES enables or disables messages that tell how files are being
processed within POE::Kernel and the event loop bridges.
-=item TRACE_PERFORMANCE
+=item TRACE_STATISTICS
B<This feature is experimental. No doubt it will change.>
-This keeps track of how much time is spent processing event callbacks,
-time spent in POE, and time spent waiting for an event. A report is
-displayed just before run() returns, or the data can be retrieved at
-any time using perf_getdata().
+TRACE_STATISTICS enables runtime gathering and reporting of various
+performance metrics within a POE program. Some statistics include how
+much time is spent processing event callbacks, time spent in POE's
+dispatcher, and the time spent waiting for an event. A report is
+displayed just before run() returns, and the data can be retrieved at
+any time using stat_getdata().
-perf_getdata() returns a hashref of various statistics and their
+stat_getdata() returns a hashref of various statistics and their
values. The statistics are calculated using a sliding window and vary
over time as a program runs.
@@ -3673,7 +3675,7 @@ over time as a program runs.
TRACE_PROFILE switches on event profiling. This causes the Kernel to
keep a count of every event it dispatches. A report of the events and
their frequencies is displayed just before run() returns, or at
-any time via perf_show_profile().
+any time via stat_show_profile().
=item TRACE_REFCNT
View
6 lib/POE/Loop/Event.pm
@@ -208,12 +208,12 @@ my $last_time = time();
sub _loop_event_callback {
my $self = $poe_kernel;
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
# TODO - I'm pretty sure the startup time will count as an unfair
# amout of idleness.
#
# TODO - Introducing many new time() syscalls. Bleah.
- $self->_data_perf_add('idle_seconds', time() - $last_time);
+ $self->_data_stat_add('idle_seconds', time() - $last_time);
}
$self->_data_ev_dispatch_due();
@@ -242,7 +242,7 @@ sub _loop_event_callback {
}
# Transfering control back to Event; this is idle time.
- $last_time = time() if TRACE_PERFORMANCE;
+ $last_time = time() if TRACE_STATISTICS;
}
# Event filehandle callback to dispatch selects.
View
6 lib/POE/Loop/Gtk.pm
@@ -216,12 +216,12 @@ my $last_time = time();
sub _loop_event_callback {
my $self = $poe_kernel;
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
# TODO - I'm pretty sure the startup time will count as an unfair
# amout of idleness.
#
# TODO - Introducing many new time() syscalls. Bleah.
- $self->_data_perf_add('idle_seconds', time() - $last_time);
+ $self->_data_stat_add('idle_seconds', time() - $last_time);
}
$self->_data_ev_dispatch_due();
@@ -236,7 +236,7 @@ sub _loop_event_callback {
}
# And back to Gtk, so we're in idle mode.
- $last_time = time() if TRACE_PERFORMANCE;
+ $last_time = time() if TRACE_STATISTICS;
# Return false to stop.
return 0;
View
4 lib/POE/Loop/IO_Poll.pm
@@ -343,8 +343,8 @@ sub loop_do_timeslice {
}
}
- if (TRACE_PERFORMANCE) {
- $self->_data_perf_add('idle_seconds', time() - $now);
+ if (TRACE_STATISTICS) {
+ $self->_data_stat_add('idle_seconds', time() - $now);
}
# Dispatch whatever events are due.
View
4 lib/POE/Loop/Select.pm
@@ -312,13 +312,13 @@ sub loop_do_timeslice {
}
}
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
# TODO - I think $now is too far ahead of select() and this call
# is too far afterwards. Unless "idle" seconds means also the
# time POE::Kernel spends scheduling things. Sent a note to Nick
# Williams asking for clarification on the definitions of various
# statistics.
- $self->_data_perf_add('idle_seconds', time() - $now);
+ $self->_data_stat_add('idle_seconds', time() - $now);
}
# Dispatch whatever events are due.
View
6 lib/POE/Loop/TkCommon.pm
@@ -78,12 +78,12 @@ sub loop_pause_time_watcher {
my $last_time = time();
sub _loop_event_callback {
- if (TRACE_PERFORMANCE) {
+ if (TRACE_STATISTICS) {
# TODO - I'm pretty sure the startup time will count as an unfair
# amout of idleness.
#
# TODO - Introducing many new time() syscalls. Bleah.
- $poe_kernel->_data_perf_add('idle_seconds', time() - $last_time);
+ $poe_kernel->_data_stat_add('idle_seconds', time() - $last_time);
}
$poe_kernel->_data_ev_dispatch_due();
@@ -143,7 +143,7 @@ sub _loop_event_callback {
}
# And back to Tk, so we're in idle mode.
- $last_time = time() if TRACE_PERFORMANCE;
+ $last_time = time() if TRACE_STATISTICS;
}
#------------------------------------------------------------------------------
View
4 lib/POE/Resource/Events.pm
@@ -238,8 +238,8 @@ sub _data_ev_dispatch_due {
}
if ($time < $now) {
- $self->_data_perf_add('blocked', 1);
- $self->_data_perf_add('blocked_seconds', $now - $time);
+ $self->_data_stat_add('blocked', 1);
+ $self->_data_stat_add('blocked_seconds', $now - $time);
}
$self->_data_ev_refcount_dec($event->[EV_SOURCE], $event->[EV_SESSION]);
View
109 lib/POE/Resource/Performance.pm → lib/POE/Resource/Statistics.pm
@@ -1,11 +1,11 @@
# $Id$
-# Data and methods to manage performance metrics, allowing clients to
-# look at how much work their POE server is performing.
-# None of this stuff will activate unless TRACE_PERFORMANCE or
+# Data and methods to collect runtime statistics about POE, allowing
+# clients to look at how much work their POE server is performing.
+# None of this stuff will activate unless TRACE_STATISTICS or
# TRACE_PROFILE are enabled.
-package POE::Resources::Performance;
+package POE::Resources::Statistics;
use vars qw($VERSION);
$VERSION = do {my@r=(q$Revision$=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
@@ -18,34 +18,36 @@ use strict;
# We keep a number of metrics (idle time, user time, etc).
# Every tick (by default 30secs), we compute the rolling average
# of those metrics. The rolling average is computed based on
-# the number of readings specified in $_perf_window_size.
+# the number of readings specified in $_stat_window_size.
-my $_perf_metrics = []; # the data itself
-my $_perf_interval = 30; # how frequently we take readings
-my $_perf_window_size = 4; # how many readings we average across
-my $_perf_wpos = 0; # where to currrently write metrics (circ. buffer)
-my $_perf_rpos = 0; # where to currrently write metrics (circ. buffer)
+my $_stat_metrics = []; # the data itself
+my $_stat_interval = 30; # how frequently we take readings
+my $_stat_window_size = 4; # how many readings we average across
+my $_stat_wpos = 0; # where to currrently write metrics (circ. buffer)
+my $_stat_rpos = 0; # where to currrently write metrics (circ. buffer)
my %average;
# This is for collecting event frequencies if TRACE_PROFILE is
# enabled.
my %profile;
-sub _data_perf_initialize {
+sub _data_stat_initialize {
my ($self) = @_;
- $self->_data_perf_reset;
+ $self->_data_stat_reset;
$self->_data_ev_enqueue(
- $self, $self, EN_PERF, ET_PERF, [ ],
- __FILE__, __LINE__, time() + $_perf_interval
+ $self, $self, EN_STAT, ET_STAT, [ ],
+ __FILE__, __LINE__, time() + $_stat_interval
);
}
-sub _data_perf_finalize {
+sub _data_stat_finalize {
my ($self) = @_;
- $self->_data_perf_tick();
+ $self->_data_stat_tick();
- if (TRACE_PERFORMANCE) {
- POE::Kernel::_warn('<pr> ,----- Performance Data ' , ('-' x 50), ",\n");
+ if (TRACE_STATISTICS) {
+ POE::Kernel::_warn(
+ '<pr> ,----- Observed Statistics ' , ('-' x 50), ",\n"
+ );
foreach (sort keys %average) {
next if /epoch/;
POE::Kernel::_warn(
@@ -63,7 +65,7 @@ sub _data_perf_finalize {
$average{user_events} ||= 1;
POE::Kernel::_warn(
- '<pr> +----- Derived Performance Metrics ', ('-' x 39), "+\n",
+ '<pr> +----- Derived Statistics ', ('-' x 39), "+\n",
sprintf(
"<pr> | %60.60s %9.1f%% |\n",
'idle', 100 * $average{avg_idle_seconds} / $average{interval}
@@ -85,36 +87,36 @@ sub _data_perf_finalize {
}
if (TRACE_PROFILE) {
- perf_show_profile();
+ stat_show_profile();
}
}
-sub _data_perf_add {
+sub _data_stat_add {
my ($self, $key, $count) = @_;
- $_perf_metrics->[$_perf_wpos] ||= {};
- $_perf_metrics->[$_perf_wpos]->{$key} += $count;
+ $_stat_metrics->[$_stat_wpos] ||= {};
+ $_stat_metrics->[$_stat_wpos]->{$key} += $count;
}
-sub _data_perf_tick {
+sub _data_stat_tick {
my ($self) = @_;
- my $pos = $_perf_rpos;
- $_perf_wpos = ($_perf_wpos+1) % $_perf_window_size;
- if ($_perf_wpos == $_perf_rpos) {
- $_perf_rpos = ($_perf_rpos+1) % $_perf_window_size;
+ my $pos = $_stat_rpos;
+ $_stat_wpos = ($_stat_wpos+1) % $_stat_window_size;
+ if ($_stat_wpos == $_stat_rpos) {
+ $_stat_rpos = ($_stat_rpos+1) % $_stat_window_size;
}
my $count = 0;
%average = ();
my $epoch = 0;
- while ($count < $_perf_window_size && $_perf_metrics->[$pos]->{epoch}) {
- $epoch = $_perf_metrics->[$pos]->{epoch} unless $epoch;
- while (my ($k,$v) = each %{$_perf_metrics->[$pos]}) {
+ while ($count < $_stat_window_size && $_stat_metrics->[$pos]->{epoch}) {
+ $epoch = $_stat_metrics->[$pos]->{epoch} unless $epoch;
+ while (my ($k,$v) = each %{$_stat_metrics->[$pos]}) {
next if $k eq 'epoch';
$average{$k} += $v;
}
$count++;
- $pos = ($pos+1) % $_perf_window_size;
+ $pos = ($pos+1) % $_stat_window_size;
}
if ($count) {
@@ -124,15 +126,15 @@ sub _data_perf_tick {
$average{interval} = ($now - $epoch) / $count;
}
- $self->_data_perf_reset;
+ $self->_data_stat_reset;
$self->_data_ev_enqueue(
- $self, $self, EN_PERF, ET_PERF, [ ],
- __FILE__, __LINE__, time() + $_perf_interval
+ $self, $self, EN_STAT, ET_STAT, [ ],
+ __FILE__, __LINE__, time() + $_stat_interval
) if $self->_data_ses_count() > 1;
}
-sub _data_perf_reset {
- $_perf_metrics->[$_perf_wpos] = {
+sub _data_stat_reset {
+ $_stat_metrics->[$_stat_wpos] = {
epoch => time,
idle_seconds => 0,
user_seconds => 0,
@@ -143,18 +145,18 @@ sub _data_perf_reset {
# Profile this event.
-sub _perf_profile {
+sub _stat_profile {
my ($self, $event) = @_;
$profile{$event}++;
}
# Public routines...
-sub perf_getdata {
+sub stat_getdata {
return %average;
}
-sub perf_show_profile {
+sub stat_show_profile {
POE::Kernel::_warn('<pr> ,----- Event Profile ' , ('-' x 53), ",\n");
foreach (sort keys %profile) {
POE::Kernel::_warn(
@@ -169,38 +171,39 @@ __END__
=head1 NAME
-POE::Resource::Performance -- Performance metrics for POE::Kernel
+POE::Resource::Statistics -- Runtime statistics for POE programs
=head1 SYNOPSIS
- my %stats = $poe_kernel->perf_getdata;
+ my %stats = $poe_kernel->stat_getdata;
printf "Idle = %3.2f\n", 100*$stats{avg_idle_seconds}/$stats{interval};
=head1 DESCRIPTION
-This module tracks POE::Kernel's performance metrics and provides
-accessors to them. To enable this monitoring, the TRACE_PERFORMANCE
+This module tracks runtime statistics for a POE program and provides
+accessors to them. To enable this monitoring, the TRACE_STATISTICS
flag must be true. Otherwise no statistics will be gathered.
-The performance counters are totalled every 30 seconds and a rolling
+The statistics counters are totalled every 30 seconds and a rolling
average is maintained for the last two minutes worth of data. At any
-time the data can be retrieved using the perf_getdata() method of the
+time the data can be retrieved using the stat_getdata() method of the
POE::Kernel. On conclusion of the program, the statistics will be
printed out by the POE::Kernel.
-The time() function is used to gather performance metrics. If
+The time() function is used to gather statistics over time. If
Time::HiRes is available, it will be used automatically. Otherwise
time is measured in whole seconds, and the resulting rounding errors
will make the statistics useless.
-The performance metrics were added to POE 0.28. They are still
-considered highly experimental. Please be advised that the figures
-are quite likely wrong. They may in fact be useless. The reader is
-invited to investigate and improve the module's methods.
+Runtime statistics gathering was added to POE 0.28. It is considered
+highly experimental. Please be advised that the figures are quite
+likely wrong. They may in fact be useless. The reader is invited to
+investigate and improve the module's methods.
=head1 METRICS
-The following fields are members of the hash returned by perf_getdata.
+The following fields are members of the hash returned by
+stat_getdata().
For each of the counters, there will a corresponding entry prefixed
'avg_' which is the rolling average of that counter.
@@ -239,7 +242,7 @@ waiting for a select/poll event or a timeout to trigger).
The average interval over which the counters are recorded. This will
typically be 30 seconds, however it can be more if there are
-long-running user events which prevent the performance monitoring from
+long-running user events which prevent the statistics gathering from
running on time, and it may be less if the program finishes in under
30 seconds. Often the very last measurement taken before the program
exits will use a duration less than 30 seconds and this will cause the
View
12 lib/POE/Resources.pm
@@ -5,17 +5,15 @@ use strict;
use vars qw($VERSION);
$VERSION = do {my@r=(q$Revision$=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
-# XXX - For all I know, the order here may matter.
-
my @resources = qw(
- POE::XS::Resource::Extrefs
- POE::XS::Resource::SIDs
- POE::XS::Resource::Signals
POE::XS::Resource::Aliases
- POE::XS::Resource::FileHandles
POE::XS::Resource::Events
+ POE::XS::Resource::Extrefs
+ POE::XS::Resource::FileHandles
+ POE::XS::Resource::SIDs
POE::XS::Resource::Sessions
- POE::XS::Resource::Performance
+ POE::XS::Resource::Signals
+ POE::XS::Resource::Statistics
);
sub initialize {
Please sign in to comment.
Something went wrong with that request. Please try again.