I'm wondering if Devel::NYTProf can be used as a library in another library. I'd like to do something like the following
around 'somesub' => sub {
my $orig = shift;
my $self = shift;
start-timing;
$self->$orig(@_);
end-timing;
print '$time';
}
but from it's documentation I'm unable to d开发者_Go百科etermine if it can be used like this. Is it possible? could someone tell me the API calls that i'd do?
The simplest, most reliable thing to do is:
- Add
DB::enable_profile
andDB::disable_profile
calls in your library (you might want to check whether the subs are defined first, to avoid breakage when NYTProf isn't loaded). - Start perl with -d:NYTProf and
NYTPROF=start=no
in the environment.
All of this is pretty clearly explained in the Devel::NYTProf docs.
You could try having your library conditionally load NYTProf, but the deal here is that only stuff compiled after NYTProf is loaded gets any tracepoints. That might sound perfectly okay, since you only want to profile your library, but it's not clear what will happen if your library calls out (or calls back) to any other code, and I didn't test it. It's probably a lot easier to make the simple version make do :)
I don't think it can be used that way. But you might take a look at Aspect::Library::Profiler or Aspect::Library::Timer
精彩评论