/**
  * Gets the total time of root node.
  *
  * @return The total time of root node
  */
 protected double getRootTotalTime() {
   CallTreeNode focusedNode = (CallTreeNode) cpuModel.getFocusTarget();
   if (focusedNode != null) {
     return focusedNode.getTotalTime();
   }
   return threadNode.getTotalTime();
 }
  @Ignore
  @Test
  public void gap() {
    SpanAlign root = makeSpanAlign(START_TIME, 240);
    CallTree callTree = new SpanCallTree(root);
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 0, 1, 1));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 1, 2, 1));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 2, 3, 1));
    callTree.add(4, makeSpanAlign(root.getSpanBo(), SYNC, (short) 3, 4, 1));
    callTree.add(-1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 4, 5, 1));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 5, 6, 1));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 6, 7, 1));
    callTree.add(-1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 7, 8, 1));
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 8, 9, 1));

    CallTreeIterator iterator = callTree.iterator();
    // assertEquals(5, iterator.size());

    while (iterator.hasNext()) {
      CallTreeNode node = iterator.next();
      SpanAlign align = node.getValue();
      for (int i = 0; i <= align.getDepth(); i++) {
        System.out.print("#");
      }
      System.out.println(" : gap=" + align.getGap());
    }
  }
Beispiel #3
0
 /**
  * When stopwatch is stopped, the the split is added to current tree node and this tree node is
  * popped from call stack. As a result, parent tree node becomes current tree node.
  *
  * @return Current (child) tree node
  */
 public CallTreeNode onStopwatchStop(Split split) {
   CallTreeNode currentNode = callStack.removeLast();
   currentNode.addSplit(split);
   if (callStack.isEmpty()) {
     onRootStopwatchStop(currentNode, split);
   }
   return currentNode;
 }
  @Test
  public void gapComplex() {
    SpanAlign root = makeSpanAlign(START_TIME, 240);
    CallTree callTree = new SpanCallTree(root);
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 0, 1, 1));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 1, 2, 1));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 2, 3, 1));
    callTree.add(4, makeSpanAlign(root.getSpanBo(), SYNC, (short) 3, 4, 1, -1, 1));

    SpanAlign rpc = makeSpanAlign(START_TIME + 5, 240);
    CallTree rpcTree = new SpanCallTree(rpc);
    rpcTree.add(1, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 0, 1, 1));
    rpcTree.add(2, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 1, 2, 1));
    rpcTree.add(3, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 2, 3, 1));
    rpcTree.add(4, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 3, 4, 1));
    callTree.add(rpcTree);

    CallTree asyncTree = new SpanAsyncCallTree(root);
    asyncTree.add(1, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 0, 5, 1, 1, -1));
    asyncTree.add(2, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 1, 6, 1, 1, -1));
    asyncTree.add(3, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 2, 7, 1, 1, -1));
    asyncTree.add(4, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 3, 8, 1, 1, -1));
    callTree.add(asyncTree);

    callTree.add(5, makeSpanAlign(root.getSpanBo(), SYNC, (short) 4, 5, 1));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 5, 3, 1));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 6, 4, 1));
    callTree.add(-1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 7, 6, 1));
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 8, 2, 1));

    CallTreeIterator iterator = callTree.iterator();
    // assertEquals(5, iterator.size());

    System.out.println("gapComplex");
    while (iterator.hasNext()) {
      CallTreeNode node = iterator.next();
      SpanAlign align = node.getValue();
      for (int i = 0; i <= align.getDepth(); i++) {
        System.out.print("#");
      }
      System.out.println(" : gap=" + align.getGap());
      if (!node.isRoot()) {
        assertEquals(1, align.getGap());
      }
    }
  }
 /**
  * Refreshes the callers and callees.
  *
  * @param callerNames The caller names
  * @param calleeNames The callee names
  * @param frameRootNodes The frame root nodes
  * @param method The method
  */
 private void refreshCallersCallees(
     List<String> callerNames,
     List<String> calleeNames,
     List<CallTreeNode> frameRootNodes,
     String method) {
   for (CallTreeNode frameNode : frameRootNodes) {
     String parentFrameName = frameNode.getParent().getName();
     String frameName = frameNode.getName();
     if (parentFrameName.equals(method)) {
       calleeNames.add(frameName);
     }
     if (frameName.equals(method)) {
       callerNames.add(parentFrameName);
     }
     refreshCallersCallees(callerNames, calleeNames, frameNode.getChildren(), method);
   }
 }
  @Ignore
  @Test
  public void executionTime() {
    SpanAlign root = makeSpanAlign(START_TIME, 10);
    CallTree callTree = new SpanCallTree(root);
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 0, 1, 8));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 1, 2, 4));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 2, 3, 3));
    callTree.add(4, makeSpanAlign(root.getSpanBo(), SYNC, (short) 3, 4, 2, -1, 1));

    SpanAlign rpc = makeSpanAlign(START_TIME + 10, 5);
    CallTree rpcTree = new SpanCallTree(rpc);
    rpcTree.add(1, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 0, 1, 4));
    rpcTree.add(2, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 1, 2, 3));
    rpcTree.add(3, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 2, 3, 2));
    rpcTree.add(4, makeSpanAlign(rpc.getSpanBo(), SYNC, (short) 3, 4, 1));
    callTree.add(rpcTree);

    CallTree asyncTree = new SpanAsyncCallTree(root);
    asyncTree.add(1, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 0, 5, 4, 1, -1));
    asyncTree.add(2, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 1, 6, 3, 1, -1));
    asyncTree.add(3, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 2, 7, 2, 1, -1));
    asyncTree.add(4, makeSpanAlign(root.getSpanBo(), ASYNC, (short) 3, 8, 1, 1, -1));
    callTree.add(asyncTree);

    callTree.add(5, makeSpanAlign(root.getSpanBo(), SYNC, (short) 4, 5, 1));
    callTree.add(2, makeSpanAlign(root.getSpanBo(), SYNC, (short) 5, 6, 3));
    callTree.add(3, makeSpanAlign(root.getSpanBo(), SYNC, (short) 6, 7, 1));
    callTree.add(-1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 7, 8, 1));
    callTree.add(1, makeSpanAlign(root.getSpanBo(), SYNC, (short) 8, 9, 1));

    CallTreeIterator iterator = callTree.iterator();
    // assertEquals(5, iterator.size());

    System.out.println("executionTime");
    while (iterator.hasNext()) {
      CallTreeNode node = iterator.next();
      SpanAlign align = node.getValue();
      for (int i = 0; i <= align.getDepth(); i++) {
        System.out.print("#");
      }
      System.out.println(" : executionTime=" + align.getExecutionMilliseconds());
      assertEquals(1, align.getExecutionMilliseconds());
    }
  }
  /**
   * Gets the thread corresponding to the given node.
   *
   * @param callersCalleesMethod The tree node
   * @return The thread
   */
  private String getThread(IMethodNode callersCalleesMethod) {
    if (focusTarget != null) {
      return focusTarget.getThread();
    }

    if (callersCalleesMethod != null) {
      return callersCalleesMethod.getThread();
    }
    return null;
  }
  /**
   * Gets the CPU dump string.
   *
   * @param runtime The runtime
   * @param mainClass The main class
   * @param arguments The arguments
   * @return The CPU dump string
   */
  protected String getCpuDumpString(String runtime, String mainClass, String arguments) {

    // get date and time
    Date currentDate = new Date();
    String date = new SimpleDateFormat("yyyy/MM/dd").format(currentDate); // $NON-NLS-1$
    String time = new SimpleDateFormat("HH:mm:ss").format(currentDate); // $NON-NLS-1$

    StringBuffer buffer = new StringBuffer();
    buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); // $NON-NLS-1$
    buffer.append("<?JvmMonitor version=\""); // $NON-NLS-1$
    buffer.append(AGENT_VERSION);
    buffer.append("\"?>\n"); // $NON-NLS-1$

    buffer
        .append("<cpu-profile date=\"")
        .append(date)
        .append(' ') // $NON-NLS-1$
        .append(time)
        .append("\" "); // $NON-NLS-1$
    buffer.append("runtime=\"").append(runtime).append("\" "); // $NON-NLS-1$ //$NON-NLS-2$
    buffer.append("mainClass=\"").append(mainClass).append("\" "); // $NON-NLS-1$ //$NON-NLS-2$
    buffer.append("arguments=\"").append(arguments).append("\">\n"); // $NON-NLS-1$ //$NON-NLS-2$

    for (ThreadNode<CallTreeNode> node : callTreeThreads) {
      buffer
          .append("\t<thread name=\"")
          .append(node.getName())
          .append("\">\n"); // $NON-NLS-1$ //$NON-NLS-2$
      for (CallTreeNode frameNode : node.getChildren()) {
        frameNode.dump(buffer, 2);
      }
      buffer.append("\t</thread>\n"); // $NON-NLS-1$
    }
    buffer.append("</cpu-profile>"); // $NON-NLS-1$

    return buffer.toString();
  }
  /**
   * Adds the focused hot spot nodes.
   *
   * @param frame The frame node
   */
  private void addFocusedHotSpotNodes(ICallTreeNode frame) {
    String methodName = frame.getName();
    MethodNode node = new MethodNode(this, methodName, null);
    node.incrementCount(frame.getInvocationCount());
    node.incrementTime(frame.getSelfTime());
    focusedHotSpotRoots.put(methodName, node);

    for (CallTreeNode child : ((CallTreeNode) frame).getChildren()) {
      methodName = child.getName();
      if (focusedHotSpotRoots.containsKey(methodName)) {
        node = focusedHotSpotRoots.get(methodName);
        node.incrementCount(child.getInvocationCount());
        node.incrementTime(child.getSelfTime());
      } else {
        node = new MethodNode(this, methodName, null);
        node.incrementCount(child.getInvocationCount());
        node.incrementTime(child.getSelfTime());
        focusedHotSpotRoots.put(methodName, node);
      }
      addFocusedHotSpotNodes(child);
    }
  }
Beispiel #10
0
 /** Transforms this call tree into a loggable message. */
 public String getLogMessage(Split context) {
   context.getStopwatch().setAttribute(CallTreeCallback.ATTR_NAME_LAST, this);
   return "Call Tree:\r\n" + rootNode.toString();
 }