Compartir a través de


Tiempo de interrupción

El tiempo de interrupción es la cantidad de tiempo desde que se inició por última vez el sistema, en intervalos de 100 nanosegundos. El recuento de tiempo de interrupción comienza en cero cuando se inicia el sistema y se incrementa en cada interrupción del reloj por la longitud de un tic del reloj. La longitud exacta de un tic del reloj depende del hardware subyacente y puede variar entre sistemas.

A diferencia del tiempo del sistema, el recuento de tiempo de interrupción no está sujeto a ajustes por parte de los usuarios o el servicio de hora de Windows, lo que lo convierte en una mejor opción para medir duraciones cortas. Las aplicaciones que requieren mayor precisión que el recuento de tiempo de interrupción deben usar un temporizador de alta resolución. Use la función QueryPerformanceFrequency para recuperar la frecuencia del temporizador de alta resolución y la función QueryPerformanceCounter para recuperar el valor del contador.

Las funciones QueryInterruptTime, QueryInterruptTimePrecise, QueryUnbiasedInterruptTime y QueryUnbiasedInterruptTimePrecise se pueden usar para recuperar el recuento de tiempo de interrupción. El tiempo de interrupción no sesgado significa que solo se cuenta el tiempo que el sistema está en estado de trabajo; por lo tanto, el recuento de tiempo de interrupción no es "sesgado" por el tiempo que el sistema pasa en suspensión o hibernación.

Windows Server 2008, Windows Vista, Windows Server 2003 y Windows XP/2000: La función QueryUnbiasedInterruptTime está disponible a partir de Windows 7 y Windows Server 2008 R2.

La resolución del temporizador establecida por las funciones timeBeginPeriod y timeEndPeriod afecta a la resolución de las funciones QueryInterruptTime y QueryUnbiasedInterruptTime . Sin embargo, no se recomienda aumentar la resolución del temporizador porque puede reducir el rendimiento general del sistema y aumentar el consumo de energía evitando que el procesador entre en estados de ahorro de energía. En su lugar, las aplicaciones deben usar un temporizador de alta resolución.

Nota

Las funciones QueryInterruptTime, QueryInterruptTimePrecise, QueryUnbiasedInterruptTime y QueryUnbiasedInterruptTimePrecise generan resultados diferentes en las compilaciones de depuración ("checked") de Windows, ya que el recuento de tiempo de interrupción y el recuento de tics están avanzados aproximadamente 49 días. Esto ayuda a identificar errores que podrían no producirse hasta que el sistema se haya estado ejecutando durante mucho tiempo. La compilación activada está disponible para los suscriptores de MSDN a través del sitio web de Microsoft Developer Network (MSDN).

 

En el ejemplo siguiente se muestra cómo recuperar el recuento de tiempo de interrupción mediante una llamada a las funciones QueryInterruptTime, QueryInterruptTimePrecise, QueryUnbiasedInterruptTime y QueryUnbiasedInterruptTimePrecise . Vínculo a la biblioteca OneCore.lib al compilar una aplicación de consola que llame a estas funciones.

#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);
}

Para recuperar el tiempo transcurrido que tenga en cuenta la suspensión o hibernación, use la función GetTickCount o GetTickCount64 , o use el contador de rendimiento Tiempo de espera del sistema. Este contador de rendimiento se puede recuperar de los datos de rendimiento de la clave del Registro HKEY_PERFORMANCE_DATA. El valor devuelto es un valor de 8 bytes. Para más información, consulte Performance Counters.

QueryInterruptTime

QueryInterruptTimePrecise

QueryUnbiasedInterruptTime

QueryUnbiasedInterruptTimePrecise

timeBeginPeriod

timeEndPeriod