Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Perl's profilers bite. I should know, I wrote one: Devel::Profiler. It's marginally better than the most common alternative, Devel::DProf, but it's very slow and breaks in many common scenarios. I've got an idea that might produce something better, but I want to get a reality check before I go and dump time into it.

I got the idea while reading an article about Intel's VTune profiler in Doctor Dobb's Journal. VTune works via an interupt handler which wakes up periodically and samples the instruction pointer of the process. These samples are used to construct a profile of the activity of the process. It's not a "perfect" profile in that it will miss things that happen infrequently or take very little time, but that's entirely acceptable in a profiler.

The up-side is that a sampling profiler like VTune is minimally invasive. It doesn't instrument the code being profiled and it can run so fast that it doesn't slow down the code being profiled. This means that the profiling data should be very reliable, corresponding closely to the behavior of the code when it's not being profiled.

So I started wondering what VTune-for-Perl would be like. Here's some random ideas:

  • Something would run at the start of the process and put the pointer for the currently executing opcode somewhere predictable (on disk? on a fifo?). I think that's called 'curcop' in the Perl core, but I could be wrong.
  • The interupt handler would wake up and saves the value of curcop each time it runs. The interval would be configurable just like it is in VTune.
  • At the end of the process code would need to be run to turn the curcop values into subroutine names and (if possible) line numbers. It seems like a walk of the op-tree with the B:: tools might allow this, but I'm not sure. I do know that this has to happen at the end because of eval"", dynamic requires, autoloading, etc.
Given the above, I have a few problems:

  • I don't know how to write an interupt handler. I think it would require a kernel module under Linux, which would be entirely new ground for me.
  • I don't know how I would get ahold of &curcop at the start of the process. Maybe write a tiny XS module to do it?
  • I don't know how to map curcop values to subroutine names.

Help or pointers to RTFM on any of these topics would be greatly appreciated.


PS: Please don't suggest I use the Perl debugger (it's broken) or fix the Perl debugger (I can't and I think the only person that can is Ilya and he's too busy). If someone did fix the debugger I could just use Devel::DProf and it would probably be good enough. If you want to know what's wrong with the debugger, do a search on perl5-porters for bug-reports concerning seg-faults from Devel::DProf.

In reply to Dreaming of a Better Profiler by samtregar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2021-10-21 18:02 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (83 votes). Check out past polls.