Using Byteman to debug Teiid
van.halbert Aug 17, 2012 3:03 PMStarting a discussion on using Byteman to debug Teiid. Once more comments / examples are gathered, an article can be written that can better serve as a How-To.
Here are some of the questions that I'll attempt to answer:
- Why Byteman?
- Are there examples?
- How do you setup the examples and run them?
- Why Byteman? Its was fairly painless to setup and easy to inject new debug statements on the fly without having to restart the server
- Are there examples? (see MonitorTranslator.btm attachment)
RULE print Passed Command CLASS ^org.teiid.translator.ExecutionFactory HELPER org.teiid.byteman.BytemanHelperForTranslator METHOD createResultSetExecution AT ENTRY BIND cmd:QueryExpression=$1 IF TRUE DO printToString(cmd); ENDRULE RULE trace Execution INTERFACE org.teiid.translator.Execution HELPER org.teiid.byteman.BytemanHelperForTranslator METHOD execute AT EXIT BIND executioner=$0; IF TRUE DO debug(executioner.getClass().getName() + " performed execute\n"); ENDRULE RULE print Row Count INTERFACE ^org.teiid.translator.ResultSetExecution HELPER org.teiid.byteman.BytemanHelperForTranslator METHOD next AFTER INVOKE next IF TRUE DO printCount($!); ENDRULE
Notice the HELPER class, org.teiid.byteman.BytemanHelperForTranslator, that is being used. I've written a helper class to assist, initially, with generically handling objects and printing out relevant information. Attached you will find the source code for this class and the test.jar, and I'll cover installing it farther down.
How to setup and run the examples
- Download latest byteman (2.1.0): https://www.jboss.org/byteman/downloads
- Byteman has the option to install the agent using bminstall, but I found it easier to control (for me) to just change the run.conf by adding the following:
JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.byteman.transform.all -Dorg.jboss.byteman.debug -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=listener:true,boot:${BYTEMAN_HOME}/lib/byteman.jar"
Note: initially, I would change -Dorg.jboss.byteman.debug to -Dorg.jboss.byteman.verbose until you get the hang of it and your rules are fairly stable.
- Compile org.teiid.byteman.BytemanHelperForTranslator and create a jar. (see test.jar attachment that can be used with the rules above)
- deploy the jar by running: bmsubmit.sh [ -b | -s ] <jar>
where [ -b | -s ] determine if you want the jar on the boot path or the system path. I've been using boot path.
jar is the fullpath to the jar
Note: if you change and rebuild jar, the server must be restarted and the jar be redeployed.
- Create your rules file with the .btm extension (see MonitorTranslator.btm attachment)
- deploy the rules by running: bmsubmit.sh -l <rule file>
- to undeploy the rules, run: bmsubmit.sh -u <rule file>
You can keep deploying / undeploying and running your test without restarting server. If you get errors on deployment of rules and you want to clean it up, run: bmsubmit.sh -u (which will uninstall all rules and start fresh)
Once your rules are deployed, run your test and you should see the output in the console.
Example:
10:26:24,316 INFO [STDOUT] Installed rule using default helper : print Passed Command
10:26:24,317 INFO [STDOUT] rule.debug{print Passed Command} : vvvvvvvvvvvvvvvvvvvvvvvvvvv
10:26:24,317 INFO [STDOUT] rule.debug{print Passed Command} : ToString org.teiid.language.Select: SELECT com.jboss.datagrid.hotrod.Team.Name FROM com.jboss.datagrid.hotrod.Team
10:26:24,317 INFO [STDOUT] rule.debug{print Passed Command} : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10:26:24,351 INFO [STDOUT] Installed rule using default helper : trace Execution
10:26:24,352 INFO [STDOUT] rule.debug{trace Execution} : org.teiid.translator.object.ObjectExecution performed execute
10:26:24,358 INFO [STDOUT] Installed rule using default helper : print Row Count
10:26:24,358 INFO [STDOUT] rule.debug{print Row Count} : vvvvvvvvvvvvvvvvvvvvvvvvvvv
10:26:24,359 INFO [STDOUT] rule.debug{print Row Count} : Count java.util.ArrayList: 1
10:26:24,359 INFO [STDOUT] rule.debug{print Row Count} : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
BytemanHelperForTranslator.java.zip 801 bytes
-
test.jar 2.0 KB
-
MonitorTranslator.btm.zip 1.0 KB
-
MonitorRules.btm.zip 1.1 KB