Re: Help! Problem on CPU usage and performance tuning.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jochen Kalmbach (nospam-Jochen.Kalmbach_at_holzma.de)
Date: 10/20/04


Date: Wed, 20 Oct 2004 04:26:47 -0700

Hi youhua.wang,

> But i think you make a mistake.
> Actually i use value return by GetThreadTimes for profile. while use
> GetTickCount() function just as comparison with GetThreadTimes().

Internally the Kernel- and UserTime is incremented by the timer-
resolution of the hal. This resolution is stored in "nt!
KeMaximumIncrement"

On my system this value is 25178 (100ns) => 2517,8 uS => 2,5 ms

So you see that the resolution is better than with "GetTickCount" but it
is worsen than using "QueryPerformanceCounter".

> Isn't QueryPerformanceCounter() return CPU time of all thread , inlude
> thread context switch?

It has the same effect as if you would use "GetTickCount" but it has a
far better resolution (on single CPU system it uses the rtdsc assembler
code, which has the same resolution as the CPU-speed.

> It can not give out the exactly CPU time of per thread. But longer
> test time is a way.

As you see, GetThreadTimes is also very diffuse for short times... and if
your thread often does not use the full quantum, then it might also be
diffus.

So it is always better to do a longer testrun.

-- 
Greetings
  Jochen
   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/


Relevant Pages

  • Re: Help! Problem on CPU usage and performance tuning.
    ... >> Actually i use value return by GetThreadTimes for profile. ... >> GetTickCountfunction just as comparison with GetThreadTimes(). ... This resolution is stored in "nt! ... So the resultion is simple the same as for GetTickCount! ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Basic Graphic Questions
    ... I don't use GetTickCount on the grounds that it has a very limited resolution. ... If I want a resolution of about one millisecond I use timeGetTime but for most general purpose high resolution timings I use QueryPerformanceCounter in association with QueryPerformanceFrequency, which gives you a very high resolution of about one microsecond on most systems, although on a multitasking OS such as Windows all timings will vary somewhat from run to run and so I generally do a few runs and take the average, usually ignoring the time of the very first call to a function after the VB program has just started. ... Also if I'm timing GDI graphics functions on XP and earlier versions, which generally perform their task in hardware using the GDI hardware acceleration of your video card, then I take care to ensure that I am timing the actual time taken by the video card hardware to complete the drawing task, rather than just the extremely small and insignificant amount of time the main processor takes to "make the drawing request" to the hardware. ...
    (microsoft.public.vb.general.discussion)
  • Re: GetThreadTimes issues
    ... Could be it because of the resolution? ... If your thread is executing faster than 1 second, ... you would see zero everytime. ... process I retrieve all the threads and I call GetThreadTimes: ...
    (microsoft.public.windowsce.embedded)
  • Re: Accurate time measurement
    ... "Multiple statements execute before either ... GetTickCount or timeGetTime record a change" and adding, ... increase the resolution of both GetTickCount and timeGetTime using ...
    (microsoft.public.vb.general.discussion)
  • Re: Timer accuracy.
    ... >> resolution timer and is more accurate than GetTickCount ... >> Private Declare Function timeGetTime _ ... >You have to be a bit careful about the timeGetTime function Jerry. ...
    (microsoft.public.vb.general.discussion)