Launch Processes in Stopped State


In many cases, it is important to profile an application from the very beginning of its execution. When launching processes, NVIDIA System Profiler takes care of it by making sure that the profiling session is fully initialized before making the exec() system call on Linux, and by using the JDWP protocol on Android.

If the process launch capabilities of NVIDIA System Profiler are not sufficient, the application should be launched manually, and the profiler should be configured to attach to the already launched process. One approach would be to call sleep() somewhere early in the application code, which would provide time for the user to attach to the process in the profiler, but there are two other more convenient mechanisms that can be used on Linux, without the need to recompile the application. (Note that the rest of this section is only applicable to Linux-based target devices, not Android.)

Both mechanisms ensure that between the time the process is created (and therefore its PID is known) and the time any of the application's code is called, the process is stopped and waits for a signal to be delivered before continuing.

LD_PRELOAD

The first mechanism uses LD_PRELOAD environment variable. It only works with dynamically linked binaries, since static binaries do not invoke the runtime linker, and therefore are not affected by the LD_PRELOAD environment variable.

When launching the process, preload the following library, depending on the process architecture:

The most common way to do that is to specify the environment variable as part of the process launch command, for example:

$ LD_PRELOAD=/opt/nvidia/tegra_system_profiler/libLauncher64.so ./my-aarch64-binary --arguments

When loaded, this library will send itself a SIGSTOP signal, which is equivalent to typing Ctrl+Z in the terminal. The process is now a background job, and you can use standard commands like jobs, fg and bg to control them. Use jobs -l to see the PID of the launched process.

When attaching to a stopped process, NVIDIA System Profiler will send SIGCONT signal, which is equivalent to using the bg command.

Launcher

The second mechanism can be used with any binary. Use /opt/nvidia/tegra_system_profiler/launcher to launch your application, for example:

$ /opt/nvidia/tegra_system_profiler/launcher ./my-binary --arguments

The process will be launched, daemonized, and wait for SIGUSR1 signal. After attaching to the process with NVIDIA System Profiler, the user needs to manually resume execution of the process from command line:

$ pkill -USR1 launcher

Note that pkill will send the signal to any process with the matching name. If that is not desirable, use kill to send it to a specific process. The standard output and error streams are redirected to /tmp/stdout_<PID>.txt and /tmp/stderr_<PID>.txt.

The launcher mechanism is more complex and less automated than the LD_PRELOAD option, but gives more control to the user.


 

NVIDIA® System Profiler Documentation Rev. 3.9.170817 ©2017. NVIDIA Corporation. All Rights Reserved.