예제 #1
0
  /**
   * Print all of the thread's information and stack traces.
   *
   * @param sb
   * @param info
   * @param indent
   */
  public static void appendThreadInfo(StringBuilder sb, ThreadInfo info, String indent) {
    boolean contention = threadBean.isThreadContentionMonitoringEnabled();

    if (info == null) {
      sb.append(indent).append("Inactive (perhaps exited while monitoring was done)\n");
      return;
    }
    String taskName = getTaskName(info.getThreadId(), info.getThreadName());
    sb.append(indent).append("Thread ").append(taskName).append(":\n");

    Thread.State state = info.getThreadState();
    sb.append(indent).append("  State: ").append(state).append("\n");
    sb.append(indent).append("  Blocked count: ").append(info.getBlockedCount()).append("\n");
    sb.append(indent).append("  Waited count: ").append(info.getWaitedCount()).append("\n");
    if (contention) {
      sb.append(indent).append("  Blocked time: " + info.getBlockedTime()).append("\n");
      sb.append(indent).append("  Waited time: " + info.getWaitedTime()).append("\n");
    }
    if (state == Thread.State.WAITING) {
      sb.append(indent).append("  Waiting on ").append(info.getLockName()).append("\n");
    } else if (state == Thread.State.BLOCKED) {
      sb.append(indent).append("  Blocked on ").append(info.getLockName()).append("\n");
      sb.append(indent)
          .append("  Blocked by ")
          .append(getTaskName(info.getLockOwnerId(), info.getLockOwnerName()))
          .append("\n");
    }
    sb.append(indent).append("  Stack:").append("\n");
    for (StackTraceElement frame : info.getStackTrace()) {
      sb.append(indent).append("    ").append(frame.toString()).append("\n");
    }
  }
예제 #2
0
 MyThreadInfo(long cpuTime, ThreadInfo info) {
   blockedCount = info.getBlockedCount();
   blockedTime = info.getBlockedTime();
   waitedCount = info.getWaitedCount();
   waitedTime = info.getWaitedTime();
   this.cpuTime = cpuTime;
   this.info = info;
 }
예제 #3
0
 void setDelta(long cpuTime, ThreadInfo info) {
   if (deltaDone) throw new IllegalStateException("setDelta already called once");
   blockedCount = info.getBlockedCount() - blockedCount;
   blockedTime = info.getBlockedTime() - blockedTime;
   waitedCount = info.getWaitedCount() - waitedCount;
   waitedTime = info.getWaitedTime() - waitedTime;
   this.cpuTime = cpuTime - this.cpuTime;
   deltaDone = true;
   this.info = info;
 }
예제 #4
0
 /**
  * {@inheritDoc}
  *
  * @see com.wily.introscope.agent.trace.ITracer#ITracer_startTrace(int,
  *     com.wily.introscope.agent.trace.InvocationData)
  */
 @Override
 public void ITracer_startTrace(int tracerIndex, InvocationData data) {
   final int currentIndex = reentrancyIndex.get().incrementAndGet();
   final ThreadInfo ti = TMX.getThreadInfo(Thread.currentThread().getId());
   waitCountBaselines.get().put(currentIndex, ti.getWaitedCount());
   blockCountBaselines.get().put(currentIndex, ti.getBlockedCount());
   if (timesEnabled) {
     waitTimeBaselines.get().put(currentIndex, ti.getWaitedTime());
     blockTimeBaselines.get().put(currentIndex, ti.getBlockedTime());
   }
 }
예제 #5
0
 /**
  * {@inheritDoc}
  *
  * @see com.wily.introscope.agent.trace.ITracer#ITracer_finishTrace(int,
  *     com.wily.introscope.agent.trace.InvocationData)
  */
 @Override
 public void ITracer_finishTrace(int tracerIndex, InvocationData data) {
   final int currentIndex = reentrancyIndex.get().decrementAndGet();
   try {
     final int priorIndex = currentIndex + 1;
     final ThreadInfo ti = TMX.getThreadInfo(Thread.currentThread().getId());
     long newWaitCount = ti.getWaitedCount();
     long newBlockCount = ti.getBlockedCount();
     long priorWaitCount = waitCountBaselines.get().remove(priorIndex);
     long priorBlockCount = blockCountBaselines.get().remove(priorIndex);
     if (priorWaitCount != NO_ENTRY && !waitCountAcc.IDataAccumulator_isShutOff()) {
       waitCountAcc.ILongAggregatingDataAccumulator_recordDataPoint(newWaitCount - priorWaitCount);
     }
     if (priorBlockCount != NO_ENTRY && !blockCountAcc.IDataAccumulator_isShutOff()) {
       blockCountAcc.ILongAggregatingDataAccumulator_recordDataPoint(
           newBlockCount - priorBlockCount);
     }
     if (timesEnabled) {
       long newWaitTime = ti.getWaitedTime();
       long newBlockTime = ti.getBlockedTime();
       long priorWaitTime = waitTimeBaselines.get().remove(priorIndex);
       long priorBlockTime = blockTimeBaselines.get().remove(priorIndex);
       if (priorWaitTime != NO_ENTRY && !waitTimeAcc.IDataAccumulator_isShutOff()) {
         waitTimeAcc.ILongAggregatingDataAccumulator_recordDataPoint(newWaitTime - priorWaitTime);
       }
       if (priorBlockTime != NO_ENTRY && !blockTimeAcc.IDataAccumulator_isShutOff()) {
         blockTimeAcc.ILongAggregatingDataAccumulator_recordDataPoint(
             newBlockTime - priorBlockTime);
       }
     }
   } finally {
     if (currentIndex < 1) {
       waitCountBaselines.remove();
       blockCountBaselines.remove();
       if (timesEnabled) {
         waitTimeBaselines.remove();
         blockTimeBaselines.remove();
       }
     }
     if (currentIndex < 0) {
       log.warn("Reentrancy Index Underrun:", currentIndex);
       reentrancyIndex.get().set(0);
     }
   }
 }
예제 #6
0
  /**
   * Formats the thread dump header for one thread.
   *
   * @param ti the ThreadInfo describing the thread
   * @return the formatted thread dump header
   */
  private static String getThreadDumpHeader(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
    sb.append(" Id=" + ti.getThreadId());
    sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) + " ns");
    sb.append(" usr="******" ns");
    sb.append(" blocked " + ti.getBlockedCount() + " for " + ti.getBlockedTime() + " ms");
    sb.append(" waited " + ti.getWaitedCount() + " for " + ti.getWaitedTime() + " ms");

    if (ti.isSuspended()) {
      sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
      sb.append(" (running in native)");
    }
    sb.append(CRLF);
    sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
    sb.append(CRLF);
    return sb.toString();
  }