Class ThreadUsage

java.lang.Object
com.tnsai.thread.ThreadUsage

public final class ThreadUsage extends Object
Tracks resource usage for an AgentThread.

Thread-safe counters for:

  • Token usage (input + output)
  • Tool call count
  • Elapsed time
  • Message count
Since:
0.0.2
  • Constructor Details

    • ThreadUsage

      public ThreadUsage()
    • ThreadUsage

      public ThreadUsage(long inputTokens, long outputTokens, int toolCalls, int messageCount)
      Create from a snapshot (for recovery).
  • Method Details

    • addInputTokens

      public void addInputTokens(long tokens)
    • addOutputTokens

      public void addOutputTokens(long tokens)
    • getInputTokens

      public long getInputTokens()
    • getOutputTokens

      public long getOutputTokens()
    • getTotalTokens

      public long getTotalTokens()
    • incrementToolCalls

      public void incrementToolCalls()
    • addToolCalls

      public void addToolCalls(int count)
    • getToolCalls

      public int getToolCalls()
    • incrementMessageCount

      public void incrementMessageCount()
    • getMessageCount

      public int getMessageCount()
    • incrementCheckpoints

      public void incrementCheckpoints()
    • getCheckpointCount

      public int getCheckpointCount()
    • getStartTime

      public Instant getStartTime()
    • getElapsedTime

      public Duration getElapsedTime()
      Get elapsed time (excluding paused duration).
    • getTotalTime

      public Duration getTotalTime()
      Get total wall clock time since start.
    • markPaused

      public void markPaused()
      Mark thread as paused.
    • markResumed

      public void markResumed()
      Mark thread as resumed.
    • isWithinQuota

      public boolean isWithinQuota(ResourceQuota quota)
      Check against quota.
    • getQuotaViolation

      public String getQuotaViolation(ResourceQuota quota)
      Get reason for quota violation, or null if within quota.
    • snapshot

      public ThreadUsage.Snapshot snapshot()
      Create a snapshot for checkpointing.
    • toString

      public String toString()
      Overrides:
      toString in class Object