Determining thread processing time

Discussion in 'Java' started by Joe, Apr 14, 2004.

  1. Joe

    Joe Guest

    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
     
    Joe, Apr 14, 2004
    #1
    1. Advertising

  2. Joe

    Chris Smith Guest

    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
     
    Chris Smith, Apr 14, 2004
    #2
    1. Advertising

  3. Joe

    Liz Guest

    "Chris Smith" <> wrote in message
    news: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
     
    Liz, Apr 15, 2004
    #3
  4. Joe

    John Guest

    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
     
    John, Apr 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Cook
    Replies:
    0
    Views:
    478
    Paul Cook
    Nov 6, 2003
  2. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    540
    Michael Foord
    Sep 17, 2004
  3. =?ISO-8859-2?Q?Krist=F3f_Str=F3bl?=

    Determining thread id on Linux

    =?ISO-8859-2?Q?Krist=F3f_Str=F3bl?=, Jan 19, 2006, in forum: Python
    Replies:
    0
    Views:
    454
    =?ISO-8859-2?Q?Krist=F3f_Str=F3bl?=
    Jan 19, 2006
  4. flamesrock
    Replies:
    8
    Views:
    548
    Hendrik van Rooyen
    Nov 24, 2006
  5. Dmitry Teslenko
    Replies:
    0
    Views:
    660
    Dmitry Teslenko
    Jan 3, 2010
Loading...

Share This Page