[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple profiling capability


i'm just tossing this idea out...

1) have a profiler package that handles all the logging, etc - and uses a constant

	package MyApp:::Profiler;
	use constant DO_PROFILE=> 1;
	sub profile {
		my ( $marker )= @_ ;
		#log;
	}
	1;

2) in your app code, do this:
MyApp:::Profiler::DO_PROFILE && MyApp:::Profiler::profile( 'some identifier' );

My rationale:
a) creating the namespace / etc means you can just wrap whatever method you want cleanly b) mp will optimize away the calls to profile if you start the server with DO_PROFILE set to 0 -- this way you don't have to deal with a performance hit in production and can leave the calls intact as-is.

in terms of actually recording...

i'd probably stack everything into a local variable as an array ; then id drop in a cleanup handler that calls a function to write it to disk or memory somehow... you'd have to have a reset within the package that clears out the var too

	my 	@profile;
	sub profile {
		my ( $marker )= @_ ;
		push @profile , $marker;
	}
	sub cleanup {
		# record
			record( suppressed );
		# reset
		@profile= ();
	}

in any event , the bulk of my suggestions are this:
1- there's no reason to continually write to disk or shared mem , or call misc functions ( unless you're profiling in-time ). just store that stuff in a perl structure and dump 1x. 2- use the optimize-away hack with constants to quickly turn off your debug code



On Nov 12, 2007, at 10:42 AM, E R wrote:

Hi,

I have the need for a simple profiling capability for mod_perl applications.
At a few (< 50) points in my code I want to call something like:

$profiler->mark("some identifier");

and increment the counter for "some identifier". Later I want to be able to get
(through a web page) a summary (grouped by identifiers) of all the
profiling calls
made (of course, made by all Apache child processes.) For instance, if I want to profile the number of times a particular subroutine was called, I would use:

sub mysubroutine {
  $profiler->mark("in mysubroutine");
  ...
}

This is very similar to logging, except for the summary part. Does anyone
have ideas of a good way to implement this? Shared memory? An external
daemon to record these calls? Has someone already implemented this?
Robust and simple are good.

Thanks,

ER


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.