Sponsored Content
Top Forums UNIX for Advanced & Expert Users Profiling..entry for a function in pthread_create Post 83561 by Vikky Panchal on Friday 16th of September 2005 12:23:42 AM
Old 09-16-2005
Profiling..entry for a function in pthread_create

Hi jim,

Thanks a lot for ur reply....

I have tried using gprof, FncCheck, SunWorkShop Pro, gprof does not give results thread wise, SunWorkShop is an excellent profiling tool, but since it is avaiable for Solaris platform i am try to find tool that can be used on other m/s also.
i had downloaded the code for profiling pv_trace (Author:= M. Tim Jones), and added modifications for multithreading and shared libraries.

i have made few modifications to the instrument.c code,
eg: As shown below.....
what i wanted is to profile for speicific functions, so what did is specify those functions as an environment variable and had them exported, in the instrument.c i read for that environment variable and populated list of functon entries in a hash table.
Now the problem is for functions calls from shared libraries. The ( *this ) parameter of "__cyg_profile_func_enter" points to some different addr.
eg:
my shared lbrary libMyThread.so on doing an "nm" gives
Addr mangled name demangled name
0x000010cc T EntryPoint__8MyThreadPv MyThread::EntryPoint(void *)

but on call to "MyThread::EntryPoint" the addr is "0xff3510cc"
This is because the linker is resolves entries to such functions at run time, i tried to use dlopen, dlsym functions but how to i get information of mangled functions corresponding to such address (in this case 0xff3510cc),

Also, when casting (*this) as int is gives a negative value(in this case 0xff3510cc). plz help...

Desc.:
checkProfileFlag() := This function tell whether to profile for all functions or
user specified functions.

DEBUG:= Macro for outputting debuggng info.
hx_search():= This is a function form "hash.c" which looks whether the
function needs to be proifiled or not.(Only useful when
functions are exported as env. variables.)


void __cyg_profile_func_enter( void *this, void *callsite )
{

if(DEBUG)
printf("E%p, %d,\n",(int*)this,abs((int*)this));

if(!checkProfileFlag()) {
if(hx_search((int *)this)){
if(DEBUG) {
printf("Profiling for %d, %p,\n",(int *)this,(int *)this);
printf("E%d,J%d\n",pthread_self(),pM[pthread_self()].size);
}
pM[pthread_self()].pth=getpid();
pM[pthread_self()].th=pthread_self();
pM[pthread_self()].fnc[pM[pthread_self()].size].addr=(int*)this;
pM[pthread_self()].fnc[pM[pthread_self()].size].Ch='E';
gettimeofday(&pM[pthread_self()].fnc[pM[pthread_self()].size].tp,NULL);
pM[pthread_self()].size++;
}
} else {
pM[pthread_self()].pth=getpid();
pM[pthread_self()].th=pthread_self();
pM[pthread_self()].fnc[pM[pthread_self()].size].addr=(int*)this;
pM[pthread_self()].fnc[pM[pthread_self()].size].Ch='E';
gettimeofday(&pM[pthread_self()].fnc[pM[pthread_self()].size].tp,NULL);
pM[pthread_self()].size++;
}

}

Last edited by Vikky Panchal; 09-16-2005 at 01:47 AM..
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Kernel Profiling

I compiled my device driver with the profiling option -p but while linking I am getting undefined reference to _mcount. LD /vobs/femto_drivers/DspBiosLink/dsplinkk/src/dsplinkk.o Building modules, stage 2. MODPOST *** Warning: "_mcount" undefined! Architechture: ppc32 From... (0 Replies)
Discussion started by: Ashok V
0 Replies

2. UNIX for Dummies Questions & Answers

profiling execution of a process

question goes like this : Explain how users can profile execution of a process with help of an example? can some one pls give me the answer?? (1 Reply)
Discussion started by: rakesh1988
1 Replies

3. Programming

pthread_create

The prototype for pthread_create function is like this:- int pthread_create(pthread_t *thread,pthread_attr_t *attr,void *(*start routine),void *arg); Q.1 .Why the return type of the start_routine must be void*?? Q.2. Why should we pass arg by converting into void * only ?? Thank You (3 Replies)
Discussion started by: sunil_abhay
3 Replies

4. Programming

Profiling results and SMP

The SCO OSR 5.7 system was migrated from older HP DL360 to new DL380 G7. The SMP feature was not activated on older box, it is activated now on this 4 core Xeon. A s/w we maintain has been copied without any change over to the new box. I noticed that the application profiling does not show any... (4 Replies)
Discussion started by: migurus
4 Replies

5. AIX

C profiling tool for AIX

Hello everybody, Please let me know if there are any free C profiling tool for AIX environment Thanks in advance (0 Replies)
Discussion started by: SteAlma
0 Replies

6. How to Post in the The UNIX and Linux Forums

Help me, write a bash script to delete parent entry with all their child entry in LDAP UNIX server

Hi All, Please help me and guide me to write a bash/shell script on Linux box to delete parent entry with all their child entries. example: Parent is : ---------- dn: email=yogesh.kumar@wipro.com, o=wipro, o=in child is: ---------- dn: cn: yogesh kumar, email=yogesh.kumar@wipro.com,... (1 Reply)
Discussion started by: Chand
1 Replies

7. Debian

Profiling Processes while shutdown

I was wondering how can I find the culprit of a slow shutdown on my debian box? I am actually looking for a diagnosis tool that might dump the process name and amount of time it took to close the process after signal was send. As for now I am trying to use journalctl to seek some information,... (5 Replies)
Discussion started by: Varun Pandey
5 Replies
profil(2)							   System Calls 							 profil(2)

NAME
profil - execution time profile SYNOPSIS
#include <unistd.h> void profil(unsigned short *buff, unsigned int bufsiz, unsigned int offset, unsigned int scale); DESCRIPTION
The profil() function provides CPU-use statistics by profiling the amount of CPU time expended by a program. The profil() function gener- ates the statistics by creating an execution histogram for a current process. The histogram is defined for a specific region of program code to be profiled, and the identified region is logically broken up into a set of equal size subdivisions, each of which corresponds to a count in the histogram. With each clock tick, the current subdivision is identified and its corresponding histogram count is incremented. These counts establish a relative measure of how much time is being spent in each code subdivision. The resulting histogram counts for a profiled region can be used to identify those functions that consume a disproportionately high percentage of CPU time. The buff argument is a buffer of bufsiz bytes in which the histogram counts are stored in an array of unsigned short int. Once one of the counts reaches 32767 (the size of a short int), profiling stops and no more data is collected. The offset, scale, and bufsiz arguments specify the region to be profiled. The offset argument is effectively the start address of the region to be profiled. The scale argument is a contraction factor that indicates how much smaller the histogram buffer is than the region to be profiled. More precisely, scale is interpreted as an unsigned 16-bit fixed-point fraction with the decimal point implied on the left. Its value is the reciprocal of the number of bytes in a subdivision, per byte of histogram buffer. Since there are two bytes per histogram counter, the effective ratio of subdivision bytes per counter is one half the scale. The values of scale are as follows: o the maximum value of scale, 0xffff (approximately 1), maps subdivisions 2 bytes long to each counter. o the minimum value of scale (for which profiling is performed), 0x0002 (1/32,768), maps subdivision 65,536 bytes long to each counter. o the default value of scale (currently used by cc -qp), 0x4000, maps subdivisions 8 bytes long to each counter. The values are used within the kernel as follows: when the process is interrupted for a clock tick, the value of offset is subtracted from the current value of the program counter (pc), and the remainder is multiplied by scale to derive a result. That result is used as an index into the histogram array to locate the cell to be incremented. Therefore, the cell count represents the number of times that the process was executing code in the subdivision associated with that cell when the process was interrupted. The value of scale can be computed as (RATIO * 0200000L), where RATIO is the desired ratio of bufsiz to profiled region size, and has a value between 0 and 1. Qualitatively speaking, the closer RATIO is to 1, the higher the resolution of the profile information. The value of bufsiz can be computed as (size_of_region_to_be_profiled * RATIO). Profiling is turned off by giving a scale value of 0 or 1, and is rendered ineffective by giving a bufsiz value of 0. Profiling is turned off when one of the exec family of functions (see exec(2)) is executed, but remains on in both child and parent processes after a fork(2). Profiling is turned off if a buff update would cause a memory fault. USAGE
The pcsample(2) function should be used when profiling dynamically-linked programs and 64-bit programs. SEE ALSO
exec(2), fork(2), pcsample(2), times(2), monitor(3C), prof(5) NOTES
In Solaris releases prior to 2.6, calling profil() in a multithreaded program would impact only the calling LWP; the profile state was not inherited at LWP creation time. To profile a multithreaded program with a global profile buffer, each thread needed to issue a call to pro- fil() at threads start-up time, and each thread had to be a bound thread. This was cumbersome and did not easily support dynamically turn- ing profiling on and off. In Solaris 2.6, the profil() system call for multithreaded processes has global impact -- that is, a call to pro- fil() impacts all LWPs/threads in the process. This may cause applications that depend on the previous per-LWP semantic to break, but it is expected to improve multithreaded programs that wish to turn profiling on and off dynamically at runtime. SunOS 5.11 12 Nov 2001 profil(2)
All times are GMT -4. The time now is 11:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy