Profiling..entry for a function in pthread_create


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Profiling..entry for a function in pthread_create
# 1  
Old 08-27-2005
Question Profiling..entry for a function in pthread_create

Hello,

i am try to write a profiler for a multithreaded applciation. When i creat e a thread for "function f2()" the profiling information for this function does not get captured in the struct profileManager. i;e i get the exit information for "function f2()" in that thread, but the entry information does not get captured. Is it because the profiling function "__cyg_profile_func_enter" does not get inserted fot that thread? Do i have to use pthread_once_t to initialize so that its entry gets profiled??

Thanks,
Vikky.

////**** This is my instrument.c file ****/////
static FILE *fp;

struct profileManager{
pid_t pth;
pthread_t th;
char Ch;
int addr;
struct timeval tp;
}pM[1000];

static int cnt=0;

void __cyg_profile_func_enter( void *this, void *callsite ) {
pthread_mutex_lock(&Lock);
pM[cnt].pth=getpid();
pM[cnt].th=pthread_self();
pM[cnt].Ch='E';
pM[cnt].addr=(int*)this;
gettimeofday(&pM[cnt].tp,NULL);
cnt++;
pthread_mutex_unlock(&Lock);
}


void __cyg_profile_func_exit( void *this, void *callsite ) {
pthread_mutex_lock(&Lock);
pM[cnt].pth=getpid();
pM[cnt].th=pthread_self();
pM[cnt].Ch='X';
pM[cnt].addr=(int*)this;
gettimeofday(&pM[cnt].tp,NULL);
cnt++;
pthread_mutex_unlock(&Lock);
}

////***** my sample code test.c ****/////
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

int f1(int i){
sleep(1);
if(i==1)
return 0;
f1(i-1);
}

void f3(){
f1(5);
}

void* f2(void* arg){
f3();
}

void f4(){
sleep(1);
}


int main(){
int i;
pthread_t th;
int code;

code = pthread_create(&th,NULL,f2,NULL); ///Create Thread for F2
if(code==0)
printf("Thread created %d\n",th);
printf("Hello World\n");
(void)f2(NULL);
for(i=0;i<5;i++)
f4();
sleep(10);
return 0;
}
# 2  
Old 08-29-2005
Can I make a suggestion? Try using monitor(), or profil(). You can force monitoring on a given function. See man monitor.

Even better use the profiler on your system, unless this is homework.
# 3  
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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
Login or Register to Ask a Question