Re: Profiling the C side of an Inline::C module
by itub (Priest) on Sep 04, 2005 at 19:35 UTC
|
What I did in one case was to make sure that the part of the C code that did most of the work was completely independent of the code that interfaces with Perl, so that it could be compiled and profiled separately as a standalone C program. YMMV. | [reply] |
|
|
That's a good idea, but I think it would be hard in this case. The code includes a lot of calls to Perl functions (sv_catpvn, for example) and the relative performance of those calls is important.
-sam
| [reply] |
Re: Profiling the C side of an Inline::C module
by ambrus (Abbot) on Sep 04, 2005 at 19:57 UTC
|
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.
| [reply] [d/l] [select] |
|
|
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
| [reply] |
|
|
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?
| [reply] |
|
|
|
|
|
|
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@/
| [reply] [d/l] [select] |
|
|
|
|
|
Re: Profiling the C side of an Inline::C module
by fauria (Deacon) on Sep 04, 2005 at 23:28 UTC
|
I was wondering if using valgrind would work. So, i tried it with a very simple c program:
#include <stdlib.h>
int main(){
int *p = malloc(sizeof(int));
free(p);
return 0;
}
and returned:
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 17 from 2)
malloc/free: in use at exit: 0 bytes in 0 blocks.
malloc/free: 1 allocs, 1 frees, 4 bytes allocated.
Everything is ok. Now, i try it using: /usr/local/bin/valgrind perl -e 'print "Hello, world!\n";' and i get:
LEAK SUMMARY:
definitely lost: 222050 bytes in 655 blocks.
possibly lost: 0 bytes in 0 blocks.
still reachable: 0 bytes in 0 blocks.
suppressed: 0 bytes in 0 blocks.
Use --leak-check=full to see details of leaked memory.
Wow. Trying to profile some mixed code, like:print "Hi, C!\n";
use Inline C;
waste();
__END__
__C__
void waste(){
void *p = malloc(sizeof(int));
//free(p);
printf("Hi, Perl!\n");
}
becomes a hell!
Has anybody tried succesfully valgrind on perl? | [reply] [d/l] [select] |
|
|
I've seen summaries on perl5-porters of valgrind runs on Perl itself. I don't think I've seen anything about running valgrind on an XS module, but it might be worth exploring.
-sam
| [reply] |