NameProfileA

The NameProfile function assigns a string to the specified process or thread.

PROFILE_COMMAND_STATUS PROFILERAPI NameProfileA(
                                   const char *pszName, 
                                   PROFILE_CONTROL_LEVEL Level,
                                   unsigned int dwId);

Parameters

pszName

The name of the profiling element. A name is invalid (resulting in NameProfileA return NAME_ERROR_INVALID_NAME) if:

Level

Indicates the profile level to which performance data collection can be applied. The following PROFILE_CONTROL_LEVEL enumerators can be used to indicate one of the three levels to which performance data collection can be applied:

dwId

Profiling level identifier. Use the process or thread identifier that is generated by the system.

Property Value/Return Value

The function indicates success or failure by using PROFILE_COMMAND_STATUS enumeration. The return value can be one of the following:

Enumerator Description

NAME_ERROR_ID_NOEXIST

The profiling element specified does not exist.

NAME_ERROR_INVALID_NAME

The name is invalid.

NAME_ERROR_LEVEL_NOEXIST

The profile level specified does not exist.

NAME_ERROR_NO_SUPPORT

The specified operation is not supported.

NAME_ERROR_OUTOFMEMORY

Memory was not available to record the event.

NAME_ERROR_REDEFINITION

A name was already assigned to the profile element. The name in this function is ignored.

NAME_ERROR_TEXTTRUNCATED

The name text exceeded 32 characters including the null character and was therefore truncated.

NAME_OK

Name was registered successfully.

Remarks

Only one name can be assigned to each process or thread. After a profiling element is named, subsequent calls to NameProfile for that element are ignored.

If the same name is given to different threads or processes, the report will include data from all elements at that level with that name.

If you specify a process or thread other than the current one, you must make sure that it has initialized and started running before you name it. Otherwise, the NameProfile method fails.

Important

CreateProcess() and CreateThread() API functions can return before the thread or process is initialized.

.NET Framework Equivalent

Microsoft.VisualStudio.Profiler.dll

Function Information

Header: Declared in VSPerf.h

Import library: VSPerf.lib

Example

The following code illustrates the NameProfile generic function call. The example assumes the use of Win32 string macros and the compiler settings for ANSI to determine whether the code calls the ANSI enabled function.

void ExerciseNameProfile()
{
    // Variables used to print output.
    HRESULT hResult;
    TCHAR tchBuffer[256];

    // Create and initialize variables to pass to 
    // ExerciseNameProfile.  The value of this 
    // parameter is based on the needs of the code;
    // and for the sake of simplicity in this example, 
    // the variable is assigned an arbitrary value.
    TCHAR * profileName = TEXT("ExerciseNameProfile");

    // Declare enumeration to hold result of call to 
    // ExerciseNameProfle.
    PROFILE_COMMAND_STATUS nameResult;

    nameResult =  NameProfile(
        profileName,
        PROFILE_GLOBALLEVEL,
        PROFILE_CURRENTID);

    // Format and print result.
    LPCTSTR pszFormat = TEXT("%s %d.\0");
    TCHAR* pszTxt = TEXT("NameProfile returned");
    hResult = StringCchPrintf(tchBuffer, 256, pszFormat, 
        pszTxt, nameResult);

#ifdef DEBUG
    OutputDebugString(tchBuffer);
#endif
}

See Also

Reference

NameProfileW

Other Resources

Visual Studio Profiler API Reference (Native)