Package org.machanism.machai.ai.manager
Class UsageStatistics
java.lang.Object
org.machanism.machai.ai.manager.UsageStatistics
Central registry for aggregated GenAI token-usage statistics.
Usage entries are grouped by model identifier and can later be logged or queried programmatically. All access to the internal storage is synchronized on the shared map instance.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a singleUsagerecord for a specific model identifier.Returns the aggregated usage map for all models.getUsageForModel(String modelId) Returns the aggregated usage entries for a specific model.static voidlogUsage()Logs usage summaries for every model currently present in the registry.static voidlogUsageForModel(String modelId) Logs a summary of the aggregatedUsagerecords for a specific model.
-
Constructor Details
-
UsageStatistics
public UsageStatistics()Creates a usage statistics registry instance.
-
-
Method Details
-
addUsage
Adds a singleUsagerecord for a specific model identifier.- Parameters:
modelId- the model identifier, for exampleOpenAI:gpt-4o-miniusage- the usage entry to record
-
logUsage
public static void logUsage()Logs usage summaries for every model currently present in the registry. -
logUsageForModel
Logs a summary of the aggregatedUsagerecords for a specific model.- Parameters:
modelId- the model identifier, for exampleOpenAI:gpt-4o-mini
-
getUsageForModel
Returns the aggregated usage entries for a specific model.A defensive copy is returned so callers can inspect the recorded values without modifying the internal registry state.
- Parameters:
modelId- the model identifier to query- Returns:
- a defensive copy of the recorded usage entries for the specified
model; never
null
-
getAllModelUsages
Returns the aggregated usage map for all models.The returned map is a shallow copy of the registry. The map instance itself can be modified by the caller without affecting the registry, but the nested usage lists remain shared references.
- Returns:
- a shallow copy of the model-to-usage-list registry
-