KeQueryTickCount()..how to get time elapsed in milliseconds

Discussion in 'Windows Vista Drivers' started by Arsalan Ahmad, Dec 27, 2005.

  1. Hi,

    In my driver, I am trying to get elapsed time between two events in
    millisecond. Please tell me how can I do this for code below:

    LARGE_INTEGER start_time;
    KeQueryTickCount(&start_time);

    // Do some processing.......

    LARGE_INTEGER end_time;
    KeQueryTickCount(&end_time);

    ULONG time_in_msec = ???????? (how can i use start_time and end_time here in
    order to get time in msec?)

    I am also getting compiler errors in converting LARGE_INTEGER to ULONG. How
    should i do this also?

    Thanks,

    Arsalan
     
    Arsalan Ahmad, Dec 27, 2005
    #1
    1. Advertisements

  2. if you read the DDK page on KeQueryTickCount, there are links to 3 different
    functions at the bottom of the page that are also related to tick count.
    one of them is the function you need to call to convert from ticks to 100 ns
    units. It even tells you how to do it.

    as for the LONG issue, you have to use a LONGLONG (64 bit value). you can
    get via

    LONGLONG elapsedticks = end_time.QuadPart - start_time.QuadPart;

    now all you have todo is convert elapsedticks from a tick count to a unit of
    time.

    d
     
    Doron Holan [MS], Dec 27, 2005
    #2
    1. Advertisements

  3. Hi,

    Now i am using following code:

    LARGE_INTEGER start_time;
    KeQueryTickCount(&start_time);
    ULONG start_time_in_msec = (ULONG)(start_time.QuadPart *
    KeQueryTimeIncrement() / 10000);

    // Do some processing.......

    LARGE_INTEGER end_time;
    KeQueryTickCount(&end_time);
    ULONG end_time_in_msec = (ULONG)(end_time.QuadPart * KeQueryTimeIncrement()
    / 10000);

    ULONG elapsed_time_in_msec = end_time_in_msec - start_time_in_msec;

    Will this works? because if I try to get the elapsed time in this way it
    seems to be running a little bit faster if I compare with my getting elapsed
    time using GetTickCount().

    Thanks,

    Arsalan
     
    Arsalan Ahmad, Dec 27, 2005
    #3
  4. this works, but you should not cast from a 64 to 32 bit value, you will lose
    time if the machine is running long enough. GetTickCount is based on the
    same KeQueryTickCount call

    d

    --
    Please do not send e-mail directly to this alias. this alias is for
    newsgroup purposes only.
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Doron Holan [MS], Dec 28, 2005
    #4
  5. I'd rather subtract 64-bit end from begin, and only then convert it to
    miliseconds.
     
    Alexander Grigoriev, Dec 28, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.