none
Resource monitoring of a thread RRS feed

  • Question

  • Since resource monitoring is on process/app-domain level, is there any level we can have control on resource usage of the threads?

    E.g. I have application with several plug-ins running, plug-ins running in threads, I want to turn off the bad plug-ins when they consumes too much resource. Is there a way doing this?

    Thanks,

    Tony

    Tuesday, June 3, 2014 12:51 AM

Answers

  • Nope, the resource monitoring feature works per app domain only.

    The only resource that a thread can be said to consume is CPU time. Now, it may be possible to devise a mechanism to monitor the CPU usage of each thread but even if you do that you have no way to tell which plugin, if any, is responsible for that. Besides, monitoring per app domain makes sense because the app domain can be unloaded with relatively little risk. For threads the only think you can do is to abort the thread but that's a bad idea in 99.9% of the cases because you have no idea what the thread was doing at the time.

    Tuesday, June 3, 2014 4:11 AM
    Moderator

All replies

  • Nope, the resource monitoring feature works per app domain only.

    The only resource that a thread can be said to consume is CPU time. Now, it may be possible to devise a mechanism to monitor the CPU usage of each thread but even if you do that you have no way to tell which plugin, if any, is responsible for that. Besides, monitoring per app domain makes sense because the app domain can be unloaded with relatively little risk. For threads the only think you can do is to abort the thread but that's a bad idea in 99.9% of the cases because you have no idea what the thread was doing at the time.

    Tuesday, June 3, 2014 4:11 AM
    Moderator
  • It is hard to tell without knowing exactly what kind of resources you are trying to monitor. For example, to monitor time spent per thread you can periodically call GetThreadTimes (http://msdn.microsoft.com/en-us/library/windows/desktop/ms683237(v=vs.85).aspx). Some things you can monitor with WMI. More sophisticated monitoring techniques involve interception of APIs responsible for the resource allocation and saving the API statistics in the TLS. If you are willing to run with a profiling agent attached, you can implement method entry - exit hooks in ICorProfilerCallback (http://msdn.microsoft.com/en-us/library/ms231434(v=vs.110).aspx) and monitor arguments of managed functions responsible for the resource allocation. You can also track the managed heap allocations per thread using ICorProfilerCallback. As I said, it all depends on what you would like to monitor.

    Tuesday, June 3, 2014 4:55 AM