Class ResourceStats

java.lang.Object
dev.engine.core.profiler.ResourceStats

public class ResourceStats extends Object
Tracks native resource lifecycle statistics: live totals and per-frame operation counters.

Each resource type is identified by a string key (e.g. "buffer", "texture"). New resource types can be added at any time — the first call to any record* method with an unknown key auto-registers it.

The tracker has two layers:

  • Live totals — absolute count of currently alive resources, never reset. Thread-safe (atomic integers).
  • Frame counters — per-frame create/destroy/use/update counts with a current/last frame model. Call newFrame() at the start of each frame to swap: current becomes last (readable by consumers), current resets to zero.

Operations tracked per frame:

  • created — new resources allocated this frame
  • destroyed — resources freed this frame (when deferred deletion actually runs)
  • used — resources bound/referenced for reading (e.g. texture sampled, buffer bound)
  • updated — resources written to (e.g. buffer upload, texture data update)
// Record operations during the frame:
resourceStats.recordCreate("buffer");
resourceStats.recordUpdate("buffer");   // wrote data into it
resourceStats.recordUse("texture");     // bound for sampling

// At frame start:
resourceStats.newFrame();

// Read completed previous frame:
int buffersCreated = resourceStats.lastFrameCreated("buffer");
int texturesUsed   = resourceStats.lastFrameUsed("texture");

// Live totals are always current:
int liveBuffers = resourceStats.liveCount("buffer");
  • Constructor Details

    • ResourceStats

      public ResourceStats()
  • Method Details

    • register

      public void register(String resourceType)
      Pre-registers a resource type. Optional — types are auto-registered on first use.
    • resourceTypes

      public Set<String> resourceTypes()
      Returns an unmodifiable view of all tracked resource type names.
    • recordCreate

      public void recordCreate(String resourceType)
      Records a resource creation. Increments live total and current frame created counter.
    • recordDestroy

      public void recordDestroy(String resourceType)
      Records a resource destruction. Decrements live total and increments current frame destroyed counter.
    • recordUse

      public void recordUse(String resourceType)
      Records a resource being used (bound/read) this frame.
    • recordUpdate

      public void recordUpdate(String resourceType)
      Records a resource being updated (written/uploaded) this frame.
    • newFrame

      public void newFrame()
      Swaps frame counters: current becomes last, current resets to zero. Call once at the start of each frame, before any record operations.
    • liveCount

      public int liveCount(String resourceType)
      Returns the current live count for the given resource type, or 0 if unknown.
    • totalLiveCount

      public int totalLiveCount()
      Returns the sum of all live resources across all tracked types.
    • lastFrameCreated

      public int lastFrameCreated(String resourceType)
    • lastFrameDestroyed

      public int lastFrameDestroyed(String resourceType)
    • lastFrameUsed

      public int lastFrameUsed(String resourceType)
    • lastFrameUpdated

      public int lastFrameUpdated(String resourceType)
    • totalLastFrameCreated

      public int totalLastFrameCreated()
    • totalLastFrameDestroyed

      public int totalLastFrameDestroyed()
    • totalLastFrameUsed

      public int totalLastFrameUsed()
    • totalLastFrameUpdated

      public int totalLastFrameUpdated()
    • currentFrameCreated

      public int currentFrameCreated(String resourceType)
    • currentFrameDestroyed

      public int currentFrameDestroyed(String resourceType)
    • currentFrameUsed

      public int currentFrameUsed(String resourceType)
    • currentFrameUpdated

      public int currentFrameUpdated(String resourceType)
    • toString

      public String toString()
      Overrides:
      toString in class Object