Dtracing short-term application

I wrote a DTrace script that measures the time spent inside a function in my C program. The program itself starts, prints some data, and then exits.

The problem is that it ends the path to speed up for me to get the process ID and start DTrace.

Right now I have a sleep () statement inside my code that gives me enough time to run DTrace. To change the code to get information about it, he defeats the Dtrace target ... correctly.

Basically what I need is to get DTrace to wait for the process identifier to appear, and then run my script against it.

+4
source share
1 answer

Presumably you are using the pid provider, in which case there is no way to enable these probes before the process is created. The usual solution for this is to call the program from dtrace itself with its -c option.

If for some reason you cannot do this (i.e. your process must be running in some environment configured by some other process), you can try a more complex approach: use proc: start or proc: exec-success to track when your program is actually running, use the stop () action to stop the program at that point, and then use system () to start another DTrace call that uses the pid provider, and then "crop" again.

+5
source

Source: https://habr.com/ru/post/1397216/


All Articles