diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java new file mode 100644 index 0000000..f95a2ed --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/MethodExecutionJPDA.java @@ -0,0 +1,45 @@ +package org.ntlab.trace; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +public class MethodExecutionJPDA { + private String signature; + private MethodExecutionJPDA callerMethodExecution = null; + private ArrayList children = new ArrayList(); + private long entryTime = 0L; + + public MethodExecutionJPDA(String signature, long enterTime) { + this.signature = signature; + this.entryTime = enterTime; + } + + public String getSignature() { + return signature; + } + + public long getEntryTime() { + return entryTime; + } + + public void addChild(MethodExecutionJPDA child) { + children.add(child); + } + + public ArrayList getChildren() { + return children; + } + + public void setCaller(MethodExecutionJPDA callerMethodExecution) { + this.callerMethodExecution = callerMethodExecution; + } + + public MethodExecutionJPDA getParent() { + return callerMethodExecution; + } + + public MethodExecutionJPDA getCallerMethodExecution() { + return callerMethodExecution; + } +} diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java new file mode 100644 index 0000000..b52135b --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/ThreadInstanceJPDA.java @@ -0,0 +1,49 @@ +package org.ntlab.trace; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; + +public class ThreadInstanceJPDA { + private ArrayList roots = new ArrayList(); + private MethodExecutionJPDA curMethodExecution = null; + private String id; + + public ThreadInstanceJPDA(String id) { + this.id = id; + } + + public void addRoot(MethodExecutionJPDA root) { + this.roots.add(root); + curMethodExecution = root; + } + + public ArrayList getRoot() { + return roots; + } + + public String getId() { + return id; + } + + public void callMethod(String signature, long timeStamp) { + MethodExecutionJPDA newMethodExecution = new MethodExecutionJPDA(signature, timeStamp); + if (curMethodExecution != null) { + curMethodExecution.addChild(newMethodExecution); + newMethodExecution.setCaller(curMethodExecution); + curMethodExecution = newMethodExecution; + } else { + addRoot(newMethodExecution); + } + } + + public void returnMethod() { + if (curMethodExecution == null) return; + curMethodExecution = curMethodExecution.getParent(); + } + + public MethodExecutionJPDA getCuurentMethodExecution() { + return curMethodExecution; + } +} diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java new file mode 100644 index 0000000..5c86d3f --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/trace/TraceJPDA.java @@ -0,0 +1,115 @@ +package org.ntlab.trace; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Stack; + +public class TraceJPDA { + protected HashMap threads = new HashMap(); + + /** + * �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; + } + file.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * ���\�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); + } + } + 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); + } + } + return results; + } + + private void getAllMethodSignatures(MethodExecutionJPDA method, HashSet results) { + results.add(method.getSignature()); + for (MethodExecutionJPDA child: method.getChildren()) { + getAllMethodSignatures(child, results); + } + } +}