开发者

How can I use NYTProf in a library

开发者 https://www.devze.com 2023-01-09 19:58 出处:网络
I\'m wondering if Devel::NYTProf can be used as a library in another library. I\'d like to do something like the following

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:

  1. Add DB::enable_profile and DB::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).
  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消