Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Attached Profiler

I know you can determine if a debugger is attached by using System.Diagnostics.Debugger.IsAttached, but is there a way of determining if a profiler is attached?

My profiler can't trace tasks through the threadpool so I want to automaticly disable parallelism when profiling.

like image 952
Fowl Avatar asked Jan 16 '23 19:01

Fowl


2 Answers

For the standard profiler interface, an environment variable needs to be set.

I guess you can just check this via the Environment class.

The variable is called COR_ENABLE_PROFILING and if enabled, will be set to 1.

like image 86
leppie Avatar answered Jan 18 '23 10:01

leppie


Debugger.IsAttached code is included whether debug or release build. And a debugger can be attached to release builds to.

Hence System.Diagnostics.Debugger.IsAttached would return False if no debugger (or profiler) is attached.

Note: I am not sure about SlimTune but Profilers you tend to attach to the process: How to: Attach and Detach the Profiler to Running Processes

like image 29
Jeremy Thompson Avatar answered Jan 18 '23 09:01

Jeremy Thompson