Skip to content

Profile Module

The Profile Module provides real-time performance monitoring with visual graphs powered by Unity's ProfilerRecorder system. Track FPS, memory usage, and any Unity profiler metric to identify performance issues, memory leaks, and optimization opportunities.

Profile Module

By default, the Profile module displays:

  • FPS (Frames Per Second): Frame rate graph to identify performance drops
  • Main Thread Time: CPU time spent on the main thread
  • Render Thread Time: CPU time spent on rendering
  • GC Allocated Per Frame: Memory allocated per frame
  • Total Reserved Memory: Total memory reserved by Unity
  • Total Allocated Memory: Total memory currently allocated

Adding Performance Metrics

To add a new performance metric, use the AddProfileStat method.

Available Profiler Stats

Unity's Profiler system provides hundreds of metrics. Here are some commonly used ones:

Rendering Stats

csharp
// Drawing statistics
ProfilerCategory.Render, "Draw Calls Count"
ProfilerCategory.Render, "SetPass Calls Count"
ProfilerCategory.Render, "Batches Count"
ProfilerCategory.Render, "Triangles Count"
ProfilerCategory.Render, "Vertices Count"

// Camera statistics
ProfilerCategory.Render, "Camera.Render"
ProfilerCategory.Render, "Shadows.Draw"

Memory Stats

csharp
ProfilerCategory.Memory, "Total Allocated Memory"
ProfilerCategory.Memory, "Total Reserved Memory"
ProfilerCategory.Memory, "GC Allocated Per Frame"
ProfilerCategory.Memory, "Texture Memory"
ProfilerCategory.Memory, "Mesh Memory"

Physics Stats

csharp
ProfilerCategory.Physics, "Physics.Processing"
ProfilerCategory.Physics, "Physics.Simulate"
ProfilerCategory.Physics, "Active Rigidbodies"
ProfilerCategory.Physics, "Active Colliders"

Audio Stats

csharp
ProfilerCategory.Audio, "Audio.Update"
ProfilerCategory.Audio, "Audio.FixedUpdate"

For a complete list of available profiler markers and counters, see:

Custom Profiler Stats

If you're tracking a custom metric, you can add it to the Profile module as you would any other built in metric.

Creating Custom Stats

csharp
using Unity.Profiling;
using UnityEngine;

public class GameMetrics : MonoBehaviour
{
    // Define custom counters
    private static readonly ProfilerCounterValue<int> _enemyCount =
        new ProfilerCounterValue<int>(
            ProfilerCategory.Scripts,
            "Enemy Count",
            ProfilerMarkerDataUnit.Count
        );

    private static readonly ProfilerCounterValue<float> _playerHealth =
        new ProfilerCounterValue<float>(
            ProfilerCategory.Scripts,
            "Player Health",
            ProfilerMarkerDataUnit.Undefined
        );

    void Start()
    {
        // Add custom stats to Profile module
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Scripts,
            statName: "Enemy Count",
            title: "Enemies",
            suffix: "count",
            minBound: 0,
            maxBound: 100
        );

        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Scripts,
            statName: "Player Health",
            title: "Health",
            suffix: "hp",
            minBound: 0,
            maxBound: 100
        );
    }

    void Update()
    {
        // Update counter values
        var enemies = FindObjectsOfType<Enemy>();
        _enemyCount.Value = enemies.Length;

        var player = FindObjectOfType<Player>();
        if (player != null)
            _playerHealth.Value = player.Health;
    }
}

Profiler Markers

Track execution time of specific code sections:

csharp
using Unity.Profiling;
using UnityEngine;

public class AIController : MonoBehaviour
{
    private static readonly ProfilerMarker _updateAIMarker =
        new ProfilerMarker("AI.Update");

    private static readonly ProfilerMarker _pathfindingMarker =
        new ProfilerMarker("AI.Pathfinding");

    void Start()
    {
        // Add markers to Profile module
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Scripts,
            statName: "AI.Update",
            title: "AI Update Time",
            suffix: "ms",
            minBound: 0,
            maxBound: 10
        );

        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Scripts,
            statName: "AI.Pathfinding",
            title: "Pathfinding Time",
            suffix: "ms",
            minBound: 0,
            maxBound: 5
        );
    }

    void Update()
    {
        using (_updateAIMarker.Auto())
        {
            // AI update logic
            UpdateVision();
            UpdateDecisions();

            using (_pathfindingMarker.Auto())
            {
                // Pathfinding logic
                CalculatePath();
            }
        }
    }

    void UpdateVision() { /* ... */ }
    void UpdateDecisions() { /* ... */ }
    void CalculatePath() { /* ... */ }
}

API

The Profile module API (IProfileModule) provides programmatic access to add and remove custom performance metrics. Access it via Debby.Profile.

AddProfileStat

Adds a new performance metric from Unity's Profiler system.

csharp
void AddProfileStat(
    ProfilerCategory category,
    string statName,
    string title = null,
    string suffix = null,
    float minBound = -1,
    float maxBound = -1,
    float downsampleMagnitude = 1,
    GraphType graphType = GraphType.Line
)

Parameters:

  • category: Unity ProfilerCategory (e.g., ProfilerCategory.Render, ProfilerCategory.Memory)
  • statName: Name of the profiler marker/counter
  • title (optional): Display name in UI (defaults to statName)
  • suffix (optional): Unit suffix (e.g., "ms", "MB", "fps")
  • minBound: Minimum Y-axis value (-1 for automatic)
  • maxBound: Maximum Y-axis value (-1 for automatic)
  • downsampleMagnitude: Divider for the stat value (e.g., 1048576 to convert bytes to MB)
  • graphType: Type of graph visualization (Line, Area, or Bars)

Example:

csharp
using Debology.Debby;
using Unity.Profiling;
using UnityEngine;

public class CustomProfileStats : MonoBehaviour
{
    void Start()
    {
        // Add draw calls counter
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Render,
            statName: "Draw Calls Count",
            title: "Draw Calls",
            suffix: "calls",
            minBound: 0,
            maxBound: 500,
            graphType: GraphType.Line
        );

        // Add SetPass calls
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Render,
            statName: "SetPass Calls Count",
            title: "SetPass Calls",
            suffix: "calls",
            minBound: 0,
            maxBound: 200
        );

        // Add batch count
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Render,
            statName: "Batches Count",
            title: "Batches",
            suffix: "batches",
            minBound: 0,
            maxBound: 300
        );

        // Add triangle count (downsampled to thousands)
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Render,
            statName: "Triangles Count",
            title: "Triangles",
            suffix: "k",
            minBound: 0,
            maxBound: 1000,
            downsampleMagnitude: 1000
        );

        // Add vertex count (downsampled to thousands)
        Debby.Profile.AddProfileStat(
            category: ProfilerCategory.Render,
            statName: "Vertices Count",
            title: "Vertices",
            suffix: "k",
            downsampleMagnitude: 1000
        );
    }
}

RemoveProfileStat

Removes a previously added performance metric from the display.

csharp
void RemoveProfileStat(ProfilerCategory category, string statName)

Parameters:

  • category: The category used when adding the stat
  • statName: The stat name used when adding

Open

Opens the Profile module in the Debby UI.

csharp
void Open()