Package com.tnsai.thread
Class ThreadUsage
java.lang.Object
com.tnsai.thread.ThreadUsage
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSnapshot for serialization. -
Constructor Summary
ConstructorsConstructorDescriptionThreadUsage(long inputTokens, long outputTokens, int toolCalls, int messageCount) Create from a snapshot (for recovery). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInputTokens(long tokens) voidaddOutputTokens(long tokens) voidaddToolCalls(int count) intGet elapsed time (excluding paused duration).longintlonggetQuotaViolation(ResourceQuota quota) Get reason for quota violation, or null if within quota.intGet total wall clock time since start.longvoidvoidvoidbooleanisWithinQuota(ResourceQuota quota) Check against quota.voidMark thread as paused.voidMark thread as resumed.snapshot()Create a snapshot for checkpointing.toString()
-
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
-
getElapsedTime
Get elapsed time (excluding paused 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
Check against quota. -
getQuotaViolation
Get reason for quota violation, or null if within quota. -
snapshot
Create a snapshot for checkpointing. -
toString
-