The Artima Developer Community
Sponsored Link

Java Answers Forum
CPU Utilization by JNI -- Win98 Probelm

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Adam Wu

Posts: 2
Nickname: depender
Registered: Dec, 2003

CPU Utilization by JNI -- Win98 Probelm Posted: Dec 24, 2003 3:57 AM
Reply to this message Reply
Advertisement
Dear all,
From www.javaworld.com, I read the paper "Profiling CPU usage from within a Java application,Roll your own CPU usage monitor using simple JNI".
Thanks to the source code privided there on the site, I have properly merged the code into my application. That is, I can now get the CPU usage value of the current java program, by a programmatic way, from inside my java program.

But I met a problem:
My application runs ok under WindowsXP and Windows2000, but when I run the same code under Windows98, the
CPU usage value is very strange and wrong. The following is the snapshot of some of the output:
***********************************
CPU utilization: 2147483.647%

CPU utilization: 2147483.647%

CPU utilization: 2147483.647%

CPU utilization: 2147483.647%

***********************************
that is, all the CPU usage value is 2147483.647%
, which is of course wrong.

And, to find the reason, I inserted:
printf("Hi from fileTimeToInt64(), and _time.QuadPart = %ld \n",_time.QuadPart);
in the fileTimeToInt64() function, which produces:
********************************************************************* *
Hi from fileTimeToInt64(), and _time.QuadPart = 7253008
Hi from fileTimeToInt64(), and _time.QuadPart = 0
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
**********************************************************************
that is, after the first time, all the value returned from fileTimeToInt64() are either
1832791420 (by the calling of fileTimeToInt64 (& kernelTime) in getProcessCPUTime() )
or 29607974 (by the calling of fileTimeToInt64 (& userTime) in getProcessCPUTime() ).

To compare, I run the same code under WindowsXP, and got the following output:
**********************************************************************
Hi from fileTimeToInt64(), and _time.QuadPart = 3404896
Hi from fileTimeToInt64(), and _time.QuadPart = 10414976
CPU utilization: 7.677%

Hi from fileTimeToInt64(), and _time.QuadPart = 3404896
Hi from fileTimeToInt64(), and _time.QuadPart = 10515120
CPU utilization: 2.115%

Hi from fileTimeToInt64(), and _time.QuadPart = 3404896
Hi from fileTimeToInt64(), and _time.QuadPart = 10815552
CPU utilization: 5.649%

Hi from fileTimeToInt64(), and _time.QuadPart = 3505040
Hi from fileTimeToInt64(), and _time.QuadPart = 10915696
CPU utilization: 3.992%

Hi from fileTimeToInt64(), and _time.QuadPart = 3505040
Hi from fileTimeToInt64(), and _time.QuadPart = 10915696
CPU utilization: 0.0%
**********************************************************************
This output under WinXP is right, since we can calculate the CPU usage value from it:
take the 5.649% as examlpe:
10815552 + 3404896 = 14220448
10515120 + 3404896 = 13920016

and : 14220448 - 13920016 = 300432 (100ns)
and then: 300432 / 10000000 = 0.0300432 (s)
0.0300432 / 0.5 = 0.0600864
6.00%
it explains : 5.649% perfectly

But, I wonder what is wrong with the same code under Windows98? Why does it prodeuce strange output value such as:
***********************************
CPU utilization: 2147483.647%
***********************************
and
************************** ********************************************
Hi from fileTimeToInt64(), and _time.QuadPart = 7253008
Hi from fileTimeToInt64(), and _time.QuadPart = 0
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
Hi from fileTimeToInt64(), and _time.QuadPart = 1832791420
Hi from fileTimeToInt64(), and _time.QuadPart = 29607974
**********************************************************************
?


and some one pointed to me that:
###
If you read the MSDN documentation for GetProcessTimes will learn that the API is

unsupported in Windows 98. The API is present is Kernel32.DLL but does not do anything.

The return values of GetProcessTimes are garbage.

HTH
###

but:
thanks for informing me that
what should I do now to do the CPU usage work by Java/JNI under Windows 98?
is there any workaround?


Thanks in advance!

Best wishes,

Adam

my email add: depender@yahoo.com





Note1: I set the probe interval to 500ms
Note2: I monitors the currently running java program's CPU usage value

Topic: class not found exceptions and serialization Previous Topic   Next Topic Topic: Question about the JAVA program

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use