Determining thread processing time

J

Joe

Hi,

I am wondering if there is any way of determining how much processing
time a thread uses. I know of the simple method of taking the system
time before the thread starts, starting the thread and when it
completes execution, getting the system time at that point but that is
not reliable for my application.
The threads I am using run as low priority so as not to interfere with
the system as they can run for a long time (hrs to days), so for
example if it has been running for 5 hours it might have only used
about 2hrs of the processor according to Task Manager in Windows 2000.
Is there any way of determining this time programmatically in Java, or
a more accurate way of how much time the thread has spent executing in
the processor?
Also, related to this, I would also like to determine the processor
speed in Java if possible, so combining the time it takes a thread to
execute on the particular processor, I can determine a fair benchmark
between different computers?

Any help much appreciated,
Joe
 
C

Chris Smith

Joe said:
The threads I am using run as low priority so as not to interfere with
the system as they can run for a long time (hrs to days), so for
example if it has been running for 5 hours it might have only used
about 2hrs of the processor according to Task Manager in Windows 2000.
Is there any way of determining this time programmatically in Java, or
a more accurate way of how much time the thread has spent executing in
the processor?

No, you can't do that in pure Java.
Also, related to this, I would also like to determine the processor
speed in Java if possible, so combining the time it takes a thread to
execute on the particular processor, I can determine a fair benchmark
between different computers?

No, you can't do that in pure Java either.

Besides, that's a strange definition of "fair benchmark" when you're
ignoring the effects of cache pollution from other simultaneous tasks.
If your goal is benchmarking, I'd strongly recommend arranging an
isolated environment with simulated load where you can prevent the
remainder of the application from running.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
L

Liz

Chris Smith said:
No, you can't do that in pure Java.

Benchmarking is tricky. Univ of Tenn has done these kind of measurements
properly. Maybe they have data on your machine(s).
 
J

John

Joe said:
Hi,

I am wondering if there is any way of determining how much processing
time a thread uses. I know of the simple method of taking the system
time before the thread starts, starting the thread and when it
completes execution, getting the system time at that point but that is
not reliable for my application.
The threads I am using run as low priority so as not to interfere with
the system as they can run for a long time (hrs to days), so for
example if it has been running for 5 hours it might have only used
about 2hrs of the processor according to Task Manager in Windows 2000.
Is there any way of determining this time programmatically in Java, or
a more accurate way of how much time the thread has spent executing in
the processor?
Also, related to this, I would also like to determine the processor
speed in Java if possible, so combining the time it takes a thread to
execute on the particular processor, I can determine a fair benchmark
between different computers?

Any help much appreciated,
Joe

I had to do this for part of my third year project. The problem is that
you have no control over the processes being executed by the operating
system so even if you have really tight control/monitoring of which
Threads are executing in the VM you can't be sure of what the CPU is
actually achieving (since the VM shares CPU resources like any ther
program).

I was interested in relative rather than absolute statistics so I
decided to just monitor the time that the thread was running (this is
distinct from contending). By doing this I could measure the proportion
of VM time (as opposed to CPU time) that each thread was using.

So how do you achieve this? You can either sample to find the currently
executing thread or create a relatively complex system of wait() and
notify() calls that update an accumulating VM time variable as each
thread takes control. You essentially perform the thread scheduling that
the VM normally carries out yourself.

If you want to know more I have links to the project at www.jcourt.com
where you can download a report (the stuff you are interested in is in
the later chapters) and also all the project source code.

Hope this helps,

John
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top