ok - I think I was on a wild good chase with the manifest, although I suspect it does need
some tidying up.
Looking at the source for:
org.jboss.profiler.agent.Agent.redefine(Class[] clz, boolean instrument)
This method appears to the be part involved in instrumenting classes. I assume that
without instrumentation, we cannot gather stats. Now the confusing part:
redefine is called from the same class at three points:
addClasses()
removeClasses()
setEnabled()
each of which is called from the handler.
I don't want to add and remove classes manually each time, so I'll concern myself
with the enabled method call.
Take a look at the method:public static void setEnabled(boolean e) {
| if (isRepository()) {
| List<Class> l = new ArrayList<Class>();
|
| for (Class c : instrumentation.getAllLoadedClasses()) {
| String className = c.getName().replace(".", "/");
|
| boolean added = false;
| for (int i = 0; !added && i < includeList.size(); i++) {
| String classes = includeList.get(i);
| if (className.startsWith(classes)) {
| l.add(c);
| added = true;
| }
| }
| }
|
| Class[] clz = new Class[l.size()];
| for (int i = 0; i < l.size(); i++) {
| clz = l.get(i);
| }
|
| if (enabled) {
| redefine(clz, true);
| } else {
| redefine(clz, false);
| }
| }
| }
Code will never be instrumented if the repository is disabled (which is the default
value)
No instrumentation = no stats.
So I do the following:
configure jboss.profiler.properties with:
core=asm (javaassist doesn't seem to work)
repository=yes
Then:
1) start the application server, and run through my test case. I need to do this to get
the classes loaded by the classloader (is there a way to circumvent this?)
2) Using the jmx-console/socket client I enable the profiler. This causes the classes
which are in the classloader to be reloaded.
3) I then run my test again.
4) stopProfiler
5) getSnapshot 1
voila
One big caveat - I had to change the logic in :
private static void redefine(Class[] clz, boolean instrument)
to handle exception on a per class basis so that if loading a class fails we don't
bail out of the whole operation:
| if (clz != null) {
| for (Class c : clz) {
| try {
| byte[] buffer = null;
| if (instrument) {
| buffer = transformer.loadInstrumented(c.getName(), c.getClassLoader());
| } else {
| buffer = transformer.loadNonInstrumented(c.getName(),
c.getClassLoader());
| }
|
| if (buffer != null) {
| ClassDefinition cd = new ClassDefinition(c, buffer);
| l.add(cd);
| }
| }
| catch (Throwable t) {
| System.err.println("Failed to load [" + c.getName() + "]:
" + t.getMessage());
| }
| }
| }
|
Has anyone else had a similar experience or can shed some light on the issues?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4145160#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...