Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Determining thread processing time

Reply
Thread Tools

Determining thread processing time

 
 
Joe
Guest
Posts: n/a
 
      04-14-2004
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
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      04-14-2004
Joe wrote:
> 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
 
Reply With Quote
 
 
 
 
Liz
Guest
Posts: n/a
 
      04-15-2004

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)4.net...
> Joe wrote:
> > 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?


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

>
> 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



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      04-15-2004
Joe wrote:

> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[gtk+thread] Why worker thread never wakes from time.sleep()? Dmitry Teslenko Python 0 01-03-2010 08:07 PM
Is time.time() < time.time() always true? flamesrock Python 8 11-24-2006 06:51 AM
Determining thread id on Linux =?ISO-8859-2?Q?Krist=F3f_Str=F3bl?= Python 0 01-19-2006 06:03 PM
Question: processing HTML, re-write default processing action of many tags Hubert Hung-Hsien Chang Python 2 09-17-2004 03:10 PM
Determining control behaviour at design-time/run-time Paul Cook ASP .Net 0 11-06-2003 09:17 AM



Advertisments