ICLRProfiling::AttachProfiler Method
Attaches the specified profiler to the specified process.
HRESULT AttachProfiler( [in] DWORD dwProfileeProcessID, [in] DWORD dwMillisecondsMax, // optional [in] const CLSID * pClsidProfiler, [in] LPCWSTR wszProfilerPath, // optional [in] size_is(cbClientData)] void * pvClientData, // optional [in] UINT cbClientData); // optional
This method returns the following HRESULTs.
|
HRESULT |
Description |
|---|---|
|
S_OK |
The specified profiler has successfully attached to the target process. |
|
CORPROF_E_PROFILER_ALREADY_ACTIVE |
There is already a profiler active or attaching to the target process. |
|
CORPROF_E_PROFILER_NOT_ATTACHABLE |
The specified profiler does not support attachment. The trigger process may attempt to attach a different profiler. |
|
CORPROF_E_PROFILEE_INCOMPATIBLE_WITH_TRIGGER |
Unable to request a profiler attachment, because the version of the target process is incompatible with the current process that is calling AttachProfiler. |
|
HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) |
The user of the trigger process does not have access to the target process. |
|
HRESULT_FROM_WIN32(ERROR_PRIVILEGE_NOT_HELD) |
The user of the trigger process does not have the privileges necessary to attach a profiler to the given target process. The application event log may contain more information. |
|
CORPROF_E_IPC_FAILED |
A failure occurred when communicating with the target process. This commonly happens if the target process was shutting down. |
|
HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) |
The target process does not exist or is not running a CLR that supports attachment. This may indicate that the CLR was unloaded since the call to the runtime enumeration method. |
|
HRESULT_FROM_WIN32(ERROR_TIMEOUT) |
The timeout expired without beginning to load the profiler. You can retry the attach operation. Timeouts occur when a finalizer in the target process runs for a longer time than the timeout value. |
|
E_INVALIDARG |
One or more parameters have invalid values. |
|
E_FAIL |
Some other, unspecified failure occurred. |
|
Other error codes |
If the profiler’s ICorProfilerCallback3::InitializeForAttach method returns an HRESULT that indicates failure, AttachProfiler returns that same HRESULT. In this case, E_NOTIMPL is converted to CORPROF_E_PROFILER_NOT_ATTACHABLE. |
For more information about attaching and detaching profilers, see Profiler Attach and Detach.
Memory Management
In keeping with COM conventions, the caller of AttachProfiler (for example, the trigger code authored by the profiler developer) is responsible for allocating and de-allocating the memory for the data that the pvClientData parameter points to. When the CLR executes the AttachProfiler call, it makes a copy of the memory that pvClientData points to and transmits it to the target process. When the CLR inside the target process receives its own copy of the pvClientData block, it passes the block to the profiler through the InitializeForAttach method, and then deallocates its copy of the pvClientData block from the target process.
Platforms: See .NET Framework System Requirements.
Header: CorProf.idl, CorProf.h
Library: CorGuids.lib
.NET Framework Versions: 4.5, 4