Topic
19 replies Latest Post - ‏2012-10-16T14:41:36Z by WiseMind
WiseMind
WiseMind
29 Posts
ACCEPTED ANSWER

Pinned topic enabling method trace health Center

‏2012-10-16T07:51:23Z |
Hi,

I want to enabled all method trace of my application. Like I have a HelloWorld Class which contains 3 methods: method1,method2 and method3. Now I want to see which method is taking so much time.

I have googled it and got to know we can only trace methods by giving method name. Is there any way to enabled method trace of all application's method. How to do that ?? As we don't know before running application which method is gonna take so much time.

I found the following command
java -Xhealthcenter -Xtrace:maximal=mt,methods={"sun/reflect/GeneratedConstructorAccessor1.newInstance"} HelloWorld

Help is required.

Thanks
Updated on 2012-10-16T14:41:36Z at 2012-10-16T14:41:36Z by WiseMind
  • SystemAdmin
    SystemAdmin
    188 Posts
    ACCEPTED ANSWER

    Re: enabling method trace health Center

    ‏2012-10-16T08:05:03Z  in response to WiseMind
    Hi,

    You can generate the strings you need to switch on method trace from within Health Center. Instructions on how to do this are in the help under

    Tool: IBM Monitoring and Diagnostic Tools for Java - Health Center > Monitoring a running Java application > Tracing Methods

    Then, once you have followed those steps and restarted your application with the extra command line parameters, read this section on understanding the data

    Tool: IBM Monitoring and Diagnostic Tools for Java - Health Center > Viewing the data collected > Method trace perspective

    You should find most of the answers to any questions about the data, how to understand it and how to use Health Center are in the help.

    regards

    Toby
    • WiseMind
      WiseMind
      29 Posts
      ACCEPTED ANSWER

      Re: enabling method trace health Center

      ‏2012-10-16T10:07:01Z  in response to SystemAdmin
      Thanks Toby.

      When I give the following commands it shows me method trace. But no Classes,Garbage Collection and Profile has been collected this time.. Can I see all the details together ?

      java -Xhealthcenter -Xtrace:maximal=mt,methods=*.* HelloWorld

      Anything I am missing ?

      One more question, In Method Profile View I can see method details like below

      Self (30%) Tree (66%) HelloWorld.method1 ( I can uderstand this )

      But in Method Trace summary, I am unable to see time consumed by this method. I am also to unable find Class HelloWorld and any of their method... Is there missing anything ??

      Thanks
      • SystemAdmin
        SystemAdmin
        188 Posts
        ACCEPTED ANSWER

        Re: enabling method trace health Center

        ‏2012-10-16T10:14:41Z  in response to WiseMind
        Hi,

        Turning on method trace for methods (methods=*.*) is not a good idea as this generates so much data it will cause your application to run very slowly and also prevent the other data that Health Center uses to be lost. It is much better to just select 1 or 2 methods and and get the data on those. That is probably why you are not seeing any other data in Health Center.

        regards

        Toby
        • WiseMind
          WiseMind
          29 Posts
          ACCEPTED ANSWER

          Re: enabling method trace health Center

          ‏2012-10-16T10:27:41Z  in response to SystemAdmin
          Thanks Toby.

          Yeah I can understand to enabling trace of all methods not good for application as it slows down. As We have a bigger application so diagnosing the issue by tracing 1 by 1 method is taking too much time and some how not possible. Do you think its a better option ?? What would be the best way to achieve the needful ?
          Thanks
          • SystemAdmin
            SystemAdmin
            188 Posts
            ACCEPTED ANSWER

            Re: enabling method trace health Center

            ‏2012-10-16T10:39:49Z  in response to WiseMind
            Hi,

            The profiling view in Health Center should be sufficient to tell you which methods are being used the most. From this, you can then look at those methods back in the code base to determine if you can optimize them.

            Method Trace should only be used if you need exact timings but for most performance issues, and understanding where the application is spending its time, the profiling view on its own should be ok.

            What sort of performance problems are you trying to solve ? Is your application running slowly ? leaking memory ?

            regards

            Toby
            • SystemAdmin
              SystemAdmin
              188 Posts
              ACCEPTED ANSWER

              Re: enabling method trace health Center

              ‏2012-10-16T10:41:59Z  in response to SystemAdmin
              Hi,

              In my last post I said "which methods are being used the most". By this, I mean't which methods are taking up the most cpu time so this will tell you where the application is doing all its work.

              The help section on method profiling explains all the fields and how to use the data.

              regards

              Toby
              • WiseMind
                WiseMind
                29 Posts
                ACCEPTED ANSWER

                Re: enabling method trace health Center

                ‏2012-10-16T11:25:24Z  in response to SystemAdmin
                As we have discussed earlier for particular class method, we need to give particular method name

                > java -XhealthCenter -Xtrace:maximal=mt,methods={"HelloWorld.main"} HelloWorld

                Method Trace Summary
                HelloWorld.main([Ljava.lang.String;) 0(Count) 0.0 ms (Total Time) 0.0 ms (Max time) 0 ms (Mean time) HelloWorld.main([Ljava.lang.String;)
                While there is issue in this method as created by myself. Its giving outOfMemory exception. But here in method trace its showing Total time spend by this method is just 0.0 ms.

                How it is possible ?? strange
            • WiseMind
              WiseMind
              29 Posts
              ACCEPTED ANSWER

              Re: enabling method trace health Center

              ‏2012-10-16T10:50:59Z  in response to SystemAdmin
              Thanks Toby.

              Yes our application is running slowly. So we need to see which methods are taking too much time. We have an application with lots of classes. So at first look we can not say this particular class method is taking too much time. We have to run the application and then want to see which classes are botlenecks and which methods are having issue and taking too much time.
              Thanks for your advice and help so far.
              • SystemAdmin
                SystemAdmin
                188 Posts
                ACCEPTED ANSWER

                Re: enabling method trace health Center

                ‏2012-10-16T11:34:07Z  in response to WiseMind
                Hi,

                So the profiling view will be fine for this initially. If you monitor your application without method trace switched on, the profiling view will give you the data you need.

                The profiling table will sort itself initially by the number of samples column. This tells you which methods have been doing the most work and therefore have been taking the most cpu time. The methods at the top of the table are the one that are running the most. This is not to be confused with a count of how many times they have run. It could be that you have a method that only runs a few times but does so much work it appears at the top of the list.

                What I would do would be to run your application with Health Center attached and leave it monitoring for a while whilst you observe which methods appear at the top. You may also see difference methods appear at the top if your application starts to do different things (i.e. you put load through it).

                Then, once you have a good idea of which methods are using the most cpu time. Go back to the source code and look those methods in detail to see if you can spot any logic that could be taking excessive time (bad loops for example).

                Another reason for an application running slowly is that it could be doing excessive garbage collection. Does the Garbage Collection view in Health Center have any red crosses next to the recommendations panel in the bottom left hand corner ?

                regards

                Toby
                • WiseMind
                  WiseMind
                  29 Posts
                  ACCEPTED ANSWER

                  Re: enabling method trace health Center

                  ‏2012-10-16T12:27:37Z  in response to SystemAdmin
                  Hi Toby,

                  Without switching on method trace. I have run the application with -Xhealthcenter. Now what I can see in profiling at the top is below.

                  4(Samples) 57.1 (Self) 71.4 (Tree) com.ibm.oti.vm.BootstrapClassLoader.loadClass(java.lang.String)
                  I dont understand which method is it providing information. While in testing application I created outofmemory issue by myself in HelloWorld class method test_run() and test_execute().

                  While I can not see any detail about these methods.. Don't you think this tool tells us which method is taking too much time with the exact method name.

                  What should we do in this situation.

                  Thanks Toby
                  • SystemAdmin
                    SystemAdmin
                    188 Posts
                    ACCEPTED ANSWER

                    Re: enabling method trace health Center

                    ‏2012-10-16T12:45:29Z  in response to WiseMind
                    Hi,

                    So what this tells us is the com.ibm.oti.vm.BootstrapClassLoader.loadClass method is that one that is doing the most work. The way the sampling profiler works is to give a method a count if it is actively executing java code when the sampler runs. So, you may have a method that is called lots and lots of times but if it only does one thing that happens very quickly, that method will not appear at the top of the list. If you have a method that is doing lots of things, you will see that towards the top of the list. The profiling view shows you which methods are using the most cpu time, not which methods are being called the most.

                    Also, I can see from the example you have given that the samples count is only 4. This tells me that either you have not run the application for very long or your application is not actually doing very much that requires cpu time.

                    Your methods need to be doing something to stress the cpu (like doing lots of loops) to get good data in this view. Small test programs rarely stress the cpu which is why you are not seeing any data.

                    For example, if you run this class with Health Center, you will see the Toby.bigMethod() appears in the list because that spends a long time running the loop code
                    ##############################
                    class Toby{

                    static public void main(String[] args) {
                    new Toby();
                    }

                    Toby(){
                    try {
                    System.gc();
                    bigMethod();
                    System.out.println("press enter key to exit");
                    System.in.read();
                    } catch (Exception e) {
                    }
                    System.exit(-1);
                    }

                    private void bigMethod() {
                    for (int i=1; i < 1000000000; i++) {
                    System.out.println("looping " + i);
                    }
                    }
                    }
                    #########################
                    regards

                    Toby
                    • WiseMind
                      WiseMind
                      29 Posts
                      ACCEPTED ANSWER

                      Re: enabling method trace health Center

                      ‏2012-10-16T13:17:42Z  in response to SystemAdmin
                      Hi Toby,

                      I have run your program. Now its giving the following information in profile view

                      0 (Sample) 0.0 (Self) 25.0 (Tree) Toby.bigMethod()

                      while again this class is taking much CPU usage

                      5 41.7 58.3 com.ibm.oti.vm.BootstrapClassLoader.loadClass(java.lang.String)
                      0 0.0 57.1 com.ibm.java.diagnostics.healthcenter.agent.mbean.HCLaunchMBean$JmxStarterThread.run()

                      That means Toby.bigMethod() is taking less time and CPU than com.ibm.oti.vm.BootstrapClassLoader.loadClass ? I dont knw where internally this class is taking too much time.

                      Toby : I am more interested to find out which method is taking most time and gives me exact time detail. So I would be able to diagnose/tune the class method.What should we do to achieve that information ?? I think Method Trace Summary may able to achieve my target. but its showing 0 0 0 0 time spend. May be there is some alternative way to get the information.
                      Thanks Toby
                      • SystemAdmin
                        SystemAdmin
                        188 Posts
                        ACCEPTED ANSWER

                        Re: enabling method trace health Center

                        ‏2012-10-16T13:39:35Z  in response to WiseMind
                        how long did you run the test for ?
                        • WiseMind
                          WiseMind
                          29 Posts
                          ACCEPTED ANSWER

                          Re: enabling method trace health Center

                          ‏2012-10-16T13:45:08Z  in response to SystemAdmin
                          Almost 4 to 5 mins
                        • WiseMind
                          WiseMind
                          29 Posts
                          ACCEPTED ANSWER

                          Re: enabling method trace health Center

                          ‏2012-10-16T13:57:34Z  in response to SystemAdmin
                          Dear Toby,

                          I am interested more towards just getting method details. Kindly tell me what should I do that it just list down the methods, theirs elapsed time, Max time details of each method So i would be able to diagnose and tune application accordingly.

                          Thanks alot
                        • SystemAdmin
                          SystemAdmin
                          188 Posts
                          ACCEPTED ANSWER

                          Re: enabling method trace health Center

                          ‏2012-10-16T14:03:27Z  in response to SystemAdmin
                          Hi,

                          That's very odd, I only had to run for 20 seconds and was seeing sample counts in the 50's.

                          Ok, lets go back to the beginning. What is the level of java you are running with and what is the level of the health center agent you are using ?

                          "java -Xhealthcenter -version"

                          regards

                          Toby
                          • WiseMind
                            WiseMind
                            29 Posts
                            ACCEPTED ANSWER

                            Re: enabling method trace health Center

                            ‏2012-10-16T14:12:37Z  in response to SystemAdmin
                            Here is the result

                            INFO: Agent version "2.0.0.20111124"
                            java version "1.5.0"
                            Java(TM) 2 Runtime Environment, Standard Edition (build pap32devifx-20110627 (SR12 FP5 ))
                            IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc-32 j9vmap3223ifx-20110624 (JIT enabled)
                            J9VM - 20110623_85457_bHdSMr
                            JIT - 20100623_16197ifx10_r8
                            GC - FP22011_06)
                            JCL - 20110627
                            • SystemAdmin
                              SystemAdmin
                              188 Posts
                              ACCEPTED ANSWER

                              Re: enabling method trace health Center

                              ‏2012-10-16T14:25:29Z  in response to WiseMind
                              Those levels look fine, what we need to do is understand why we are not getting any information out (including method trace) as from what you have said, you have it all configured correctly.

                              Can you paste in the exact launch command you are using for your application?
                              • WiseMind
                                WiseMind
                                29 Posts
                                ACCEPTED ANSWER

                                Re: enabling method trace health Center

                                ‏2012-10-16T14:41:36Z  in response to SystemAdmin
                                I am using the following command

                                java -Xhealthcenter Toby
                                Thanks