ホーム › System.SystemInformation › GetProcessorSystemCycleTime
GetProcessorSystemCycleTime
関数プロセッサグループのカーネルモード実行サイクル時間を取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL GetProcessorSystemCycleTime(
WORD Group,
SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* Buffer, // optional
DWORD* ReturnedLength
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Group | WORD | in | サイクル時間を取得する対象のプロセッサグループ番号。 |
| Buffer | SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* | outoptional | グループ内の各プロセッサについて SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION 構造体を受け取るバッファへのポインター。出力時、この構造体の DWORD64 型の CycleTime メンバーには、1 つのプロセッサのサイクル時間が設定されます。 |
| ReturnedLength | DWORD* | inout | バッファのサイズ (バイト単位)。関数が戻ると、このパラメーターには Buffer に書き込まれたバイト数が格納されます。バッファがデータに対して小さすぎる場合、関数は ERROR_INSUFFICIENT_BUFFER で失敗し、ReturnedLength パラメーターに必要なバッファサイズを設定します。 |
戻り値の型: BOOL
公式ドキュメント
指定したプロセッサグループ内の各プロセッサが、アクティブになってから遅延プロシージャ呼び出し (DPC) および割り込みサービスルーチン (ISR) の実行に費やしたサイクル時間を取得します。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、GetLastError を使用します。
エラー値が ERROR_INSUFFICIENT_BUFFER の場合、ReturnedLength パラメーターには必要なバッファサイズが格納されます。
解説(Remarks)
この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を 0x0601 以降として定義します。詳細については、 Using the Windows Headers を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL GetProcessorSystemCycleTime(
WORD Group,
SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* Buffer, // optional
DWORD* ReturnedLength
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetProcessorSystemCycleTime(
ushort Group, // WORD
IntPtr Buffer, // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ref uint ReturnedLength // DWORD* in/out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetProcessorSystemCycleTime(
Group As UShort, ' WORD
Buffer As IntPtr, ' SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ByRef ReturnedLength As UInteger ' DWORD* in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Group : WORD
' Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
' ReturnedLength : DWORD* in/out
Declare PtrSafe Function GetProcessorSystemCycleTime Lib "kernel32" ( _
ByVal Group As Integer, _
ByVal Buffer As LongPtr, _
ByRef ReturnedLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetProcessorSystemCycleTime = ctypes.windll.kernel32.GetProcessorSystemCycleTime
GetProcessorSystemCycleTime.restype = wintypes.BOOL
GetProcessorSystemCycleTime.argtypes = [
ctypes.c_ushort, # Group : WORD
ctypes.c_void_p, # Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ctypes.POINTER(wintypes.DWORD), # ReturnedLength : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetProcessorSystemCycleTime = Fiddle::Function.new(
lib['GetProcessorSystemCycleTime'],
[
-Fiddle::TYPE_SHORT, # Group : WORD
Fiddle::TYPE_VOIDP, # Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
Fiddle::TYPE_VOIDP, # ReturnedLength : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn GetProcessorSystemCycleTime(
Group: u16, // WORD
Buffer: *mut SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION, // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool GetProcessorSystemCycleTime(ushort Group, IntPtr Buffer, ref uint ReturnedLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetProcessorSystemCycleTime' -Namespace Win32 -PassThru
# $api::GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength)#uselib "KERNEL32.dll"
#func global GetProcessorSystemCycleTime "GetProcessorSystemCycleTime" sptr, sptr, sptr
; GetProcessorSystemCycleTime Group, varptr(Buffer), varptr(ReturnedLength) ; 戻り値は stat
; Group : WORD -> "sptr"
; Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "sptr"
; ReturnedLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetProcessorSystemCycleTime "GetProcessorSystemCycleTime" int, var, var ; res = GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength) ; Group : WORD -> "int" ; Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "var" ; ReturnedLength : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetProcessorSystemCycleTime "GetProcessorSystemCycleTime" int, sptr, sptr ; res = GetProcessorSystemCycleTime(Group, varptr(Buffer), varptr(ReturnedLength)) ; Group : WORD -> "int" ; Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "sptr" ; ReturnedLength : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetProcessorSystemCycleTime(WORD Group, SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* Buffer, DWORD* ReturnedLength) #uselib "KERNEL32.dll" #cfunc global GetProcessorSystemCycleTime "GetProcessorSystemCycleTime" int, var, var ; res = GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength) ; Group : WORD -> "int" ; Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "var" ; ReturnedLength : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetProcessorSystemCycleTime(WORD Group, SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* Buffer, DWORD* ReturnedLength) #uselib "KERNEL32.dll" #cfunc global GetProcessorSystemCycleTime "GetProcessorSystemCycleTime" int, intptr, intptr ; res = GetProcessorSystemCycleTime(Group, varptr(Buffer), varptr(ReturnedLength)) ; Group : WORD -> "int" ; Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "intptr" ; ReturnedLength : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetProcessorSystemCycleTime = kernel32.NewProc("GetProcessorSystemCycleTime")
)
// Group (WORD), Buffer (SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out), ReturnedLength (DWORD* in/out)
r1, _, err := procGetProcessorSystemCycleTime.Call(
uintptr(Group),
uintptr(Buffer),
uintptr(ReturnedLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetProcessorSystemCycleTime(
Group: Word; // WORD
Buffer: Pointer; // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetProcessorSystemCycleTime';result := DllCall("KERNEL32\GetProcessorSystemCycleTime"
, "UShort", Group ; WORD
, "Ptr", Buffer ; SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
, "Ptr", ReturnedLength ; DWORD* in/out
, "Int") ; return: BOOL●GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength) = DLL("KERNEL32.dll", "bool GetProcessorSystemCycleTime(int, void*, void*)")
# 呼び出し: GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength)
# Group : WORD -> "int"
# Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "void*"
# ReturnedLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn GetProcessorSystemCycleTime(
Group: u16, // WORD
Buffer: [*c]SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION, // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc GetProcessorSystemCycleTime(
Group: uint16, # WORD
Buffer: ptr SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION, # SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength: ptr uint32 # DWORD* in/out
): int32 {.importc: "GetProcessorSystemCycleTime", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int GetProcessorSystemCycleTime(
ushort Group, // WORD
SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* Buffer, // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
uint* ReturnedLength // DWORD* in/out
);ccall((:GetProcessorSystemCycleTime, "KERNEL32.dll"), stdcall, Int32,
(UInt16, Ptr{SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION}, Ptr{UInt32}),
Group, Buffer, ReturnedLength)
# Group : WORD -> UInt16
# Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> Ptr{SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION}
# ReturnedLength : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetProcessorSystemCycleTime(
uint16_t Group,
void* Buffer,
uint32_t* ReturnedLength);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength)
-- Group : WORD
-- Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
-- ReturnedLength : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetProcessorSystemCycleTime = lib.func('__stdcall', 'GetProcessorSystemCycleTime', 'int32_t', ['uint16_t', 'void *', 'uint32_t *']);
// GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength)
// Group : WORD -> 'uint16_t'
// Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> 'void *'
// ReturnedLength : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetProcessorSystemCycleTime: { parameters: ["u16", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength)
// Group : WORD -> "u16"
// Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> "pointer"
// ReturnedLength : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetProcessorSystemCycleTime(
uint16_t Group,
void* Buffer,
uint32_t* ReturnedLength);
C, "KERNEL32.dll");
// $ffi->GetProcessorSystemCycleTime(Group, Buffer, ReturnedLength);
// Group : WORD
// Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
// ReturnedLength : DWORD* in/out
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean GetProcessorSystemCycleTime(
short Group, // WORD
Pointer Buffer, // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
IntByReference ReturnedLength // DWORD* in/out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun GetProcessorSystemCycleTime = GetProcessorSystemCycleTime(
Group : UInt16, # WORD
Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION*, # SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength : UInt32* # DWORD* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetProcessorSystemCycleTimeNative = Int32 Function(Uint16, Pointer<Void>, Pointer<Uint32>);
typedef GetProcessorSystemCycleTimeDart = int Function(int, Pointer<Void>, Pointer<Uint32>);
final GetProcessorSystemCycleTime = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetProcessorSystemCycleTimeNative, GetProcessorSystemCycleTimeDart>('GetProcessorSystemCycleTime');
// Group : WORD -> Uint16
// Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> Pointer<Void>
// ReturnedLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetProcessorSystemCycleTime(
Group: Word; // WORD
Buffer: Pointer; // SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
ReturnedLength: Pointer // DWORD* in/out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'GetProcessorSystemCycleTime';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetProcessorSystemCycleTime"
c_GetProcessorSystemCycleTime :: Word16 -> Ptr () -> Ptr Word32 -> IO CInt
-- Group : WORD -> Word16
-- Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> Ptr ()
-- ReturnedLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getprocessorsystemcycletime =
foreign "GetProcessorSystemCycleTime"
(uint16_t @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* Group : WORD -> uint16_t *)
(* Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> (ptr void) *)
(* ReturnedLength : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetProcessorSystemCycleTime" get-processor-system-cycle-time :convention :stdcall) :int32
(group :uint16) ; WORD
(buffer :pointer) ; SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out
(returned-length :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetProcessorSystemCycleTime = Win32::API::More->new('KERNEL32',
'BOOL GetProcessorSystemCycleTime(WORD Group, LPVOID Buffer, LPVOID ReturnedLength)');
# my $ret = $GetProcessorSystemCycleTime->Call($Group, $Buffer, $ReturnedLength);
# Group : WORD -> WORD
# Buffer : SYSTEM_PROCESSOR_CYCLE_TIME_INFORMATION* optional, out -> LPVOID
# ReturnedLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。