diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java index f95a2ed..c06bb3f 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java @@ -42,4 +42,27 @@ public MethodExecutionJPDA getCallerMethodExecution() { return callerMethodExecution; } + + /** + * ���̃��\�b�h���s����т��̑S�Ăяo������Ăяo���؂̒��ŋt�����ɒT������(�������Avisitor �� true ��Ԃ��܂�) + * @param visitor �r�W�^�[ + * @return�@true -- �T���𒆒f����, false -- �Ō�܂ŒT������ + */ + public boolean traverseMethodExecutionsBackward(IMethodExecutionVisitorJPDA visitor) { + if (visitor.preVisitMethodExecution(this)) return true; + ArrayList calledMethodExecutions = getChildren(); + for (int i = calledMethodExecutions.size() - 1; i >= 0; i--) { + MethodExecutionJPDA child = calledMethodExecutions.get(i); + if (child.traverseMethodExecutionsBackward(visitor)) return true; + } + if (visitor.postVisitMethodExecution(this, null)) return true; + return false; + } + + public interface IMethodExecutionVisitorJPDA { + abstract public boolean preVisitThread(ThreadInstanceJPDA thread); + abstract public boolean postVisitThread(ThreadInstanceJPDA thread); + abstract public boolean preVisitMethodExecution(MethodExecutionJPDA methodExecution); + abstract public boolean postVisitMethodExecution(MethodExecutionJPDA methodExecution, ArrayList children); + } } diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTrace.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTrace.java index 89fa699..7f67456 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTrace.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTrace.java @@ -10,8 +10,8 @@ * @param args */ public static void main(String[] args) { -// Trace trace = new Trace("documents\\worstCase.txt"); - Trace trace = new TraceJSON("documents\\_worstCase.txt"); +// Trace trace = new Trace("traces\\worstCase.txt"); + Trace trace = new TraceJSON("traces\\_worstCase.txt"); // HashSet marked = trace.getMarkedMethodSignatures(1255991806833871L, 1255991808597322L); HashSet marked = trace.getMarkedMethodSignatures(1044823638835493L, 1044823639353788L); System.out.println("===== Marked Methods ====="); diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTraceJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTraceJPDA.java new file mode 100644 index 0000000..0a02209 --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TestTraceJPDA.java @@ -0,0 +1,134 @@ +package org.ntlab.trace; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class TestTraceJPDA { + + /** + * @param args + */ + public static void main(String[] args) { + try { + final HashMap methodTraceCounts = new HashMap<>(); // ���̃��\�b�h�̎��s���܂ރg���[�X�̐� + final HashMap methodExecCountSums = new HashMap<>(); // ���̃��\�b�h�̑S���s�g���[�X�ɂ����鑍���s�� + final HashMap methodExecDepthSums = new HashMap<>(); // ���̃��\�b�h�̑S���s�g���[�X�ɂ�����S���s�̌Ăяo���[���̑��a + File dir; + dir = new File("traces"); + for (File file: dir.listFiles()) { + if (file.getName().endsWith(".log")) { + TraceJPDA traceJPDA = new TraceJPDA(new BufferedReader(new FileReader(file))); + final HashMap methodExecCounts = new HashMap<>(); + final HashMap methodExecDepthSum = new HashMap<>(); + MethodExecutionJPDA.IMethodExecutionVisitorJPDA visitor = new MethodExecutionJPDA.IMethodExecutionVisitorJPDA() { + private int depth = 0; + + @Override + public boolean preVisitThread(ThreadInstanceJPDA thread) { + depth = 0; + return false; + } + @Override + public boolean postVisitThread(ThreadInstanceJPDA thread) { + return false; + } + @Override + public boolean preVisitMethodExecution(MethodExecutionJPDA methodExecution) { + String signature = methodExecution.getSignature(); + if (methodExecCounts.get(signature) == null) { + methodExecCounts.put(signature, 1); + } else { + methodExecCounts.put(signature, methodExecCounts.get(signature) + 1); + } + if (methodExecDepthSum.get(signature) == null) { + methodExecDepthSum.put(signature, depth); + } else { + methodExecDepthSum.put(signature, methodExecDepthSum.get(signature) + depth); + } + depth++; + return false; + } + @Override + public boolean postVisitMethodExecution(MethodExecutionJPDA methodExecution, ArrayList children) { + depth--; + return false; + } + }; + traceJPDA.traverseMethodExecutionsBackward(visitor); + + for (String signature: methodExecCounts.keySet()) { + if (methodExecCounts.get(signature) != null) { + if (methodTraceCounts.get(signature) == null) { + methodTraceCounts.put(signature, 1); + } else { + methodTraceCounts.put(signature, methodTraceCounts.get(signature) + 1); + } + if (methodExecCountSums.get(signature) == null) { + methodExecCountSums.put(signature, methodExecCounts.get(signature)); + } else { + methodExecCountSums.put(signature, methodExecCountSums.get(signature) + methodExecCounts.get(signature)); + } + } + if (methodExecDepthSum.get(signature) != null) { + if (methodExecDepthSums.get(signature) == null) { + methodExecDepthSums.put(signature, methodExecDepthSum.get(signature)); + } else { + methodExecDepthSums.put(signature, methodExecDepthSums.get(signature) + methodExecDepthSum.get(signature)); + } + } + } + } + } + for (String signature: methodTraceCounts.keySet()) { + int traceCount = methodTraceCounts.get(signature); + int execCount = methodExecCountSums.get(signature); + System.out.println(signature + ":" + traceCount + ":" + + ((double)execCount / (double)traceCount) + ":" + + ((double)methodExecDepthSums.get(signature) / (double)execCount)); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + +// TraceJPDA trace150938 = new TraceJPDA("traces\\trace1500938.log"); +// System.out.println("===== JPDA Trace Methods ====="); +// for (String method: trace150938.getAllMethodSignatures()) { +// System.out.println(method); +// } +/* + * ���������� + * +===== JPDA Trace Methods ===== +org.gjt.sp.jedit.bsh.Parser.jj_3R_51() +org.gjt.sp.jedit.textarea.TextArea.getHorizontalOffset() +org.gjt.sp.jedit.bsh.Types.getTypes() +org.gjt.sp.jedit.EBMessage.toString() +org.gjt.sp.jedit.bsh.Parser.jj_3R_84() +org.gjt.sp.jedit.bsh.Reflect.invokeObjectMethod() +org.gjt.sp.jedit.TextUtilities.findMatchingBracket() +org.gjt.sp.jedit.textarea.TextArea.getLastPhysicalLine() +org.gjt.sp.jedit.textarea.TextAreaPainter.isWrapGuidePainted() +org.gjt.sp.jedit.bsh.Parser.MultiplicativeExpression() +org.gjt.sp.jedit.textarea.SelectionManager.getSelectionStartAndEnd() +org.gjt.sp.jedit.Buffer.toString() +org.gjt.sp.jedit.bsh.Parser.jj_3R_86() +org.gjt.sp.jedit.textarea.TextArea.getPainter() +org.gjt.sp.jedit.bsh.BshClassManager$SignatureKey.equals() +org.gjt.sp.jedit.bsh.Parser.jj_3R_44() +org.gjt.sp.jedit.bsh.Parser.jj_3R_142() +org.gjt.sp.jedit.textarea.SelectionManager.addToSelection() +org.gjt.sp.jedit.gui.StatusBar$2.actionPerformed() +org.gjt.sp.jedit.bsh.JavaCharStream.getEndLine() +org.gjt.sp.jedit.bsh.Parser.jj_ntk() +org.gjt.sp.util.WorkThreadPool.fireProgressChanged() +org.gjt.sp.jedit.textarea.TextArea.getVisibleLines() + : + */ + } +} diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java index b52135b..1ab2348 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java @@ -46,4 +46,13 @@ public MethodExecutionJPDA getCuurentMethodExecution() { return curMethodExecution; } + + public void traverseMethodExecutionsBackward(MethodExecutionJPDA.IMethodExecutionVisitorJPDA visitor) { + visitor.preVisitThread(this); + for (int i = 0; i < roots.size(); i++) { + MethodExecutionJPDA root = roots.get(i); + root.traverseMethodExecutionsBackward(visitor); + } + visitor.postVisitThread(this); + } } diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java index 5c86d3f..54fa06f 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java @@ -16,100 +16,140 @@ * �w�肵��JSON�g���[�X�t�@�C������ǂ��� Trace �I�u�W�F�N�g�𐶐����� * @param traceFile �g���[�X�t�@�C���̃p�X */ + public TraceJPDA(BufferedReader file) { + try { + readJPDA(file); + file.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * �w�肵��JSON�g���[�X�t�@�C������ǂ��� Trace �I�u�W�F�N�g�𐶐����� + * @param traceFile �g���[�X�t�@�C���̃p�X + */ public TraceJPDA(String traceFile) { - super(); BufferedReader file; try { file = new BufferedReader(new FileReader(traceFile)); - // �g���[�X�t�@�C���ǂݍ��� - String line = null; - String[] columns; - String[] columns2; - String[] stack; - String[] signature; - String threadId; - int prevDepth = 0; - int depth = 0; - long timeStamp = 0L; - ThreadInstanceJPDA thread = null; - while ((line = file.readLine()) != null) { - // �g���[�X�t�@�C���̉�� - columns = line.split(":"); - if (columns.length < 4) continue; - threadId = columns[0]; - stack = columns[2].split(" "); - columns2 = columns[3].split("\t"); - if (columns2.length < 2) continue; - timeStamp = Integer.parseInt(columns[1]) * 3600 - + Integer.parseInt(stack[stack.length - 1]) * 60 - + Integer.parseInt(columns2[0]); - depth = stack.length - 1; - signature = columns2[1].split(" -- "); - thread = threads.get(threadId); - if (thread == null) { - thread = new ThreadInstanceJPDA(threadId); - threads.put(threadId, thread); - } - if (signature.length < 2) continue; - for (int i = 0; i < depth - prevDepth + 1; i++) { - thread.returnMethod(); - } - thread.callMethod(signature[1] + "." + signature[0] + "()", timeStamp); - prevDepth = depth; - } + readJPDA(file); file.close(); } catch (IOException e) { e.printStackTrace(); } } + + private void readJPDA(BufferedReader file) throws IOException { + // �g���[�X�t�@�C���ǂݍ��� + String line = null; + String[] columns; + String[] columns2; + String[] stack; + String[] signature; + String threadId; + int prevDepth = 0; + int depth = 0; + long timeStamp = 0L; + ThreadInstanceJPDA thread = null; + while ((line = file.readLine()) != null) { + // �g���[�X�t�@�C���̉�� + columns = line.split(":"); + if (columns.length < 4) continue; + threadId = columns[0]; + stack = columns[2].split(" "); + columns2 = columns[3].split("\t"); + if (columns2.length < 2) continue; + timeStamp = Integer.parseInt(columns[1]) * 3600 + + Integer.parseInt(stack[stack.length - 1]) * 60 + + Integer.parseInt(columns2[0]); + depth = stack.length - 1; + signature = columns2[1].split(" -- "); + thread = threads.get(threadId); + if (thread == null) { + thread = new ThreadInstanceJPDA(threadId); + threads.put(threadId, thread); + } + if (signature.length < 2) continue; + for (int i = 0; i < depth - prevDepth + 1; i++) { + thread.returnMethod(); + } + thread.callMethod(signature[1] + "." + signature[0] + "()", timeStamp); + prevDepth = depth; + } + } /** * ���\�b�h���ɑS���\�b�h���s��S�ẴX���b�h������o�� * @return ���\�b�h�V�O�j�`�����烁�\�b�h���s�̃��X�g�ւ�HashMap */ public HashMap> getAllMethodExecutions() { - HashMap> results = new HashMap<>(); - for (String threadId: threads.keySet()) { - ThreadInstanceJPDA thread = threads.get(threadId); - for (MethodExecutionJPDA root: thread.getRoot()) { - getAllMethodExecutions(root, results); - } + final HashMap> results = new HashMap<>(); + for (ThreadInstanceJPDA thread: threads.values()) { + thread.traverseMethodExecutionsBackward(new MethodExecutionJPDA.IMethodExecutionVisitorJPDA() { + @Override + public boolean preVisitThread(ThreadInstanceJPDA thread) { + return false; + } + @Override + public boolean postVisitThread(ThreadInstanceJPDA thread) { + return false; + } + @Override + public boolean preVisitMethodExecution(MethodExecutionJPDA methodExecution) { + ArrayList executions = results.get(methodExecution.getSignature()); + if (executions == null) { + executions = new ArrayList(); + results.put(methodExecution.getSignature(), executions); + } + executions.add(methodExecution); + return false; + } + @Override + public boolean postVisitMethodExecution(MethodExecutionJPDA methodExecution, ArrayList children) { + return false; + } + }); } return results; } - - private void getAllMethodExecutions(MethodExecutionJPDA method, HashMap> results) { - ArrayList executions = results.get(method.getSignature()); - if (executions == null) { - executions = new ArrayList(); - results.put(method.getSignature(), executions); - } - executions.add(method); - for (MethodExecutionJPDA child: method.getChildren()) { - getAllMethodExecutions(child, results); - } - } /** * �S���\�b�h�̃V�O�j�`�����擾���� * @return �S���\�b�h�V�O�j�`�� */ public HashSet getAllMethodSignatures() { - - HashSet results = new HashSet(); - for (String threadId: threads.keySet()) { - ThreadInstanceJPDA thread = threads.get(threadId); - for (MethodExecutionJPDA root: thread.getRoot()) { - getAllMethodSignatures(root, results); - } - } + final HashSet results = new HashSet(); + for (ThreadInstanceJPDA thread: threads.values()) { + thread.traverseMethodExecutionsBackward(new MethodExecutionJPDA.IMethodExecutionVisitorJPDA() { + @Override + public boolean preVisitThread(ThreadInstanceJPDA thread) { + return false; + } + @Override + public boolean postVisitThread(ThreadInstanceJPDA thread) { + return false; + } + @Override + public boolean preVisitMethodExecution(MethodExecutionJPDA methodExecution) { + results.add(methodExecution.getSignature()); + return false; + } + @Override + public boolean postVisitMethodExecution(MethodExecutionJPDA methodExecution, ArrayList children) { + return false; + } + + }); + } return results; } - - private void getAllMethodSignatures(MethodExecutionJPDA method, HashSet results) { - results.add(method.getSignature()); - for (MethodExecutionJPDA child: method.getChildren()) { - getAllMethodSignatures(child, results); - } + + public void traverseMethodExecutionsBackward(MethodExecutionJPDA.IMethodExecutionVisitorJPDA visitor) { + for (ThreadInstanceJPDA thread: threads.values()) { + visitor.preVisitThread(thread); + thread.traverseMethodExecutionsBackward(visitor); + visitor.postVisitThread(thread); + } } }