in reply to Profiling the C side of an Inline::C module

As I see it, the problem with gprof is that to use it, you have to link the profiling library to the program you are running. You also have to compile your C files with a switch, but it's not difficult to tell Inline::C to do that.

I'm not sure how you can link the profiling library with perl. You may be able to achive this with the LINK config option of Inline::C, but I'm not sure if that would work. If it doesn't you have to relink perl with the profiling options given to the compiler, and install it.

Note also that the profiling option might have consequences on the linking other than just linking a library. You could try to figure these out by linking some program with and without profiling but with the -v or -### option passed to gcc (I wonder who gave this stupid name to the switch).

Update: This is all speculative of course. I don't have any experience with either Inline::C or gprof. It might be better to look for another profiler instead of gprof.

Replies are listed 'Best First'.
Re^2: Profiling the C side of an Inline::C module
by samtregar (Abbot) on Sep 04, 2005 at 23:40 UTC
    Compiling the module with "-pg" and linking in the profiling lib are no problem... But that doesn't seem to do it. gprof wants to work on "a.out", which I guess would be /usr/bin/perl in this case. I'd be willing to recompile Perl if that would do it, but I'd like to hear that someone has done it successfully before first. My programmer's intuition is telling me it won't work...

    -sam

      I'd be willing to recompile Perl if that would do it, but I'd like to hear that someone has done it successfully before first. My programmer's intuition is telling me it won't work...
      Alright, I've never done that exact thing (I've done debugging of Inline C code with gdb and a perl with debugging symbols, though), but I'd be extremely surprised if the combination of compiling perl and your inline c code with '-pg' didn't work correctly. What exactly about your intuitions tells you it won't?
        The 'gprof' program wants to look at 'a.out' to interpret the contents of the generated 'gmon.out'. Assuming 'a.out' is a specially-prepared Perl, I don't see how it could have the data needed to interpret calls to my module's code. I could be wrong though, I'm just going by what I've read of the manual.

        -sam

      Well, my intuition is telling me it will work, if you compile perl with the -pg option, and arrange for the final invocation of ld to use the profiling C runtime. You should end up with a perl that, when run (e.g. with perl -e 1), produces a gmon.out file.

      Then, make sure that Inline::C is using the -pg option to compile your module, and when you run perl on your test script, you'll now get a gmon.out file that includes profiling details about your module.

      --
      @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/
        Alright, I'll give it a try. I was won over when I found in reading perlhack that Perl has built-in support for gprof via the "perl.gprof" make target.

        -sam