割り込み時間
割り込み時間 は、システムが最後に開始されてからの時間 (100 ナノ秒間隔) です。 割り込み時間カウントは、システムが起動すると 0 から始まり、クロック割り込みごとにクロック ティックの長さだけインクリメントされます。 クロック ティックの正確な長さは、基になるハードウェアによって異なり、システムによって異なる場合があります。
システム時間とは異なり、割り込み時間の数はユーザーまたは Windows タイム サービスによる調整の影響を受けず、短い期間を測定するためのより良い選択肢となります。 割り込み時間数よりも高い精度を必要とするアプリケーションでは、 高解像度タイマーを使用する必要があります。 QueryPerformanceFrequency 関数を使用して、高解像度タイマーの頻度を取得し、QueryPerformanceCounter 関数を使用してカウンターの値を取得します。
QueryInterruptTime、QueryInterruptTimePrecise、QueryUnbiasedInterruptTime、QueryUnbiasedInterruptTimePrecise 関数を使用して、割り込み時間数を取得できます。 公平な割り込み時間とは、システムが動作状態にある時間のみがカウントされることを意味します。したがって、割り込み時間数は、システムがスリープまたは休止状態に費やす時間によって "偏り" されません。
Windows Server 2008、Windows Vista、Windows Server 2003、Windows XP/2000:QueryUnbiasedInterruptTime 関数は、Windows 7 および Windows Server 2008 R2 以降で使用できます。
timeBeginPeriod 関数と timeEndPeriod 関数によって設定されたタイマー解決は、QueryInterruptTime 関数と QueryUnbiasedInterruptTime 関数の解決に影響します。 ただし、プロセッサが省電力状態に入らないようにすることで、システム全体のパフォーマンスを低下させ、消費電力を増やすことができるため、タイマーの解像度を上げることはお勧めしません。 代わりに、アプリケーションでは高解像度タイマーを使用する必要があります。
注意
QueryInterruptTime、QueryInterruptTimePrecise、QueryUnbiasedInterruptTime、QueryUnbiasedInterruptTimePrecise 関数は、Windows のデバッグ ("checked") ビルドで異なる結果を生成します。これは、割り込み時間数とティック数が約 49 日進んでいるためです。 これは、システムが長時間実行されるまで発生しない可能性があるバグを特定するのに役立ちます。 チェックされたビルドは、 Microsoft Developer Network (MSDN) Web サイトを介して MSDN サブスクライバーが使用できます。
次の例では、 QueryInterruptTime、 QueryInterruptTimePrecise、 QueryUnbiasedInterruptTime、 QueryUnbiasedInterruptTimePrecise 関数を呼び出して割り込み時間数を取得する方法を示します。 これらの関数を呼び出すコンソール アプリケーションをビルドするときに、OneCore.lib ライブラリにリンクします。
#include "stdafx.h"
#include <windows.h>
#include <realtimeapiset.h>
void InterruptTimeTest()
{
ULONGLONG InterruptTime;
ULONGLONG PreciseInterruptTime;
ULONGLONG UnbiasedInterruptTime;
ULONGLONG PreciseUnbiasedInterruptTime;
// The interrupt time that QueryInterruptTime reports is based on the
// latest tick of the system clock timer. The system clock timer is
// the hardware timer that periodically generates interrupts for the
// system clock. The uniform period between system clock timer
// interrupts is referred to as a system clock tick, and is typically
// in the range of 0.5 milliseconds to 15.625 milliseconds, depending
// on the hardware platform. The interrupt time value retrieved by
// QueryInterruptTime is accurate within a system clock tick.
QueryInterruptTime(&InterruptTime);
printf("Interrupt time: %.7f seconds\n",
(double)InterruptTime/(double)10000000);
// Precise interrupt time is more precise than the interrupt time that
// QueryInterruptTime reports because the functions that report
// precise interrupt time read the timer hardware directly.
QueryInterruptTimePrecise(&PreciseInterruptTime);
printf("Precise interrupt time: %.7f seconds\n",
(double)PreciseInterruptTime/(double)10000000);
// Unbiased interrupt time means that only time that the system is in
// the working state is counted. Therefore, the interrupt-time count
// is not biased by time the system spends in sleep or hibernation.
QueryUnbiasedInterruptTime(&UnbiasedInterruptTime);
printf("Unbiased interrupt time: %.7f seconds\n",
(double)UnbiasedInterruptTime/(double)10000000);
// QueryUnbiasedInterruptTimePrecise gets an interrupt-time count
// that is both unbiased and precise, as defined in the comments
// included earlier in this example.
QueryUnbiasedInterruptTimePrecise(&PreciseUnbiasedInterruptTime);
printf("Precise unbiased interrupt time: %.7f seconds\n",
(double)PreciseUnbiasedInterruptTime/(double)10000000);
}
int main(void)
{
void InterruptTimeTime();
InterruptTimeTest();
return(0);
}
スリープまたは休止状態を考慮した経過時間を取得するには、 GetTickCount または GetTickCount64 関数を使用するか、System Up Time パフォーマンス カウンターを使用します。 このパフォーマンス カウンターは、レジストリ キー HKEY_PERFORMANCE_DATAのパフォーマンス データから取得できます。 返される値は 8 バイトの値です。 これらのパフォーマンス カウンターの詳細については、「 パフォーマンス カウンター」を参照してください。
関連トピック
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示