Topic
4 replies Latest Post - ‏2007-02-27T06:06:13Z by SystemAdmin
SystemAdmin
SystemAdmin
235 Posts
ACCEPTED ANSWER

Pinned topic Resource allocation in JVM

‏2006-11-06T19:37:35Z |
A method during its execution can use different resources. During its execution at a particular resource, I need to find the service time, which is the elapsed time when it starts execution at that particular resource and the time when it leaves the resource. This service time will be input to queuing model and simulation model. For. eg: in a transaction methods A(), B(), C(), D() are supposed to execute in sequence. If all the methods use only one resource then the service time i.e the duration when method A() starts executing and the time when method D() leaves the resource is sufficient, but if during the execution any of the method starts using different resource then I need to stop capturing the service time at that resource and find the service time of execution at the next resource.

When a java application is executing in JVM, how do I trace which resource (CPU, I/O etc ) it is using currently or how do I trace the event when a particular resource is allocated for a method and when it is left and I also need to know which resource is being used during that time. I have vague idea this can be traced by java.laung.runtime or java.lang.instrument api but I am not able to figue it out, please somebody reply.

Rishi
Updated on 2007-02-27T06:06:13Z at 2007-02-27T06:06:13Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    235 Posts
    ACCEPTED ANSWER

    Re: Resource allocation in JVM

    ‏2006-11-12T15:36:37Z  in response to SystemAdmin
    can anyone help if I want to find how much cpu time a method is actually using.
    • SystemAdmin
      SystemAdmin
      235 Posts
      ACCEPTED ANSWER

      Re: Resource allocation in JVM

      ‏2006-11-17T08:05:47Z  in response to SystemAdmin
      Some of my developerWorks articles showed ways of using bytecode modification and/or aspects to do this type of thing. See http://www.ibm.com/developerworks/java/library/j-cwt03085/ for an approach using AspectWerkz, or http://www.ibm.com/developerworks/java/library/j-dyn0203.html and http://www.ibm.com/developerworks/java/library/j-dyn0414/ for approaches using bytecode modification. These just used the System.currentTimeMillis() or System.nanoTime() methods, which measure elapsed time. If you instead want CPU time (which may be different due to task switching and such), AFAIK you'll have to use hooks to native code to get the information.

      The article on "Annotations with ASM" (http://www.ibm.com/developerworks/java/library/j-cwt06075/) gives an example of using the Instrumentation API to intercept class loading and modify the bytecode as classes are loaded.
      • SystemAdmin
        SystemAdmin
        235 Posts
        ACCEPTED ANSWER

        Re: Resource allocation in JVM

        ‏2007-02-25T20:11:45Z  in response to SystemAdmin
        Thankyou for the reply ... sorry for taking so long to acknowledge the mail.
        Well i am interested in service time rather than elapsed time. How can I use hooks to native code to get the information.

        Thanks,
        Rishi
        • SystemAdmin
          SystemAdmin
          235 Posts
          ACCEPTED ANSWER

          Re: Resource allocation in JVM

          ‏2007-02-27T06:06:13Z  in response to SystemAdmin
          I'll confess that this is getting out of my depth, in terms of the OS measurement of CPU time for a process. I know that systems used to use strictly tick-based time measurement, with a timer interrupt at regular intervals. In this approach, each time the timer interrupt fires the tick clock is incremented and the time since the last tick is allocated to whichever task was running before the interrupt fired. I believe systems now have more accurate ways of measuring time based on the actual CPU clock, but I don't know the details.

          Assuming you can find a way to access a system's CPU time measurement for your process, you'll probably want to use JNI (Java Native Interface) to call native code from your Java code. The native code can use the appropriate system call to access the time value, then return the result to your Java code.

          The downside of this is that the actual JNI call and system call take up a non-negligible amount of CPU time. Unless you're timing a method that both takes a long time to execute and is running on a system where it's likely to be interrupted during execution you're probably better off just using the tick-based time value from System.nanoTime() method. This also involves some overhead, but the JVM implementation is likely to involve less overhead than anything you can do using JNI and a native call.