MCPcopy Create free account
hub / github.com/GCMiner/GCMiner / studentLearnMonitor

Method studentLearnMonitor

src/test/java/Monitor.java:7–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5 final static ClassPool pool = ClassPool.getDefault();
6 final static String classname = "examples.Student";
7 public void studentLearnMonitor() throws Exception{
8 CtClass ss = pool.getCtClass(classname);
9 CtClass.debugDump="./dump";
10 String methodname = "learn";
11 CtMethod learn_ori = ss.getDeclaredMethod(methodname);
12 //拷贝一份learn方法
13 CtMethod learn_cp = CtNewMethod.copy(learn_ori,learn_ori.getName()+"_cp",ss,null);
14 //添加拷贝后的方法
15 ss.addMethod(learn_cp);
16 //修改learn方法:原代码前后添加时间
17 String src = "{"+
18 "long start = System.currentTimeMillis();" +
19 learn_ori.getName()+"_cp($$);"+
20 "long end = System.currentTimeMillis();"+
21 "System.out.println(end-start);"+
22 "}";
23 learn_ori.setBody(src);
24 ss.toClass();
25 //生成.class文件,主要用于调试,查看是否有代码片段被忽略
26 //ss.writeFile();
27 Student s = new Student();
28 s.learn();
29 }
30
31 public void studentDisplayMonitor() throws Exception{
32 CtClass ss = pool.getCtClass(classname);

Callers

nothing calls this directly

Calls 1

learnMethod · 0.95

Tested by

no test coverage detected