It sounds like you are trying to automate your application when it is being run under the profiler. The goal being to automate a certain set of actions you are interested in profiling. If so ...
I don't know of a way to detect off hand if a process is running under the profiler. Any such detection would likely be flaky.
A more reliable way to do this would be to simply add a parameter to your application which instructs it to automate the scenario. Then simply pass this parameter to the application when you are launching under the profiler (most allow you to pass options to the process). This will greatly simplify the scenario.
An even better solution would be to write a second program whose sole purpose is to drive the application. This removes the test only code from your production application.