Updating an Event Tracing Session
To update the properties of an event tracing session, call the ControlTrace function using the EVENT_TRACE_CONTROL_UPDATE control code. You can specify the session to update using a session handle obtained from an earlier call to StartTrace, or a session name. The properties of the event tracing session are updated using the values specified in the EVENT_TRACE_PROPERTIES structure. You can update only a subset of the properties. For a list of the properties you can update, see the Properties parameter of the ControlTrace function.
If the ControlTrace call is successful, the EVENT_TRACE_PROPERTIES structure is updated to reflect the new property values. The structure will also contain the new run statistics for the event tracing session.
The following example shows how to update the kernel event tracing session. The example queries for the current property values and updates the structure before updating the session.
#include <windows.h>
#include <stdio.h>
#include <wmistr.h>
#include <evntrace.h>
#define MAX_SESSION_NAME_LEN 1024
#define MAX_LOGFILE_PATH_LEN 1024
void wmain(void)
{
ULONG status = ERROR_SUCCESS;
EVENT_TRACE_PROPERTIES* pSessionProperties = NULL;
ULONG BufferSize = 0;
// Allocate memory for the session properties. The memory must
// be large enough to include the log file name and session name.
// This example specifies the maximum size for the session name
// and log file name.
BufferSize = sizeof(EVENT_TRACE_PROPERTIES) +
(MAX_SESSION_NAME_LEN * sizeof(WCHAR)) +
(MAX_LOGFILE_PATH_LEN * sizeof(WCHAR));
pSessionProperties = (EVENT_TRACE_PROPERTIES*) malloc(BufferSize);
if (NULL == pSessionProperties)
{
wprintf(L"Unable to allocate %d bytes for properties structure.\n", BufferSize);
goto cleanup;
}
ZeroMemory(pSessionProperties, BufferSize);
pSessionProperties->Wnode.BufferSize = BufferSize;
// Query for the kernel trace session's current property values.
status = ControlTrace((TRACEHANDLE)NULL, KERNEL_LOGGER_NAME, pSessionProperties, EVENT_TRACE_CONTROL_QUERY);
if (ERROR_SUCCESS != status)
{
if (ERROR_WMI_INSTANCE_NOT_FOUND == status)
{
wprintf(L"The Kernel Logger is not running.\n");
}
else
{
wprintf(L"ControlTrace(query) failed with %lu\n", status);
}
goto cleanup;
}
// Update the enable flags to also enable the Process and Thread providers.
pSessionProperties->LogFileNameOffset = 0; // Zero tells ETW not to update the file name
pSessionProperties->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
pSessionProperties->EnableFlags |= EVENT_TRACE_FLAG_PROCESS | EVENT_TRACE_FLAG_THREAD;
// Update the session's properties.
status = ControlTrace((TRACEHANDLE)NULL, KERNEL_LOGGER_NAME, pSessionProperties, EVENT_TRACE_CONTROL_UPDATE);
if (ERROR_SUCCESS != status)
{
wprintf(L"ControlTrace(update) failed with %lu.\n", status);
goto cleanup;
}
wprintf(L"\nUpdated session");
cleanup:
if (pSessionProperties)
{
free(pSessionProperties);
pSessionProperties = NULL;
}
}
Related topics