Can a .NET app detect that it's being profiled?
mdraughn
Posts: 2
Our web application has a development mode config flag that provides behind-the-scenes access that makes it easier for developers to test the application (e.g. force session expiration, run background operations, etc.). This flag also enables additional validation and logging that is useful for detecting defects, but which is unnecessary and too time-consuming for production use.
Unfortunately, these additional activities also reduce the usefulness of the Performance Profiler, since they are doing things that we have already optimized out of production, and they sometimes show up as spurious hot spots.
I'm planning to add a flag to indicate a special profiling mode that keeps the useful testing features but disables the performance-crippling activities. However, since it will be easy to forget to set the flag, I'm wondering if there's a way for the application itself to detect that it's running under the Ants Performance Profiler so it can automatically suppress those features.
Is there some environment variable that's set by the profiler or some method to call? Or is there some way to run special setup and teardown scripts to manage the flag?
Thanks.
Unfortunately, these additional activities also reduce the usefulness of the Performance Profiler, since they are doing things that we have already optimized out of production, and they sometimes show up as spurious hot spots.
I'm planning to add a flag to indicate a special profiling mode that keeps the useful testing features but disables the performance-crippling activities. However, since it will be easy to forget to set the flag, I'm wondering if there's a way for the application itself to detect that it's running under the Ants Performance Profiler so it can automatically suppress those features.
Is there some environment variable that's set by the profiler or some method to call? Or is there some way to run special setup and teardown scripts to manage the flag?
Thanks.
Comments
When you profile by starting an application through the profiler (rather than by attaching to the application), the profiler does set two environment variables for the process: COR_ENABLE_PROFILING and COR_PROFILER
The COR_ENABLE_PROFILING value will be set to 1 and the COR_PROFILER will have the value of the profiler core dll's GUID, which for version 9.2 is {F487E236-8315-45AF-833E-DF0967B1E79A}
I hope that helps!
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?