How to write the SIGPROF handler that calls AsyncGetCallTrace?

I am writing a short and simple profiler (in C) that is designed to regularly output stack trace for threads on different Java clients. I should use the undocumented AsyncGetCallTrace function instead of GetStackTrace to minimize intrusion and allow stack tracing regardless of the state of the stream. The source code of the function can be found here: http://download.java.net/openjdk/jdk6/promoted/b20/openjdk-6-src-b20-21_jun_2010.tar.gz in hotspot / src / share / vm / prims / forte .cpp. I found several help pages that document the JVMTI, signal processing and time, as well as a blog with details on how to set up the AsyncGetCallTrace call: http://jeremymanson.blogspot.com/2007/05/profiling-with-jvmtijvmpi- SIGPROF -and.html.

This blog is missing code for actually calling a function in a signal handler (the author assumes that the reader can do this on his own). I ask for help with this. I am not sure how and where to create the ASGCT_CallTrace structure (and the internal ASGCT_CallFrame structure) as defined in the above forte.cpp file. The ASGCT_CallTrace structure is one of the parameters passed to AsyncGetCallTrace, so I need to create it, but I don’t know how to get the correct values ​​for my fields: JNIEnv * env_id, jint num_frames and JVMPI_CallFrame. Also, I don't know what the third parameter passed to AsyncGetCallTrace (void ucontext) should be?

The above problem is the main one I have. However, other issues I came across include: [1] SIGPROF does not seem to be raised by the timer precisely at certain intervals, but a little less often. That is, if I set a timer to send SIGPROF every second (1 s, 0 μs), then in a 5-second run I get less than 5 outputs of SIGPROF handlers (usually 1-3) [2] SIGPROF output does not appear at all during Thread.sleep in Java code. That way, if SIGPROF needs to be sent every second, and I have Thread.sleep (5000) ;, I will not receive output from the handler while this code is executing.

Any help would be greatly appreciated. Additional information (as well as parts of the code and output) will be sent upon request.

Thank!

+3
1

- , , , .

ASGCT_CallTrace ( ASGCT_CallFrame) ​​ , , : ASGCT_CallTrace; JNIEnv * env; global_VM_pointer- > AttachCurrentThread ((void **) & env, NULL); trace.env_id = env; trace.num_frames = 0; ASGCT_CallFrame [25]; trace.frames = storage;

uContext: ucontext_t uContext; getcontext (& uContext);

: AsyncGetCallTrace (& trace, 25, & uContext);

, , , . , , , java- . - , ( ).

: [1] SIGPROF, . , . [2] . , .

+1

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


All Articles