Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Etw › TraceSetInformation

TraceSetInformation

関数
トレースセッションに対して各種設定情報を構成する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

WIN32_ERROR TraceSetInformation(
    ULONGLONG TraceId,
    TRACE_QUERY_INFO_CLASS InformationClass,
    void* TraceInformation,
    DWORD InformationLength
);

パラメーター

名前方向説明
TraceIdULONGLONGin情報を設定する対象トレースセッションのハンドル。
InformationClassTRACE_QUERY_INFO_CLASSin有効または無効にする情報クラス。クラスが取得する情報は、イベントの拡張データセクションに含まれます。有効にできる情報クラスの一覧については、TRACE_QUERY_INFO_CLASS 列挙型を参照してください。
TraceInformationvoid*in情報クラス固有のデータへのポインター。このパラメーターの内容は情報クラスによって決まります。
InformationLengthDWORDinTraceInformation バッファー内のデータのサイズ(バイト単位)。

戻り値の型: WIN32_ERROR

公式ドキュメント

イベントトレースセッションの設定を構成します。

戻り値

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

関数が失敗した場合、戻り値は次のいずれかのエラーコードです。

解説(Remarks)

この関数は、StartTrace を呼び出した後に呼び出します。

InformationClass パラメーターが TraceStackTracingInfo に設定されている場合、この関数を呼び出すと、指定したカーネルイベントのスタックトレースが有効になります。この関数を後続で呼び出すと、スタックトレースが有効になっているカーネルイベントの以前の一覧が上書きされます。スタックトレースを無効にするには、InformationClassTraceStackTracingInfo に、InformationLength を 0 に設定してこの関数を呼び出します。

イベントの拡張データセクションには、コールスタックが含まれます。拡張データのレイアウトは StackWalk_Event MOF クラスによって定義されます。

通常、64 ビットコンピューターでは、ページフォールトが許可されない特定のコンテキストにおいてカーネルスタックをキャプチャできません。x64 でカーネルスタックのウォークを有効にするには、DisablePagingExecutive メモリ管理レジストリ値を 1 に設定します。DisablePagingExecutive レジストリ値は、次のレジストリキーの下にあります: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management。これはシステムのメモリ使用量を増加させるため、一時的な診断目的でのみ行ってください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

WIN32_ERROR TraceSetInformation(
    ULONGLONG TraceId,
    TRACE_QUERY_INFO_CLASS InformationClass,
    void* TraceInformation,
    DWORD InformationLength
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint TraceSetInformation(
    ulong TraceId,   // ULONGLONG
    int InformationClass,   // TRACE_QUERY_INFO_CLASS
    IntPtr TraceInformation,   // void*
    uint InformationLength   // DWORD
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function TraceSetInformation(
    TraceId As ULong,   ' ULONGLONG
    InformationClass As Integer,   ' TRACE_QUERY_INFO_CLASS
    TraceInformation As IntPtr,   ' void*
    InformationLength As UInteger   ' DWORD
) As UInteger
End Function
' TraceId : ULONGLONG
' InformationClass : TRACE_QUERY_INFO_CLASS
' TraceInformation : void*
' InformationLength : DWORD
Declare PtrSafe Function TraceSetInformation Lib "advapi32" ( _
    ByVal TraceId As LongLong, _
    ByVal InformationClass As Long, _
    ByVal TraceInformation As LongPtr, _
    ByVal InformationLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TraceSetInformation = ctypes.windll.advapi32.TraceSetInformation
TraceSetInformation.restype = wintypes.DWORD
TraceSetInformation.argtypes = [
    ctypes.c_ulonglong,  # TraceId : ULONGLONG
    ctypes.c_int,  # InformationClass : TRACE_QUERY_INFO_CLASS
    ctypes.POINTER(None),  # TraceInformation : void*
    wintypes.DWORD,  # InformationLength : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
TraceSetInformation = Fiddle::Function.new(
  lib['TraceSetInformation'],
  [
    -Fiddle::TYPE_LONG_LONG,  # TraceId : ULONGLONG
    Fiddle::TYPE_INT,  # InformationClass : TRACE_QUERY_INFO_CLASS
    Fiddle::TYPE_VOIDP,  # TraceInformation : void*
    -Fiddle::TYPE_INT,  # InformationLength : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn TraceSetInformation(
        TraceId: u64,  // ULONGLONG
        InformationClass: i32,  // TRACE_QUERY_INFO_CLASS
        TraceInformation: *mut (),  // void*
        InformationLength: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint TraceSetInformation(ulong TraceId, int InformationClass, IntPtr TraceInformation, uint InformationLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_TraceSetInformation' -Namespace Win32 -PassThru
# $api::TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
#uselib "ADVAPI32.dll"
#func global TraceSetInformation "TraceSetInformation" sptr, sptr, sptr, sptr
; TraceSetInformation TraceId, InformationClass, TraceInformation, InformationLength   ; 戻り値は stat
; TraceId : ULONGLONG -> "sptr"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "sptr"
; TraceInformation : void* -> "sptr"
; InformationLength : DWORD -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global TraceSetInformation "TraceSetInformation" int64, int, sptr, int
; res = TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
; TraceId : ULONGLONG -> "int64"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
; TraceInformation : void* -> "sptr"
; InformationLength : DWORD -> "int"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; WIN32_ERROR TraceSetInformation(ULONGLONG TraceId, TRACE_QUERY_INFO_CLASS InformationClass, void* TraceInformation, DWORD InformationLength)
#uselib "ADVAPI32.dll"
#cfunc global TraceSetInformation "TraceSetInformation" int64, int, intptr, int
; res = TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
; TraceId : ULONGLONG -> "int64"
; InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
; TraceInformation : void* -> "intptr"
; InformationLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procTraceSetInformation = advapi32.NewProc("TraceSetInformation")
)

// TraceId (ULONGLONG), InformationClass (TRACE_QUERY_INFO_CLASS), TraceInformation (void*), InformationLength (DWORD)
r1, _, err := procTraceSetInformation.Call(
	uintptr(TraceId),
	uintptr(InformationClass),
	uintptr(TraceInformation),
	uintptr(InformationLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function TraceSetInformation(
  TraceId: UInt64;   // ULONGLONG
  InformationClass: Integer;   // TRACE_QUERY_INFO_CLASS
  TraceInformation: Pointer;   // void*
  InformationLength: DWORD   // DWORD
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TraceSetInformation';
result := DllCall("ADVAPI32\TraceSetInformation"
    , "Int64", TraceId   ; ULONGLONG
    , "Int", InformationClass   ; TRACE_QUERY_INFO_CLASS
    , "Ptr", TraceInformation   ; void*
    , "UInt", InformationLength   ; DWORD
    , "UInt")   ; return: WIN32_ERROR
●TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength) = DLL("ADVAPI32.dll", "dword TraceSetInformation(qword, int, void*, dword)")
# 呼び出し: TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
# TraceId : ULONGLONG -> "qword"
# InformationClass : TRACE_QUERY_INFO_CLASS -> "int"
# TraceInformation : void* -> "void*"
# InformationLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "advapi32" fn TraceSetInformation(
    TraceId: u64, // ULONGLONG
    InformationClass: i32, // TRACE_QUERY_INFO_CLASS
    TraceInformation: ?*anyopaque, // void*
    InformationLength: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
proc TraceSetInformation(
    TraceId: uint64,  # ULONGLONG
    InformationClass: int32,  # TRACE_QUERY_INFO_CLASS
    TraceInformation: pointer,  # void*
    InformationLength: uint32  # DWORD
): uint32 {.importc: "TraceSetInformation", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
uint TraceSetInformation(
    ulong TraceId,   // ULONGLONG
    int InformationClass,   // TRACE_QUERY_INFO_CLASS
    void* TraceInformation,   // void*
    uint InformationLength   // DWORD
);
ccall((:TraceSetInformation, "ADVAPI32.dll"), stdcall, UInt32,
      (UInt64, Int32, Ptr{Cvoid}, UInt32),
      TraceId, InformationClass, TraceInformation, InformationLength)
# TraceId : ULONGLONG -> UInt64
# InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
# TraceInformation : void* -> Ptr{Cvoid}
# InformationLength : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t TraceSetInformation(
    uint64_t TraceId,
    int32_t InformationClass,
    void* TraceInformation,
    uint32_t InformationLength);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
-- TraceId : ULONGLONG
-- InformationClass : TRACE_QUERY_INFO_CLASS
-- TraceInformation : void*
-- InformationLength : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const TraceSetInformation = lib.func('__stdcall', 'TraceSetInformation', 'uint32_t', ['uint64_t', 'int32_t', 'void *', 'uint32_t']);
// TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
// TraceId : ULONGLONG -> 'uint64_t'
// InformationClass : TRACE_QUERY_INFO_CLASS -> 'int32_t'
// TraceInformation : void* -> 'void *'
// InformationLength : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  TraceSetInformation: { parameters: ["u64", "i32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength)
// TraceId : ULONGLONG -> "u64"
// InformationClass : TRACE_QUERY_INFO_CLASS -> "i32"
// TraceInformation : void* -> "pointer"
// InformationLength : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t TraceSetInformation(
    uint64_t TraceId,
    int32_t InformationClass,
    void* TraceInformation,
    uint32_t InformationLength);
C, "ADVAPI32.dll");
// $ffi->TraceSetInformation(TraceId, InformationClass, TraceInformation, InformationLength);
// TraceId : ULONGLONG
// InformationClass : TRACE_QUERY_INFO_CLASS
// TraceInformation : void*
// InformationLength : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Advapi32 extends StdCallLibrary {
    Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
    int TraceSetInformation(
        long TraceId,   // ULONGLONG
        int InformationClass,   // TRACE_QUERY_INFO_CLASS
        Pointer TraceInformation,   // void*
        int InformationLength   // DWORD
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun TraceSetInformation = TraceSetInformation(
    TraceId : UInt64,   # ULONGLONG
    InformationClass : Int32,   # TRACE_QUERY_INFO_CLASS
    TraceInformation : Void*,   # void*
    InformationLength : UInt32   # DWORD
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef TraceSetInformationNative = Uint32 Function(Uint64, Int32, Pointer<Void>, Uint32);
typedef TraceSetInformationDart = int Function(int, int, Pointer<Void>, int);
final TraceSetInformation = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<TraceSetInformationNative, TraceSetInformationDart>('TraceSetInformation');
// TraceId : ULONGLONG -> Uint64
// InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
// TraceInformation : void* -> Pointer<Void>
// InformationLength : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TraceSetInformation(
  TraceId: UInt64;   // ULONGLONG
  InformationClass: Integer;   // TRACE_QUERY_INFO_CLASS
  TraceInformation: Pointer;   // void*
  InformationLength: DWORD   // DWORD
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'TraceSetInformation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TraceSetInformation"
  c_TraceSetInformation :: Word64 -> Int32 -> Ptr () -> Word32 -> IO Word32
-- TraceId : ULONGLONG -> Word64
-- InformationClass : TRACE_QUERY_INFO_CLASS -> Int32
-- TraceInformation : void* -> Ptr ()
-- InformationLength : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let tracesetinformation =
  foreign "TraceSetInformation"
    (uint64_t @-> int32_t @-> (ptr void) @-> uint32_t @-> returning uint32_t)
(* TraceId : ULONGLONG -> uint64_t *)
(* InformationClass : TRACE_QUERY_INFO_CLASS -> int32_t *)
(* TraceInformation : void* -> (ptr void) *)
(* InformationLength : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("TraceSetInformation" trace-set-information :convention :stdcall) :uint32
  (trace-id :uint64)   ; ULONGLONG
  (information-class :int32)   ; TRACE_QUERY_INFO_CLASS
  (trace-information :pointer)   ; void*
  (information-length :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TraceSetInformation = Win32::API::More->new('ADVAPI32',
    'DWORD TraceSetInformation(UINT64 TraceId, int InformationClass, LPVOID TraceInformation, DWORD InformationLength)');
# my $ret = $TraceSetInformation->Call($TraceId, $InformationClass, $TraceInformation, $InformationLength);
# TraceId : ULONGLONG -> UINT64
# InformationClass : TRACE_QUERY_INFO_CLASS -> int
# TraceInformation : void* -> LPVOID
# InformationLength : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型