I am unable to generate flat profiling result using sprof
in Ubuntu 16.04.02 (as well as 14.04.01). Here is a reproducible example, adapted from man sprof
.
First create a directory for experiment, then create prog.c
and libdemo.c
files inside:
// prog.c
#include <stdlib.h>
void x1(void);
void x2(void);
int
main(int argc, char *argv[])
{
x1();
x2();
exit(EXIT_SUCCESS);
}
// libdemo.c
#include <unistd.h>
void
consumeCpu1(int lim)
{
int j;
for (j = 0; j < lim; j++)
getppid();
}
void
x1(void) {
int j;
for (j = 0; j < 100; j++)
consumeCpu1(200000);
}
void
consumeCpu2(int lim)
{
int j;
for (j = 0; j < lim; j++)
getppid();
}
void
x2(void)
{
int j;
for (j = 0; j < 1000; j++)
consumeCpu2(10000);
}
Now open a terminal, and change directory to the above created one, then run the following shell script:
cc -g -fPIC -shared -o libdemo.so libdemo.c
cc -g -o prog prog.c -L. -ldemo
export LD_PROFILE=libdemo.so
export LD_PROFILE_OUTPUT=$(pwd) ## use current directory
rm -f libdemo.so.profile
LD_LIBRARY_PATH=. ./prog
sprof -p libdemo.so libdemo.so.profile
I get an error:
Inconsistency detected by ld.so: dl-open.c: 717: _dl_open: Assertion `_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT' failed!
libdemo.so.profile
has been generated without problem, but sprof
fails to process it.
I found this Stack Overflow thread What is causing sprof to complain about “inconsistency detected by ld.so”?, but it does not offer a solution. I want to get sprof
to work!
Is this problem dependent on Linux distributions? I saw a thread on 2016, where sprof
is successful: sprof flat profile name column has ugly format.
Frankly speaking I don't know which is the best forum to post this question. It looks like a programming question that belongs to Stack Overflow, but the C program and profiling runs alright; it is just sprof
that fails to process it in the final stage, which should be a Linux related issue. Then if this issue is independent on Linux distributions, I should ask about on Unix & Linux, but if it only occurs on Ubuntu, I should raise it here on ask ubuntu. Well, feel free to migrate it to the best place as you see fit; I have no clue on it at all.
0 Answers