0

I am new at instrumentation world. I am trying to instrumentate a remote JVM at Runtime. Actually, i have to log all classes or part of them and transform them.. I have read many documents and i found this code HERE

I changed the code and i replaced

// Run sayHello in a loop
Person person = new Person();
for(int i = 0; i < 1000; i++) {
    person.sayHello(i);
    person.sayHello("" + (i*-1));
    Thread.currentThread().join(5000);
}

by this one:

for (int i = 1; i < args.length; i++) {
    String className = args[i] ;
    System.out.println("className" + className);
    // Call transformClass on the transformer MBean
    server.invoke(on, "transformClass", new Object[]{className}, new String[]{String.class.getName()});
}

But i found that args.length=0 I don't know what the args[] contain...And if it contains loaded classes (i assume) then why it is empty..

Any help please?

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
GEmyy
  • 1
  • 1
  • 8

1 Answers1

0

I wrote that code, but I don't understand what you're trying to do in your code. The referenced github gists were in reference to the answer to this SO question, so it may help you to re-read that question.

There are multiple steps involved, and the classes need to be packaged in a specific way, but the basics are:

  1. Use the AgentInstaller to install the instrumentation agent into a running JVM.
  2. Connect to the JVM via JMX.
  3. Invoke the transformClass(String className, String methodName, String methodSignature) MBean operation to instrument the class using the demo transformer.
Community
  • 1
  • 1
Nicholas
  • 15,916
  • 4
  • 42
  • 66
  • thnx @Nicholas... it's done ;) But i want to ask you an other question: with your code on github, could I instrument classes witch are locatedin another application? – GEmyy Apr 07 '16 at 17:24
  • @GEmyy; Yup. That's the idea. Install the agent into the target app, then instrument it. – Nicholas Apr 07 '16 at 18:21
  • thnx @Nicholas, but how should i install the agent into the target app? the "AgentInstaller" Class exists in my program But i want to instrumentate another application.. Should I just change the PID in the AgentInstaller Class or what exactely? – GEmyy Apr 08 '16 at 08:07
  • Because when i do this: VirtualMachine vm = VirtualMachine.attach(pid_of_the _other_app); I got 2 crashed apps – GEmyy Apr 08 '16 at 08:30