Performance Monitor .NET CLR Networking 4.0.0.0 Instance naming

不羁的心 提交于 2019-12-23 10:01:36

问题


I'm trying to use a Performance Counter do determine how many bytes my application has sent or received. I followed the suggested solution found here: Calculating Bandwidth, but the instance of my application doesn’t show up in the “.NET CLR Networking” category. Exception message:

"Instance 'ApplicationName[8824]' does not exist in the specified Category"

(I have added <performanceCounters enabled="true"/> in my App.config and it still it cannot be found after some networking activities)

So I started Performance Monitor so see the error with my own eyes. As expected, my application doesn't show up in the .NET CLR Networking category, but it can luckily be found in the .NET CLR Networking 4.0.0.0 category.

However, my problem is that I cannot figure out how instance name is generated. Here is the name of the instance I see in the Performance Monitor: ApplicationName.exe_p4952_r15_ad1.

So far I have figured out that the first parts must be made of ProcessName and PID, but I have no clue what the last two ("r15" and "ad1") pieces come from.

Does somebody have a clue what the last two pieces could be?

One solution would be to enumerate all the instances found in the “.NET CLR Networking 4.0.0.0” category and search for ApplicationName.exe_PID*, but would prefer to look for the correct name directly (if possible).


回答1:


Check this link for more information on how the name is built. In short the "rXX" is the runtime ID of the common language runtime (instance) that executes your code.

This new naming convention was established so that in side-by-side scenarios (where you have more than one CLR instance in a process; which is a new feature starting with .NET 4.0) you can actually differentiate the performance counters.

The "adXX" is not described on the page above, but from the acronym I'd suppose it stands for Application Domain. The number could possibly be the AppDomain.Id of the application domain.




回答2:


See this answer on how to get the correct name. In short, use

var processFileName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
var instanceName = VersioningHelper.MakeVersionSafeName(processFileName, ResourceScope.Machine, ResourceScope.AppDomain);


来源:https://stackoverflow.com/questions/8654104/performance-monitor-net-clr-networking-4-0-0-0-instance-naming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!