>>>>> "Rafael" == Rafael Garcia-Suarez <[EMAIL PROTECTED]> writes:
Rafael> Alexander Kolbasov wrote: >> Solaris (*) has a dynamic instrumentation tool called DTrace. It allows to >> *dynamically* instrument any running application and get useful information >> about its behavior with zero (or almost zero) impact on the application when it >> is not instrumented. >> >> This works fine with normal applications, but not so good with interpteded >> languages since C function names and data types have little to do with the >> structure of the interpreted language. I am playing with the idea of adding some >> hooks to Perl5 that will allow DTrace to be used for Perl programs (**). As an Rafael> Maybe are you aware of Rafael> http://blogs.sun.com/roller/page/alanbur?entry=dtrace_and_perl already ? Thanks for the pointer! It seems that Alan already made a pretty good progress on adding probes for subroutines. I am still curious whether it is possible to use DTrace to be able to trace based on Perl line numbers. IMO this will add a *tremendous* value. >> initial experiment I changed Perl_runops_standard() function a bit and was able >> to use DTrace to trace start and end of each Perl OP evaluation. This is not Rafael> You can also plug in your own runloop at compile time. See for example Rafael> my module Runops::Switch on CPAN. Cool! I'll take a look at it. Does it have the knowledge of the current file and line numbers and when execution switches from line X to Y? Rafael> The line number isn't stored in all ops, but only in COPs. You then get Rafael> it with the CopLINE macro, see cop.h. How do I know whether I am dealing with COP? Also, looking at cop.h it seems that getting file/lines with USE_ITHREADS is pretty cheap but otherwise can be quite expensive. Is it a way to get file/line number information from the op tree (may be not from every op) cheaply? For example, would it be reasonable (performance-wise) to get line/file information once per Perl_runops_standard() entry? Would it make any sense to do so? In my prototype I changed Perl_runops_standard() to int Perl_runops_standard(pTHX) { OP* (CPERLscope(*op_addr))(pTHX) = PL_op->op_ppaddr; /* * Would be really cool to insert here something like * * DTRACE_PROBE2(perl__line, file_name, line_number); * */ do { DTRACE_PROBE1(perl, call__entry, op_addr); PL_op = CALL_FPTR(op_addr)(aTHX); DTRACE_PROBE1(perl, call__return, op_addr); if (!PL_op) break; op_addr = PL_op->op_ppaddr; PERL_ASYNC_CHECK(); } while (1); TAINT_NOT; return 0; } P.S. Please bear in mind that I am *really* ignorant in Perl internals. - Alexander Kolbasov