Skip to content

Commit

Permalink
Item1648: add memory usage to Monitor
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x00@3949 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed May 21, 2009
1 parent 0faca84 commit 5128084
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions core/lib/Monitor.pm
Expand Up @@ -3,18 +3,18 @@
Monitoring package. Instrument the code like this:
use Monitor;
use Monitor ();
Monitor::MARK("Description of event");
Monitor::MARK("Another event");
or, to monitor all the calls to a module
use Monitor;
use Monitor ();
Monitor::MonitorMethod('Foswiki::Users');
or a function
use Monitor;
use Monitor ();
Monitor::MonitorMethod('Foswiki::Users', 'getCanonicalUserID');
Then set the environment variable FOSWIKI_MONITOR to a perl true value, and
Expand All @@ -40,13 +40,14 @@ use vars qw(@times @methodStats);
sub get_stat_info {

# open and read the main stat file
if ( !open( _INFO, "</proc/$_[0]/stat" ) ) {
my $_INFO;
if ( !open( $_INFO, '<', "/proc/$_[0]/stat" ) ) {

# Failed
return { vsize => 0, rss => 0 };
}
my @info = split( /\s+/, <_INFO> );
close(_INFO);
my @info = split( /\s+/, <$_INFO> );
close($_INFO);

# these are all the props (skip some)
# pid(0) comm(1) state ppid pgrp session tty
Expand Down Expand Up @@ -111,12 +112,17 @@ sub END {
# }
my %methods;
foreach my $call (@methodStats) {
$methods{ $call->{method} } = { count => 0, min => 99999999, max => 0 }
$methods{ $call->{method} } = {
count => 0,
min => 99999999,
max => 0,
mem_min => 99999999,
mem_max => 0
}
unless defined( $methods{ $call->{method} } );
$methods{ $call->{method} }{count} += 1;
my $diff = timediff( $call->{out}, $call->{in} );

#my $diff = $call->{out}{rss} - $call->{in}{rss};
$methods{ $call->{method} }{min} = ${$diff}[0]
if ( $methods{ $call->{method} }{min} > ${$diff}[0] );
$methods{ $call->{method} }{max} = ${$diff}[0]
Expand All @@ -128,13 +134,25 @@ sub END {
else {
$methods{ $call->{method} }{total} = $diff;
}
my $memdiff = $call->{out_stat}{rss} - $call->{in_stat}{rss};
$methods{ $call->{method} }{mem_min} = $memdiff
if ( $methods{ $call->{method} }{mem_min} > $memdiff );
$methods{ $call->{method} }{mem_max} = $memdiff
if ( $methods{ $call->{method} }{mem_max} < $memdiff );
}
print STDERR "\n| Count | Min | Max | Total | Method |";
print STDERR
"\n| Count | Time (Min/Max) | Memory(Min/Max) | Total | Method |";
foreach my $method ( sort keys %methods ) {
print STDERR "\n| "
. sprintf( '%6u', $methods{$method}{count} ) . ' | '
. sprintf( '%6.3f', $methods{$method}{min} ) . ' | '
. sprintf( '%6.3f', $methods{$method}{max} ) . ' | '
print STDERR "\n| "
. sprintf( '%6u', $methods{$method}{count} ) . ' | '
. sprintf( '%6.3f / %6.3f',
$methods{$method}{min},
$methods{$method}{max} )
. ' | '
. sprintf( '%6u / %6u',
$methods{$method}{mem_min},
$methods{$method}{mem_max} )
. ' | '
. timestr( $methods{$method}{total} )
. " | $method |";
}
Expand Down

0 comments on commit 5128084

Please sign in to comment.