This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Question sprof on multiple shared libraries


I have a little program that calls two routines. Each routine is defined on a separate shared library. I am enclosing the program at the end of the message.
Questions:

1) can sprof support multiple shared libraries?
if so, 
*	what is the syntax for generating the profile(s) file (LD_PROFILE=????)
*	what is the syntax for sprof
2) I was able to produce two profile files by executing the program twice.
*	LD_PROFILE=libhello.so
*	./usehello
*	sprof libhello.so libhello.so.profile
*	LD_PROFILE=libreadname.so
*	./usehello
*	sprof libreadname.so libreadname.so.profile
3) However, the output for step 2 does not represent what I was expecting for libreadname.so


==================  output for libhello.so ====================
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name
  0.00      0.00     0.00        1     0.00           print_hello

index % time    self  children    called     name

                0.00    0.00        0/0           <UNKNOWN>
[0]      0.0    0.00    0.00        0         atexit@@GLIBC_2.0 [0]
                0.00    0.00        1/1           print_hello [1]
                0.00    0.00        0/0           atexit@@GLIBC_2.0 [0]
-----------------------------------------------
                0.00    0.00        1/1           <UNKNOWN>
[1]      0.0    0.00    0.00        1         print_hello [1]
-----------------------------------------------

===================== output from libreadname.so ====================

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name

index % time    self  children    called     name

                0.00    0.00        0/0           <UNKNOWN>
[0]      0.0    0.00    0.00        0         atexit@@GLIBC_2.0 [0]
                0.00    0.00        0/0           atexit@@GLIBC_2.0 [0]
-----------------------------------------------

4) I am enclosing makefile and source files of the sample program

I am enclosing the steps that I have followed:
 
1) make
cc -c usehello.c -o usehello.o
cc -fPIC -Wall -c libhello.c
cc -fPIC -Wall -c libreadname.c
cc -shared -Wl,-soname,libreadname.so -o ./libreadname.so libreadname.o
cc -shared -Wl,-soname,libhello.so -o ./libhello.so libhello.o
cc -o usehello usehello.o -L. -lhello -L. -lreadname
2) LD_PROFILE=libhello.so,libreadname.so
3) ./usehello
The program execute normally but it does not generate the profile file on /var/tmp
4) I get the errors for the following commands
	sprof libhello.so,libreadname.so libhello.so.profile
	I get the following error:
	sprof: failed to load shared object `libhello.so,libreadname.so': No 
	such file or directory
	
					OR

	sprof libhello.so libhello.so.profile
	I get the following error:
	sprof: cannot load profiling data: No such file or directory

5) I understand the second error - There were no profile file on /var/tmp

I am also enclosing the sample program


=========================== Makefile ==================================

#
# -Wall	- Produces warning about questionable coding practice
# -Wl	- pass the option list to the linker
# -fPIC	- emit position-independent code, suitable for dynamic linking,
#		  even if branches need large displacements.
# -shared - for SUN machines
#
LIBDIR	= .

usehello: usehello.o libhello.so libreadname.so
	cc -o usehello usehello.o -L$(LIBDIR) -lhello -L$(LIBDIR) -lreadname

usehello.o: usehello.c
	cc -c usehello.c -o usehello.o

libhello.so: libhello.o libreadname.so
	cc -shared -Wl,-soname,$@ -o $(LIBDIR)/libhello.so libhello.o
	
libreadname.so: libreadname.o
	cc -shared -Wl,-soname,$@ -o $(LIBDIR)/libreadname.so libreadname.o

libreadname.o: libreadname.c
	cc -fPIC -Wall -c libreadname.c

libhello.o: libhello.c
	cc -fPIC -Wall -c libhello.c

clean:
	rm $(LIBDIR)/libhello.so
	rm $(LIBDIR)/libreadname.so
	rm -rf *.o

================================= libhello.c ==========================
#include <stdio.h>

void print_hello(char *s) 
{
	printf("Hello %s\n", s);
}

================================ libreadname.c =========================

#include <stdio.h>

char b[512];

char *read_name(void)
{

	printf("enter name: ");
	b[0] = '\0';
	if (fgets(b, sizeof (b), stdin) == NULL || b[0] == '\n') {
		return (NULL);
	}                                                          
	printf("\n");
	return ((char *)&b[0]);

}

=============================== usehello.c =============================

#include "libhello.h"
#include "libreadname.h"

int main(void) 
{
	int i;
	char *buffer;

	buffer = read_name();
	for (i=0; i < 100; i++) {
		print_hello(buffer);
	}
	return(0);
}

============================== libhello.h ==============================
extern void print_hello(char *s);

============================== libreadname.h ==========================

extern char *read_name(void);






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]