QueryAllTracesW 関数 (evntrace.h)

QueryAllTraces 関数は、呼び出し元がクエリを実行するアクセス許可を持つすべてのイベント トレース セッションのプロパティと統計情報を取得します。

構文

ULONG WMIAPI QueryAllTracesW(
  [out] PEVENT_TRACE_PROPERTIES *PropertyArray,
  [in]  ULONG                   PropertyArrayCount,
  [out] PULONG                  LoggerCount
);

パラメーター

[out] PropertyArray

イベント トレース セッションのセッション プロパティと統計情報を受け取る EVENT_TRACE_PROPERTIES 構造体へのポインターの配列。

EVENT_TRACE_PROPERTIES構造体の Wnode.BufferSizeLoggerNameOffsetLogFileNameOffset メンバーのみを設定する必要があります。 他のメンバーはすべて 0 に設定する必要があります。

[in] PropertyArrayCount

PropertyArray 配列内の構造体の数。 この値は、ETW がサポートするイベント トレース セッションの最大数である 64 以下である必要があります。

Windows 10:PropertyArrayCount は 64 より大きく、一部のシステムでは 64 を超えるトレース セッションがサポートされる場合があります。

[out] LoggerCount

コンピューターで開始されたイベント トレース セッションの実際の数。

戻り値

関数が成功した場合、戻り値は ERROR_SUCCESS です。

関数が失敗した場合、戻り値は システム エラー コードの 1 つです。 一般的なエラーとその原因を次に示します。

  • ERROR_INVALID_PARAMETER

    次のいずれかが当てはまります。

    • PropertyArrayCount が 0 であるか、サポートされているセッションの最大数を超えています
    • PropertyArrayNULL です
  • ERROR_MORE_DATA

    プロパティ配列が小さすぎてすべてのセッションの情報を受信することはできません (SessionCountPropertyArrayCount より大きい)。 この関数は、 PropertyArrayCount で指定されたプロパティ構造体の数をプロパティ配列に入力します。

注釈

イベント トレース コントローラーは、この関数を呼び出します。

この関数は、呼び出し元がクエリを実行するアクセス許可を持つトレース セッションを取得します。 管理者特権で実行されているユーザー、パフォーマンス ログ ユーザー グループ内のユーザー、LocalSystem、LocalService、NetworkService として実行されているサービスは、すべてのトレース セッションを表示できます。

この関数は、プライベート ログ セッションを返しません。

1 つのセッションの情報を取得するには、 ControlTrace 関数を使用し、 ControlCode パラメーターを EVENT_TRACE_CONTROL_QUERY に設定します。

次の例は、この関数を呼び出す方法を示しています。

#include <windows.h>
#include <evntrace.h>
#include <vector>

const unsigned MAX_SESSION_NAME_LEN = 1024;
const unsigned MAX_LOGFILE_PATH_LEN = 1024;
const unsigned PropertiesSize =
    sizeof(EVENT_TRACE_PROPERTIES) +
    (MAX_SESSION_NAME_LEN * sizeof(CHAR)) +
    (MAX_LOGFILE_PATH_LEN * sizeof(CHAR));

int main()
{
    ULONG status;
    std::vector<EVENT_TRACE_PROPERTIES*> sessions; // Array of pointers to property structures
    std::vector<BYTE> buffer;                      // Buffer that contains all the property structures
    ULONG sessionCount;                            // Actual number of sessions started on the computer

    // The size of the session name and log file name used by the
    // controllers are not known, therefore create a properties structure that allows
    // for the maximum size of both.

    try
    {
        sessionCount = 64; // Start with room for 64 sessions.
        do
        {
            sessions.resize(sessionCount);
            buffer.resize(PropertiesSize * sessionCount);

            for (size_t i = 0; i != sessions.size(); i += 1)
            {
                sessions[i] = (EVENT_TRACE_PROPERTIES*)&buffer[i * PropertiesSize];
                sessions[i]->Wnode.BufferSize = PropertiesSize;
                sessions[i]->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
                sessions[i]->LogFileNameOffset = sizeof(EVENT_TRACE_PROPERTIES) + (MAX_SESSION_NAME_LEN * sizeof(CHAR));
            }

            status = QueryAllTracesA(&sessions[0], sessionCount, &sessionCount);
        } while (status == ERROR_MORE_DATA);

        if (status != ERROR_SUCCESS)
        {
            printf("Error calling QueryAllTraces: %u\n", status);
        }
        else
        {
            printf("Actual session count: %u.\n\n", sessionCount);

            for (ULONG i = 0; i < sessionCount; i++)
            {
                WCHAR sessionGuid[50];
                (void)StringFromGUID2(sessions[i]->Wnode.Guid, sessionGuid, ARRAYSIZE(sessionGuid));

                printf(
                    "Session GUID: %ls\n"
                    "Session ID: %llu\n"
                    "Session name: %s\n"
                    "Log file: %s\n"
                    "min buffers: %u\n"
                    "max buffers: %u\n"
                    "buffers: %u\n"
                    "buffers written: %u\n"
                    "buffers lost: %u\n"
                    "events lost: %u\n"
                    "\n",
                    sessionGuid,
                    sessions[i]->Wnode.HistoricalContext,
                    (PCSTR)((LPCBYTE)sessions[i] + sessions[i]->LoggerNameOffset),
                    (PCSTR)((LPCBYTE)sessions[i] + sessions[i]->LogFileNameOffset),
                    sessions[i]->MinimumBuffers,
                    sessions[i]->MaximumBuffers,
                    sessions[i]->NumberOfBuffers,
                    sessions[i]->BuffersWritten,
                    sessions[i]->LogBuffersLost,
                    sessions[i]->EventsLost);
            }
        }
    }
    catch (std::bad_alloc const&)
    {
        printf("Error allocating memory for properties.\n");
        status = ERROR_OUTOFMEMORY;
    }

    return status;
}

注意

evntrace.h ヘッダーは、Unicode プリプロセッサ定数の定義に基づいて、この関数の ANSI または Unicode バージョンを自動的に選択するエイリアスとして QueryAllTraces を定義します。 encoding-neutral エイリアスの使用を encoding-neutral ではないコードと混在すると、コンパイル エラーまたはランタイム エラーが発生する不一致が発生する可能性があります。 詳細については、「 関数プロトタイプの規則」を参照してください。

要件

要件
サポートされている最小のクライアント Windows 2000 Professional [デスクトップ アプリのみ]
サポートされている最小のサーバー Windows 2000 Server [デスクトップ アプリのみ]
対象プラットフォーム Windows
ヘッダー evntrace.h
Library Windows 8.1および Windows Server 2012 R2 の Sechost.lib。Windows 8、Windows Server 2012、Windows 7、Windows Server 2008 R2、Windows Server 2008、Windows Vista、Windows XP 上の Advapi32.lib
[DLL] Windows 8.1 および Windows Server 2012 R2 の Sechost.dll;Windows 8、Windows Server 2012、Windows 7、Windows Server 2008 R2、Windows Server 2008、Windows Vista、Windows XP での Advapi32.dll

こちらもご覧ください

ControlTrace

EVENT_TRACE_PROPERTIES

EnumerateTraceGuids