3-sub appdomain created in a process(main appdomain), and how to get sub-Appdomain cpu usage, memory usage, and the thread number in real-time?
Asked
Active
Viewed 1,569 times
-1
-
this was asked before as was closed on `4 NOV2014` google search reveals everything lol [c# how to get sub-appdomain cpu usage, memory usage](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=c%23%20how%20to%20get%20sub-appdomain%20cpu%20usage%2c%20memory%20usage) it's the first one in the search – MethodMan Nov 17 '14 at 03:47
2 Answers
0
CPU usage and other related information does no really apply to .Net AppDomain and it only exists at CLR level and not at OS level. So, by default you can only track these details at a process level.
Since .Net 4.0, AppDomiain has static property called MonitoringIsEnabled
. Once this is set, you can track the details using other properties (AppDomain.Monitor<XXXX>
). Note that this is still not real time. This might be a good start.

danish
- 5,550
- 2
- 25
- 28
0
Using the following method, the acquired values seems incorrect.
public static double GetAppDomainCpuUsage(AppDomain hostDomain)
{
if (Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds > 0)
return hostDomain.MonitoringTotalProcessorTime.TotalMilliseconds * 100 / Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds;
return 0;
}
public static double GetAppDomainMemoryUsage(AppDomain hostDomain)
{
if (AppDomain.MonitoringSurvivedProcessMemorySize > 0)
return (double)hostDomain.MonitoringSurvivedMemorySize * 100 / (double)AppDomain.MonitoringSurvivedProcessMemorySize;
return 0;
}
AppDomain.MonitoringIsEnabled = true;

taotao
- 1
- 6