4 Replies Latest reply on Oct 7, 2012 11:24 AM by nhantran

    Using Byteman to micro-benmark my app

    nhantran

      Hello,

       

      I am using Byteman to measure some methods in my project. I needed the Instrumentation object to calculate objects size, but could not find it out from inside Helper class.

      Looking at HelperManager in the codebase of Byteman, I have seen the Instrumentation object there but not being used/exposed.

       

      Should we add a public method to public this object:

       

      class HelperManager {

      public Instrumentation getInstrumentation() {

      return inst;

      }

      }

       

      class Rule {

      public Instrumentation getInstrumentation() {

      return helperManager.getInstrumentation();

      }

      }

       

      and later, in any subclass of Helper, we can reference the Instrumentation object via the rule?

       

      Or do we have other better way to get the Instrumentation object?

       

      Thanks.

      Nhan

        • 1. Re: Using Byteman to micro-benmark my app
          adinn

          Hi Nhan,

          Nhan Tran wrote:

           

          Hello,

           

          I am using Byteman to measure some methods in my project. I needed the Instrumentation object to calculate objects size, but could not find it out from inside Helper class.

          Looking at HelperManager in the codebase of Byteman, I have seen the Instrumentation object there but not being used/exposed.

           

          Hmm, I wonder if maybe there might be a good reason for that? :-)

           

          Nhan Tran wrote:

           

          Or do we have other better way to get the Instrumentation object?

           

          The Instrumentation instance is the key to Pandora's box since it provides access to the whole classbase and allows transformation of any class. It is quite probably the most extreme security risk available to any Java program to provide access to this instance and exposing it would mean that loading Byteman into production systems would be a very unwise move. That would be a significant lost opportunity as Byteman is a very powerful debugging tool for live installations. So, Byteman takes great care to ensure that only specific Byteman classes (actually instances) have access to this instance.

           

          Interestingly, your problem about computing object sizes has been raised before on this forum by Rafael Soares. On that thread I suggested just exposing the getObjectSize capability. I believe Rafael decided to implement a second agent to provide access  to the getObjectSize method -- I think because he needed the behaviour  imediately. However, it could be implemented safely by adding a getObjectSize() method to HelperManager and having it call the getObjectSize() method of the Instrumentation instance. The Rule could expose this via its own getObjectSize() method and, indeed, getObjectSize() might as well be added as a method in the standard Helper class so it is available by default to all rules. If you want this please raise a JIRA issue for it. Indeed, if you can implement and test it with your own application I'd be happy to accept the code as a contribution.

           

          regards,

           

           

          Andrew Dinn

          1 of 1 people found this helpful
          • 2. Re: Using Byteman to micro-benmark my app
            nhantran

            Andrew Dinn wrote:

             

            The Instrumentation instance is the key to Pandora's box since it provides access to the whole classbase and allows transformation of any class. It is quite probably the most extreme security risk available to any Java program to provide access to this instance and exposing it would mean that loading Byteman into production systems would be a very unwise move

            This makes sense. Thanks, Andrew

             

            I am creating a Jira issue at https://issues.jboss.org/browse/BYTEMAN-221 and will attach the patch shortly.

             

            Regards.

            Nhan

            • 3. Re: Using Byteman to micro-benmark my app
              adinn

              Hi Nhan,

               

              Thank you very much for raising the JIRA even more so providing a fix and testing it. It's always extremely gratifying to have a user find a new use case and even better when they enable it and make the code available for others to benefit from. That's what open source is all about.

               

              In order for me to accept your code I  need to ask you to visit  https://cla.jboss.org/ and follow the instructions to register as an individual contributor to Byteman (you will need to select this as the project you wish to contribute to). This is a necessary legal step to confirm that you are willing to allow Red Hat to publish your code under the open source license used by the project (LGPL). I get forwarded a notice when you sign which allows me to approve you as a contributor. After that I can add your patch to the repository and it will appear into the next release (I also always mention all new contributors when the release goes out).

               

              Once again, thanks for your help.

               

              regards

               

               

              Andrew Dinn

              • 4. Re: Using Byteman to micro-benmark my app
                nhantran

                Done, Andrew.

                 

                Thank you for your support to get me to involve the community

                 

                Regards

                Nhan