0

Is there an API to have WinDBG-SOS-like features in .NET?

Given an object, I would like to know how many roots are keeping it alive at runtime from C# within the same process.

Stefano d'Antonio
  • 5,874
  • 3
  • 32
  • 45

2 Answers2

1

ClrMD

NuGet: https://www.nuget.org/packages/Microsoft.Diagnostics.Runtime

And I wrote a small example:

https://github.com/UnoSD/ClrMdExample

Stefano d'Antonio
  • 5,874
  • 3
  • 32
  • 45
0

Yes there is. How all those profiles would work if not? This is called Profiling API: https://msdn.microsoft.com/en-us/library/ms404386(v=vs.110).aspx .

The API itself is unmanaged (COM object). But there is nothing that could stop you to use it from managed code through a RCW.

I am not sure and in doubt if you can profile a process from within itself. I think the profiler must be in another process. Though I see no issue to have process to process communication and feed the data back to the profiled process through some communication method like named pipes.

Łukasz Rozmej
  • 249
  • 2
  • 8
  • Thanks, I'll have a look at the documentation later; do you also have any link to some example? – Stefano d'Antonio Aug 20 '16 at 10:32
  • Sorry I was probably wrong about being able to write a managed profiler :( http://stackoverflow.com/questions/5736845/is-is-possible-to-use-profiling-api-right-from-c You can find interesting blog reference in that post – Łukasz Rozmej Aug 20 '16 at 22:26
  • Digging deeper I found even more interesting things: http://www.topholt.com/c-clr-profiler/ http://research.microsoft.com/en-us/um/redmond/projects/pex/wiki/Microsoft.ExtendedReflection.html – Łukasz Rozmej Aug 20 '16 at 22:32
  • This looks like a very good starting point for your task: http://stackoverflow.com/questions/3898078/obtaining-global-roots-from-net-programs – Łukasz Rozmej Aug 20 '16 at 22:46