diff --git a/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java index 24d1471..127dc87 100644 --- a/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java +++ b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/DebuggingControlAction.java @@ -166,6 +166,10 @@ // �I�����C����͒���traceCollector��TraceJSON#getObjectFlow()���Ăяo�����̃R�[�h // printObjectFlow(vm, thread, threadInstance); + + // �X�s�[�h�v���Ɣ�r + SpeedTester st = new SpeedTester(); + st.countMethodExecutionTest(vm, thread); } /** diff --git a/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/SpeedTester.java b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/SpeedTester.java new file mode 100644 index 0000000..9c80b8f --- /dev/null +++ b/org.ntlab.reverseDebugger/src/org/ntlab/debuggingControl/SpeedTester.java @@ -0,0 +1,106 @@ +package org.ntlab.debuggingControl; + +import com.sun.jdi.ClassNotLoadedException; +import com.sun.jdi.IncompatibleThreadStateException; +import com.sun.jdi.IntegerValue; +import com.sun.jdi.InvalidTypeException; +import com.sun.jdi.InvocationException; +import com.sun.jdi.LongValue; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.StringReference; +import com.sun.jdi.ThreadReference; +import com.sun.jdi.Value; +import com.sun.jdi.VirtualMachine; + +public class SpeedTester { + private static final String TRACE = "org.ntlab.traceCollector.tracer.trace"; + + public void countMethodExecutionTest(VirtualMachine vm, ThreadReference thread) { + MethodCaller mc = new MethodCaller(vm, thread); + try { + StringReference threadId = mc.getVm().mirrorOf(String.valueOf(mc.getThreadId())); + ObjectReference threadInstance = (ObjectReference)mc.callStaticMethod(TRACE, "TraceJSON", "getThreadInstance", threadId); + ObjectReference roots = (ObjectReference)mc.setObj(threadInstance).callInstanceMethod("getRoot"); + ObjectReference currentMe = (ObjectReference)mc.callInstanceMethod("getCurrentMethodExecution"); + String targetSignature = ((StringReference)mc.setObj(currentMe).callInstanceMethod("getSignature")).value(); + System.out.println("targetSignature: " + targetSignature); + final int LOOP = 10; + + // �ꎟ��͂̒T��������, ReverseDebugger���ɍ쐬�����ꍇ�ł̏������Ԍv�� + System.out.println(); System.out.println("ReverseDebugger:"); + test(mc, roots, targetSignature, SpeedTestType.REVERSE_DEBUGGER, LOOP); + + // �ꎟ��͂̒T��������, �^�[�Q�b�g�v���O�����ɖ��ߍ���TraceCollector���ɍ쐬�����ꍇ�ł̏������Ԍv�� + System.out.println(); System.out.println("TraceCollector:"); + test(mc, roots, targetSignature, SpeedTestType.TRACE_COLLECTOR, LOOP); + } catch (InvalidTypeException | ClassNotLoadedException + | InvocationException | IncompatibleThreadStateException e) { + e.printStackTrace(); + } + } + + private void test(MethodCaller mc, ObjectReference roots, String targetSignature, SpeedTestType type, final int LOOP) + throws InvalidTypeException, ClassNotLoadedException, InvocationException, IncompatibleThreadStateException { + int count = 0; + long beforeTime, afterTime, executionTime, sumTime = 0, bestTime = -1, worstTime = -1; + for (int i = 0; i < LOOP; i++) { + mc.setObj(roots); + beforeTime = System.nanoTime(); + switch (type) { + case REVERSE_DEBUGGER: + count = countMethodExecutionInReverseDebugger(mc, targetSignature, 0, "--------"); + break; + case TRACE_COLLECTOR: + count = countMethodExecutionInTraceCollector(mc, targetSignature, 0, "--------"); + break; + } + afterTime = System.nanoTime(); + executionTime = afterTime - beforeTime; + System.out.print("count: " + count + " "); + System.out.println(String.format("Time%-2d: %10d nsec", (i + 1), executionTime)); + sumTime += (executionTime); + bestTime = (bestTime < 0 || executionTime < bestTime) ? executionTime : bestTime; + worstTime = (worstTime < 0 || executionTime > worstTime) ? executionTime : worstTime; + } + System.out.println(String.format("%-12s: %10d nsec", "BestTime", bestTime)); + System.out.println(String.format("%-12s: %10d nsec", "WorstTime", worstTime)); + System.out.println(String.format("%-12s: %10d nsec", "AverageTime", (sumTime / LOOP))); + } + + private int countMethodExecutionInTraceCollector(MethodCaller mc, String targetSignture, int count, String indent) + throws InvalidTypeException, ClassNotLoadedException, InvocationException, IncompatibleThreadStateException { + VirtualMachine vm = mc.getVm(); + String methodName = "countMethodExecutionInTraceCollector"; + return ((IntegerValue)mc.callStaticMethod(TRACE, "TraceJSON", methodName, mc.getObj(), + vm.mirrorOf(targetSignture), vm.mirrorOf(count), vm.mirrorOf(indent))).value(); + } + + private int countMethodExecutionInReverseDebugger(MethodCaller mc, String targetSignature, int count, String indent) + throws InvalidTypeException, ClassNotLoadedException, InvocationException, IncompatibleThreadStateException { + VirtualMachine vm = mc.getVm(); + ObjectReference methodExecutions = mc.getObj(); + if (methodExecutions == null) { + return count; + } + int methodExecutionsSize = ((IntegerValue)mc.callInstanceMethod("size")).value(); + if (methodExecutionsSize == 0) { + return count; + } + for (int i = 0; i < methodExecutionsSize; i++) { + IntegerValue index = vm.mirrorOf(i); + ObjectReference methodExecution = (ObjectReference)mc.setObj(methodExecutions).callInstanceMethod("get", index); + String signature = ((StringReference)mc.setObj(methodExecution).callInstanceMethod("getSignature")).value(); +// System.out.println(indent + signature); + if (targetSignature.equals(signature)) { + count++; + } + ObjectReference children = (ObjectReference)mc.callInstanceMethod("getChildren"); + count = countMethodExecutionInReverseDebugger(mc.setObj(children), targetSignature, count, indent + "--------"); + } + return count; + } + + private enum SpeedTestType { + REVERSE_DEBUGGER, TRACE_COLLECTOR; + } +}