Bagikan melalui


Memperbarui Sesi Pelacakan Peristiwa

Untuk memperbarui properti sesi pelacakan peristiwa, panggil fungsi ControlTrace menggunakan kode kontrol EVENT_TRACE_CONTROL_UPDATE . Anda dapat menentukan sesi yang akan diperbarui menggunakan handel sesi yang diperoleh dari panggilan sebelumnya ke StartTrace, atau nama sesi. Properti sesi pelacakan peristiwa diperbarui menggunakan nilai yang ditentukan dalam struktur EVENT_TRACE_PROPERTIES . Anda hanya dapat memperbarui subset properti. Untuk daftar properti yang bisa Anda perbarui, lihat parameter Properti fungsi ControlTrace .

Jika panggilan ControlTrace berhasil, struktur EVENT_TRACE_PROPERTIES diperbarui untuk mencerminkan nilai properti baru. Struktur juga akan berisi statistik eksekusi baru untuk sesi pelacakan peristiwa.

Contoh berikut menunjukkan cara memperbarui sesi pelacakan peristiwa kernel. Contoh kueri untuk nilai properti saat ini dan memperbarui struktur sebelum memperbarui sesi.

#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;
    }
}

Mengonfigurasi dan Memulai Sesi Pencatat Privat

Mengonfigurasi dan Memulai Sesi SystemTraceProvider

Mengonfigurasi dan Memulai Sesi AutoLogger

Mengonfigurasi dan Memulai Sesi Pelacakan Peristiwa

Mengonfigurasi dan Memulai Sesi Pencatat Kernel NT