-
Notifications
You must be signed in to change notification settings - Fork 21
2 Usage
Assuming you have completed this step.
If you get a different WEB UI, don't worry. Just a UI update, content is same.
Watch is a function, that enhances specific method, and record the input and output params and time consuming.
Once you exec the cmd as following, you will get a string Base64(123) = MTIz
$ curl 'http://localhost:8080/base64?str=123'
Base64(123) = MTIzBecuase the demo project has code like this
@GetMapping("/base64")
public ResponseEntity<String> base64(String str) {
return ResponseEntity.ok("Base64("+str+") = "
+ new BASE64Encoder().encode(str.getBytes()));
}Enter the className#MethodName which is com.example.demo.DemoApplication#base64 to the input of the Watch section in the Web UI. Then click the watch button, will get some logs in the right log window, which shows the transformer is added success. (Make minCost be 0, it's a filter to print the log)
Run the cmd curl 'http://localhost:8080/base64?str=123' again , and have a look at the log window. The time consuming as well as input and output params have been printed, that is the Watch.

By default, the watch will effect 100 times. If you want to remove the watch monitor, click the effected class button, all of the effected classes will be list in a dialog. You can input the uuid of the transformer to delete it. Well, if you want to delete all the effects, click the reset button.

Of course, I think you have noticed that the log showed from newest to oldest.
Similar with Watch, OuterWatch enhances the outer method to record same things.
Watch change the code of the method self:
// watch
void mechod() {
...some code // change the code, insert some code before and after original code
}
==>
void mechod() {
...record input params and start time
...some code // change the code, insert some code before and after original code
...record output params and end time - start time
} OuterWatch change the code of outMethod:
void outMethod() {
...some code
innerMethod(); // change this line, insert some code before and after this line
...some code
}
==>
void outMethod() {
...some code
...record input params of innerMethod and start time
innerMethod(); // change this line, insert some code before and after this line
...record output params and end time - start time
...some code
}Outer watch the *#encode in the base64 as following, you noticed that, it is allowed that use a pattern * as the className of inner method. Well, the outer method is not.

Run the curl command again, you will get the log in log window, line26 is the line number of the *#encode in base64, req, res belong to *#encode method.
$ curl http://localhost:8080/base64?str=123
Finally, remember to reset the effected classes.
Trace is similar to OuterWatch, OuterWatch effects the specific inner method, but Trace effects all inner methods. Well, Trace only record the time consuming, without the req and res. It can be used to analyze function time-consuming to know where the most time is spent. The method from java.lang.xx (exclude java.lang.Thread) will be ignore. In addtion, the method in lambda cannot be traced, because in actually, these methods belong to a anonymous class, instead of the current class.

Rememer to reset the transformer.
ChangeBody will change the body of specific method. Through the previous study, you should easily learn its usage, as follows:

The relationship between ChangeResult and ChangeBody is like OuterWatch and Watch.
You can change the return value of inner method using $_ = newReturnValue;. In addition, if you choose the javassist engine, you can also use the javassist built-in varibles, like $1, $args, $proceed and so on. Use $_ = 1 + $proceed($$); to execute the original method to get the result then plus 1. In the other hand if you choose the ASM engine, you can also use $_ $1 $proceed, exclude $$, use $_ = 1 + $proceed(); instead.

Exec triggers the execution of a piece of code immediately~
What you need to know:
- 1 In the class
w.Global, I have prepare many useful methods for you code-
info(Object)anderror(Object, Throwable)print content to log window. -
ognl("ognl expression")execute ognl expression. -
reset()same with reset in web ui. -
readFile(String)read file and return string lines. -
getInstances(Class)get the top 100 instances of the specific class.
-
- 2 For spring boot, you can use the built-in varible
ctx, which is theSpringApplicationContext. Usectx.getBean("beanName")to get the bean Object. - 3 In the editor area, including
ExecandChangeBody,intandIntegercannot auto box/unbox, because thejavassistcompiler is too simple to finish the job. Also, any new feature in jdk 4+ will not supported, includinglambda,genericand so on. Become a primitive man, that is the price of powerful features.

Use a .class file to replace the class running in the jvm. Change the source code, compile to get the class file.

Then upload this file, class will be changed.
