Byteman – Byte code manipulation tool for Logging, Testing and Fault Injection

Byteman

Byteman is a byte code manipulation tool for fault injection, testing and tracing. The Byteman agent allows to inject the rules into the existing java application with out changing the source code. You can inject the rules during the JVM startup time or into running application with out build and redeploy. We can inject the rules for custom java classes, private methods and the JRE libraries as well. Below are the Byteman use cases.

  • Add logging statements for the legacy application
  • Inject fault scenarios to the application via Junit or TestNG unit test cases

Now, we will see simple java application for which we will add debug statements via Byteman.

Let us write a simple Java application.


package org.smarttechie;

/**
* Class will demonstrate the Byteman
* @author Siva
*
*/
public class BytemanDemonstration {
public static void main(String[] args) {
    System.out.println("With this class we are demonstrating the byteman");
 }
}

Download the latest Byteman distribution.

Write Byteman script to inject the debug statements for the above class.


RULE trace main entry
CLASS BytemanDemonstration
METHOD main
AT ENTRY
IF true
DO traceln("entering into main method")
ENDRULE

RULE trace main exit
CLASS BytemanDemonstration
METHOD main
AT EXIT
IF true
DO traceln("exiting the main method")
ENDRULE

Launch the JVM by passing the Byteman agent and the script file path.

 java -javaagent:${Byteman_Home}\lib\byteman.jar=script:${SCRIPT_FILE_PATH}\logrules.btm <class_name>

After launching the JVM, you will able to see the log messages coming from the script file.


entering into main method
With this class we are demonstrating the byteman
exiting the main method

For further exploration, follow the below links.

https://developer.jboss.org/wiki/ABytemanTutorial#top

https://developer.jboss.org/wiki/BMUnitUsingBytemanWithJUnitOrTestNGFromMavenAndAnt#top

Advertisements

I am Siva Prasad Rao Janapati. Working as a software developer. Has hands on experience on ATG Commerce(DAS/DPS/DCS), Mozu commerce, Broadleaf Commerce, Java, JEE, Spring, Play, JPA, Hibernate, Velocity, JMS, Jboss, Weblogic,Tomcat, Jetty, Apache, Apache Solr, Spring Batch, JQuery, NodeJS, SOAP, REST, MySQL, Oracle, Mongo DB, Memcached, HazelCast, Git, SVN, CVS, Ant, Maven, Gradle, Amazon Web services, Rackspace, Quartz, JMeter, Junit, Open NLP, Facebook Graph,Twitter4J, YouTube Gdata, Bazzarvoice,Yotpo, 4-Tell, Alatest, Shopzilla, Linkshare. I have hands on experience on open sources and commercial technologies.

Tagged with: ,
Posted in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

DZone

DZone MVB

Java Code Geeks
Java Code Geeks
%d bloggers like this: