[CentOS] Does sprof work on CentOS5?

Thu Jul 10 07:07:17 UTC 2008
Hywel Richards <hywelbr at googlemail.com>

Filipe Brandenburger wrote:
> Acutally I have no idea of what sprof is or does, but from the error
>   
Let me tell you about sprof, then, because it is fantastic!

Of course, it would be even better if it worked.

It is a statistical profiler for shared object libraries that 
(presumably) works by sampling the position of the program counter every 
now and again. All you need to do is set the value of LD_PROFILE to the 
name of the .so and statistics will get dumped to a file in /var/tmp.

You can then use sprof to build a profile from those stats in the same 
way that gprof does from a gmon.out file.

But it's much better than gprof as you don't have to compile with 
special flags which cause code to get inserted and distorts the timing 
of your program anyway. And as it profiles .so files it also allows you 
to easily profile python modules, for example, where you don't want to 
recompile the main program.

Unfortunately, there does not seem to be much information about it on 
the internet.
It makes me wonder if there is an alternative which has superceeded it 
(I see oprofile, but it looks a good deal more difficult to use).
> message above it seems sprof cannot find your library because it is
> not in the default library search path. Try this:
>
> $ LD_LIBRARY_PATH=.  sprof libmy.so /var/tmp/libmy.so.profile
>
> Let us know how that goes.
>   
No luck with that, I'm afraid:

$ LD_LIBRARY_PATH=. sprof libmy.so /var/tmp/libmy.so.profile
sprof: failed to load shared object `libmy.so'

I've tried all sorts to try and coax the program to accept the files - I 
wonder if it might not just be an unhelpful error message and something 
else is failing. I have a strace here in case anyone can understand what 
is going on (is it some locale setting that it doesn't like, perhaps, I 
don't know much about that stuff - it doesn't seem to attempt to open 
anything like libmy.so at all):

execve("/usr/bin/sprof", ["sprof", "libmy.so", 
"/var/tmp/libmy.so.profile"], [/* 39 vars */]) = 0
brk(0)                                  = 0x8c78000
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0xb7fd7000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or 
directory)
open("/usr/lib/xorg/tls/i686/sse2/libdl.so.2", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/usr/lib/xorg/tls/i686/sse2", 0xbf83ced8) = -1 ENOENT (No such 
file or directory)
open("/usr/lib/xorg/tls/i686/libdl.so.2", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/usr/lib/xorg/tls/i686", 0xbf83ced8) = -1 ENOENT (No such file 
or directory)
open("/usr/lib/xorg/tls/sse2/libdl.so.2", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/usr/lib/xorg/tls/sse2", 0xbf83ced8) = -1 ENOENT (No such file 
or directory)
open("/usr/lib/xorg/tls/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file 
or directory)
stat64("/usr/lib/xorg/tls", 0xbf83ced8) = -1 ENOENT (No such file or 
directory)
open("/usr/lib/xorg/i686/sse2/libdl.so.2", O_RDONLY) = -1 ENOENT (No 
such file or directory)
stat64("/usr/lib/xorg/i686/sse2", 0xbf83ced8) = -1 ENOENT (No such file 
or directory)
open("/usr/lib/xorg/i686/libdl.so.2", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/usr/lib/xorg/i686", 0xbf83ced8) = -1 ENOENT (No such file or 
directory)
open("/usr/lib/xorg/sse2/libdl.so.2", O_RDONLY) = -1 ENOENT (No such 
file or directory)
stat64("/usr/lib/xorg/sse2", 0xbf83ced8) = -1 ENOENT (No such file or 
directory)
open("/usr/lib/xorg/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or 
directory)
stat64("/usr/lib/xorg", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=80005, ...}) = 0
mmap2(NULL, 80005, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7fc3000
close(3)                                = 0
open("/lib/libdl.so.2", O_RDONLY)       = 3
read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0PJ\251\0004\0\0\0"..., 
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=16428, ...}) = 0
mmap2(0xa94000, 12408, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 
3, 0) = 0xa94000
mmap2(0xa96000, 8192, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0xa96000
close(3)                                = 0
open("/usr/lib/xorg/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or 
directory)
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, 
"\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000\277\223\0004\0\0\0"..., 
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1597968, ...}) = 0
mmap2(0x926000, 1320356, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 
3, 0) = 0x926000
mmap2(0xa63000, 12288, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x13c) = 0xa63000
mmap2(0xa66000, 9636, PROT_READ|PROT_WRITE, 
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xa66000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0xb7fc2000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7fc26c0, 
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, 
limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0xa96000, 4096, PROT_READ)     = 0
mprotect(0xa63000, 8192, PROT_READ)     = 0
mprotect(0x922000, 4096, PROT_READ)     = 0
munmap(0xb7fc3000, 80005)               = 0
brk(0)                                  = 0x8c78000
brk(0x8c99000)                          = 0x8c99000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=56454464, ...}) = 0
mmap2(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7dc2000
mmap2(NULL, 884736, PROT_READ, MAP_PRIVATE, 3, 0x1e1) = 0xb7cea000
mmap2(NULL, 4096, PROT_READ, MAP_PRIVATE, 3, 0x6d1) = 0xb7ce9000
close(3)                                = 0
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=2528, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0xb7ce8000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2528
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0xb7ce8000, 4096)                = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 
ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 
ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 
ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 
ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 
ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT 
(No such file or directory)
write(2, "sprof: ", 7sprof: )                  = 7
write(2, "failed to load shared object `li"..., 39failed to load shared 
object `libmy.so') = 39
write(2, "\n", 1
)                       = 1
exit_group(1)                           = ?