Class UsageStatistics

java.lang.Object
org.machanism.machai.ai.manager.UsageStatistics

public class UsageStatistics extends Object
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 Details

    • UsageStatistics

      public UsageStatistics()
      Creates a usage statistics registry instance.
  • Method Details

    • addUsage

      public static void addUsage(String modelId, Usage usage)
      Adds a single Usage record for a specific model identifier.
      Parameters:
      modelId - the model identifier, for example OpenAI:gpt-4o-mini
      usage - the usage entry to record
    • logUsage

      public static void logUsage()
      Logs usage summaries for every model currently present in the registry.
    • logUsageForModel

      public static void logUsageForModel(String modelId)
      Logs a summary of the aggregated Usage records for a specific model.
      Parameters:
      modelId - the model identifier, for example OpenAI:gpt-4o-mini
    • getUsageForModel

      public static List<Usage> getUsageForModel(String modelId)
      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

      public static Map<String,List<Usage>> 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