Trouble getting NYTProf to work in an embedded perl interp

24 views
Skip to first unread message

Mark Aufflick

unread,
Sep 11, 2012, 7:11:46 AM9/11/12
to develnyt...@googlegroups.com
Hi all,

I have a perl interp embedded in a Mac app. I can successfully run the
debugger by passing "-d" in the argv to perl_parse() (and also setting
PERLDB_OPTS to NonStop and running perl_run() at some point to kick
off the debugging).

I'm now trying to use NYTProf inside the embedded app for cases where
it's not possible to reduce to a test case (eg. some tricky stuff
using Cocoa bindings bound to bridged perl objects).

Using the same sort of approach as NYTProf::Apache I successfully get
the nytprof.out file written out, but it always has zero statements.
What I'm doing to set up the interpreter is this:

#if EFCPerlInterpDebugger
char * embedding[] = { "", "-w", "-d", "-e", "0" };
#else
char * embedding[] = { "", "-w", "-e", "0" };
#endif

int embedding_count = sizeof(embedding) / sizeof(char *);

my_perl = perl_alloc();
PL_perl_destruct_level = 1;
perl_construct(my_perl);
perl_parse(my_perl, xs_init, embedding_count, embedding,
my_perl_env);

#if EFCPerlInterpDebugger || EFCPerlInterpNYTProf
perl_run(my_perl);
#endif

#if EFCPerlInterpNYTProf
eval_pv("$ENV{NYTPROF} = \"file=/tmp/nytprof.$$.out\";
require Devel::NYTProf::Core; DB::set_option(\"endatexit\", 1);
DB::set_option(\"addpid\", 1); require Devel::NYTProf;
DB::enable_profile();",TRUE);
#endif

PL_exit_flags |= PERL_EXIT_DESTRUCT_END;

Then at the end I'm doing this:

eval_pv("DB::finish_profile();", TRUE);

PL_perl_destruct_level = 1;
perl_destruct(my_perl);
perl_free(my_perl);

I tried setting endatexit to zero in case the lack of statements in
the -e statement was impeding it. I also tried removing the
enable_profile() and instead moving it to the places where perl code
was being executed, folliwing with disable_profile(). All to no avail.

It's worth noting in the actual code I never use eval_pv(), instead
making an SV * of an object and using call_method() directly.

Any ideas?

Thanks,

Mark.
--
Mark Aufflick
http://mark.aufflick.com/about/contact
http://pumptheory.com/about

Tim Bunce

unread,
Sep 11, 2012, 11:28:09 AM9/11/12
to develnyt...@googlegroups.com
Devel::NYTProf::Core has to be loaded as soon as possible. Certainly
before perl_run, and ideally very early in perl_parse. Try using:

char * embedding[] = { "", "-w", "-d:NYTProf", "-e", "0" };

Tim.
Reply all
Reply to author
Forward
0 new messages