Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Profiling in QNX / or From QNX Momentics: (3 Items)
   
Profiling in QNX / or From QNX Momentics  
Many problems regarding profiling applications that spawn processes by fork() / exec() calls

We build the project for "Function Instrumentation mode" i,e with the flags -finstrument-functions for compiler and -
lprofilingS for the linker successfully. 

It's a server/client application (i,e while (1) {  } but with proper termination signal handlers)

Main app is "process1" has 2 threads and launches many child processes (with many threads for each) by fork() / exec() 
of other binaries in the same directory. (1 binary -> 1 process with many threads usually) 

Use cases:

1-

Profiling the main procecess from Momentics gives a report of more than 10 threads (has only 2) (gprof is known for its 
issues with multi-process applications).
Many child processes are killed when the profiling session is launched.

---------------------
example output:

Process 335905 (child_appX) terminated SIGSEGV code=1 fltno=11 ip=00000000081373d5(/home/./child_appX@
ld_imposter_get_backtrace+0x00000000000c7bd5) mapaddr=00000000000ef3d5. ref=0000000000000b50
Process 331803 (child_appY) terminated SIGSEGV code=1 fltno=11 ip=00000000081145ef(/home/./child_appY@
ld_imposter_get_backtrace+0x00000000000a4dcf) mapaddr=00000000000cc5ef. ref=0000000000000010
Process 340002 (child_appZ) terminated SIGSEGV code=1 fltno=11 ip=00000000081145cf(/home/./child_appZ@
ld_imposter_get_backtrace+0x00000000000a4dcf) mapaddr=00000000000cc5cf. ref=0000000000001690

--------------------

2 -

We want to obtain the .ptrace file of a child process.

We set the env variables in this way:

QPROF_AUTO_START=1
QPROF_SIG_CONT_PROFILING=16
QPROF_SIG_STOP_PROFILING=17
QPROF_FILE=/home/<app_name>.ptrace (all permissions are set for the dir /home)

We launch the main application then after a while we send the signal 17 by the command :

slay -s SIGUSR2 -S -v child_appX

The child process terminates. We are given then the output:

Process 340002 (child_appX) terminated SIGUSR2 code=0 by process 446495 value=0.

But we can't find any .ptrace file anywhere.

--------------------

3 -

Configuring a "Profile As" >" C/C++ QNX Attach" session on a child process from Momentics gives no result but the 
termination of the child process (same as case 2).

we also can't find any .ptrace file anywhere.

--------------------

We have also many simple (one process , one thread with exit() calls or return from main() ) application that execute 
and exit successfully without generating any .ptrace file.

Am I not using the profiling tools properly ?
If it is a limitation for profiling , any workarounds for these problems ?

Best Regards,

Smail
Re: Profiling in QNX / or From QNX Momentics  
It really depends on what qnx version you have, how you exec/spawn, and how you launch it
Without knowing it general notes

1) If you launch from IDE uncheck Remove on exit in profile prefs in IDE if you want to preserve .ptrace files, 
otherwise IDE will delete it
2) Stop profiling singnal is actually to PAUSE profiling not to kill the process, if process died means handler is not 
installed which can happen for few reasons, see below
3) Depending how you exec you may or not may not get children be profiled, a) child has to be also instrumented for 
profiling b) you have to pass same env to trigger profiling, except QPROF_FILE, it has to be modified otherwise child 
will re-open and wipe parent session. Secondary files have to be Imported in IDE after the session using profiling 
import
4) If you fork and not exec trace file will be shared creating a mess


This is my example than works
qnxexehello.c

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

void fun(char * mess) {
	puts(mess);
	sleep(5);
}
void fun2(char * mess) {
	puts(mess);
}

int main(int argc, char * argv[]) {
	fun2("start");
	int count = 0;
	if (argc >= 2)
		count = atoi(argv[1]);
	char* var = getenv("QPROF_FILE");
	printf("Hello World!!! %d %d\n", count, getpid()); /* prints Hello World!!! */
	if (var != NULL) {
		printf("QPROF_FILE=%s\n", var);
	} else {
		printf("QPROF_FILE is not set\n");
	}

	fun("continue");

	if (count <= 0) {
		fun2("sending stop");
		fun("the end");
		exit(0);
	}
	count--;


	int pid = fork();
	if (pid==0) {
		fun("foo1");
		fun2("foo2");
		char scount[10];
		char * xargv[] = { "/tmp/qnxexehello", scount, NULL };
		sprintf(scount, "%d", count);
		if (var != NULL) {
			char * p = strstr(var, "prof");
			if (p != NULL) {
				sprintf(p, "prof%d.ptrace", getpid());
			}
		}
		int rc = execv(xargv[0], xargv);
		printf("went wrong rc=%d\n", rc);
	} else {
		fun("boo1");
		fun("boo2");
	}
	return EXIT_SUCCESS;
}
Re: Profiling in QNX / or From QNX Momentics  
Hello Elena,

Thank you for the instructive example and sorry for delay to reply.

I am working on QNX 7 and I have built all the binaries for profiling.

I guess from the example you gave that gprof doesn't handle multi-process and/or multi-thread profiling out of the box 
and I should implement more functionalities to handle the report generation.

Maybe this helper 
http://sam.zoy.org/writings/programming/gprof.html
in addition to your example can do the job.

Thank you for your help

I wonder why QNX didn't think of tools such as OProfile or Perf for profiling.
Valgrind virtualization generates lots of overhead and can be unsuitable for embedded targets.