Interrupt Time

割り込み時間とは、システムが最後に起動されてから経過した時間を 100 ナノ秒間隔で表したものです。 割り込み時間のカウントは、システムの起動時にゼロから始まり、クロック割り込みごとにクロック ティックの長さだけ増加します。 クロック ティックの正確な長さは、基盤となるハードウェアによって異なり、システムによっても異なる場合があります。

システム時間とは異なり、割り込み時間のカウントはユーザーや Windows タイム サービスによる調整の対象ではないため、短い期間を測定する場合に適しています。 割り込み時間のカウントよりも高い精度を必要とするアプリケーションでは、高解像度タイマーを使用する必要があります。 高解像度タイマーの周波数を取得するには QueryPerformanceFrequency 関数を使用し、カウンターの値を取得するには QueryPerformanceCounter 関数を使用します。

割り込み時間のカウントを取得するには、関数 QueryInterruptTimeQueryInterruptTimePreciseQueryUnbiasedInterruptTimeQueryUnbiasedInterruptTimePrecise を使用できます。 偏りのない割り込み時間とは、システムが動作状態にある時間のみがカウントされることを意味します。したがって、割り込み時間のカウントには、スリープ状態または休止状態でシステムが消費する時間による "偏り" は含まれません。

Windows Server 2008、Windows Vista、Windows Server 2003、Windows XP/2000: QueryUnbiasedInterruptTime 関数は、Windows 7 および Windows Server 2008 R2 以降で使用できます。

timeBeginPeriod 関数と timeEndPeriod 関数によって設定されたタイマー解像度は、QueryInterruptTime 関数と QueryUnbiasedInterruptTime 関数の解像度に影響します。 ただし、タイマー解像度の引き上げは、プロセッサが省電力状態に入るのを妨げることでシステム全体のパフォーマンスを低下させ、消費電力の増加につながる可能性があるため、お勧めしません。 代わりに、アプリケーションで高解像度タイマーを使用する必要があります。

Note

関数 QueryInterruptTimeQueryInterruptTimePreciseQueryUnbiasedInterruptTime、および QueryUnbiasedInterruptTimePrecise では、Windows のデバッグ ("チェック済み") ビルドで生成される結果が異なります。これは、割り込み時間のカウントとティック数が約 49 日進んでいるためです。 これは、システムが長時間実行されるまで発生しない可能性のあるバグを特定するために役立ちます。

 

次の例は、関数 QueryInterruptTimeQueryInterruptTimePreciseQueryUnbiasedInterruptTime、および 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 バイトの値です。 これらのパフォーマンス カウンターの詳細については、「 パフォーマンス カウンター」を参照してください。

QueryInterruptTime

QueryInterruptTimePrecise

QueryUnbiasedInterruptTime

QueryUnbiasedInterruptTimePrecise

timeBeginPeriod

timeEndPeriod