alexandre_paterson@yahoo.fr wrote:
On Jul 15, 8:36 pm, Eric Sosman <Eric.Sos...@sun.com> wrote:
Perhaps it's time to step back and ask what the result will be used
for.
I don't thinks so :)
That is usually a very relevant question.
"CPU usage" is not a portable notion to begin with, so the need
to query it in a portable program is already suspect.
It depends on how "portable" the program needs to be. If supporting
Windows, OS X, Linux and other Un*x flavors is enough, then it's not
because there are two or three OS specific implementations that the
program is not portable.
I'm working on a codebase that is deployed on a lot of various OSes
and it's 0.002 % of "non-portable" OS-specific script lines (just
did the count with 'wc -l'). The rest is 99.998 % Java code. Is
my program non portable?
Obviously not.
... and ask what the result will be used for.
What are the results of 'top' used for?
It is used on Linux to check load.
It does not exist on Windows, OpenVMS, z/OS etc..
Here's a test I often use to decide whether I'm asking a useful
question of the environment: If I made the query and got X as my
answer,
what would my program do differently than it would with answer Y, and
why? In the O.P.'s case: If he's able to measure "CPU usage" and finds
that it's forty-two percent, what will he do differently than if he'd
found it to be seven percent or ninety-eight point six percent?
Launch new EC2 instances when the load is too high?
Lower the "load" of your own Java program to let the OS be
more responsive?
The OP has a very good question and it's an indisputable fact
that there are many legitimate cases where this information is
definitely useful.
Could be.
But until we do get more information, then we can not
say whether the current direction is optimal or a change
of direction would be better.
CPU of a method.