Skip to content

davmason/stacksamplingprofiler

Repository files navigation

.Net Core stack sampling profiler

This sample profiler demonstrates how to use ICorProfilerInfo10::SuspendRuntime and ICorProfiler10::ResumeRuntime to sample managed callstacks.

When a profiler wanted to sample callstacks on .Net Framework, our guidance was to use the Win32 SuspendThread API to suspend a thread, then walk the native parts and pass the context to the first managed frame to ICorProfilerInfo2::DoStackSnapshot. This worked mainly, but had some nasty corner cases that the profiler could run in to unsuspectingly. In addition, there is no equivalent API to suspend a random thread on non-Windows platforms.

For .Net Core 3.0 we introduced the SuspendRuntime and ResumeRuntime APIs that pause all managed threads at a known good, walkable state. This allows the profiler to suspend an application, sample the threads, and resume without having to worry about the platform you are running on or the corner cases of suspending a thread on Windows.

Nov 2020 update I added an AsyncSampler that uses signals to sample threads, it is a prototype that is lightly tested on macos and ubuntu 20.04.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published