Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

NameProfileW

Visual Studio 2005

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


PROFILE_COMMAND_STATUS PROFILERAPI NameProfileW(
                                   const VSPWCHAR *pszName, 
                                   PROFILE_CONTROL_LEVEL Level,
                                   unsigned int dwId);

Parameters

pszName

The name of the profiling element. A name is invalid (resulting in NameProfileW 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.

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.

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 ensure that it has initialized and started running before you name it. Otherwise, the NameProfile method fails.

NoteImportant

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

Microsoft.VisualStudio.Profiler.dll

Header: Declared in VSPerf.h

Import library: VSPerf.lib

The following code illustrates the NameProfile generic function call. The example assumes the use of Win32 string macros and the compiler settings for Unicode to determine if the code calls the Unicode 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
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.