none
Efficient way to get ".NET CLR" perfcounters in-process RRS feed

  • Question

  • I want to find the most efficient way to access the CLR performance counters in-process (e.g. ".NET CLR Memory" or ".NET CLR Jit"). I use the CLR Profiling API, so I can do this natively (preferred), but also managed if necessary.

    I do know, I can use PDH.dll to query perfcounters natively. However I am trying to avoid PDH.dll, since it has numerous drawbacks and quirks (instance-index handling, translation, permissions, ...).

    My real question is, is there a way to get to the CLR metrics data-structures directly in-memory and read them as they are (without going through the perfcounter API)? When studying the Shared Source CLR, I found perfcounterdefs.h, which contains all of these data structures. Is there a way to get there directly? Should I even consider this direction, or will I drive straight to hell, when I get my hands on internal data structures?

    Thanks,
    -Christoph

    Wednesday, October 23, 2013 7:29 AM

All replies

  • hi  Christophe,  

    Have you  tried to  use System.Diagnostics.PerformanceCounter  

    please try to  take a  look  at this link  http://www.codeproject.com/Articles/8590/An-Introduction-To-Performance-Counters

    hope  this  help 


    A man's dreams are an index to his greatness

    Wednesday, October 23, 2013 7:49 AM
  • It looks like managed PerformanceCounters do suffer from the same problems as the PDH.dll:

    I want to avoid all these problems and just get these metrics from the current process. I have found, that the structs I need are defined in "perfcounterdefs.h" (from SSCLI). Is there a way to find a pointer that points to that data, so I can just plainly read it?

    Wednesday, October 23, 2013 9:28 AM
  • Hi Christoph,

    I cannot find the solution that while meet your requirements. So I recommend you post a new thread on http://social.msdn.microsoft.com/Forums/en-US/home?forum=wptk_v4 for more effective response. Here is a tool about performance analysis of logs. I hope this post will give you inspiration.

    http://pal.codeplex.com/

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 28, 2013 9:20 AM
    Moderator
  • plese check the following link on run time profiling..

    http://msdn.microsoft.com/en-us/library/w4bz2147.aspx

    Tuesday, October 29, 2013 4:56 AM
  • Update: I was able to solve this (for CLR 2.0 ONLY) by opening the shared memory "Global\\Cor_Public_IPCBlock_%PID%" *. Then casting that pointer to "PublicIPCControlBlock" **. I can read all the CLR related metrics directly from memory there.

    However, that shared memory cannot be found when run in CLR 4.5. Can you give me a hint on how that might be named in CLR 4.x? 

    * found it in "clr\src\ipcman\ipcshared.h"
    ** copied from "clr\src\ipcman\ipcheader.h"



    Wednesday, November 6, 2013 2:09 PM
  • Hah! I just found the shared memory for V4 via AccessChk: "Global\\Cor_Private_IPCBlock_v4_%PID%". Thank you Mark Russinovich!

    However, I would still need the new V4 data structures for reading the memory correctly. Is there any chance to get those?


    Wednesday, November 6, 2013 3:06 PM
  • An alternate way might be to try it out like shown at: http://geekswithblogs.net/akraus1/archive/2009/05/27/132456.aspx. Not pretty but it does work.

    The basic idea is to loop through all instance names until you found the one for your process in question.

    Sunday, November 10, 2013 4:42 PM
  • Update: I was able to solve this (for CLR 2.0 ONLY) by opening the shared memory "Global\\Cor_Public_IPCBlock_%PID%" *. Then casting that pointer to "PublicIPCControlBlock" **. I can read all the CLR related metrics directly from memory there.

    However, that shared memory cannot be found when run in CLR 4.5. Can you give me a hint on how that might be named in CLR 4.x? 

    * found it in "clr\src\ipcman\ipcshared.h"
    ** copied from "clr\src\ipcman\ipcheader.h"



    WARNING: You are using unsupported internal data structures. This is not public surface area. The data structures or their location can change between major releases or minor releases of .NET. Use it only at your own risk and be aware that any Security update can break your functionality.

    -Karel

    Thursday, March 6, 2014 8:43 PM
    Moderator