Skip to main content

ProfilerMarkers Sample

A flock of cubes whose every frame phase shows up in the Profiler under its own name.

The flock simulation whose phases the markers measure.The flock simulation whose phases the markers measure.

The flock simulation whose phases the markers measure.

Open it​

  1. Import the sample: Tools → Aspid 🐍 → FastTools → Welcome → Samples → Import on ProfilerMarkers.
  2. Open Scenes/ProfilerMarkers.unity and Window → Analysis → Profiler, enter Play Mode and select a frame in the CPU module.
  3. In the Hierarchy view, expand PlayerLoop down to Flock.Update (22).

Try​

The markers under Flock.Update nest like the code; FlockSimulation.Steering.Agent has 120 calls for 120 agents.The markers under Flock.Update nest like the code; FlockSimulation.Steering.Agent has 120 calls for 120 agents.

The markers under Flock.Update nest like the code; FlockSimulation.Steering.Agent has 120 calls for 120 agents.

  1. The tree follows the using scopes. Nothing else sets the nesting:

    public void Step(float deltaTime, float neighborRadius, float maxSpeed)
    {
    using var _ = this.Marker();

    using (this.Marker().WithName("Steering"))
    ComputeSteering(neighborRadius);

    using (this.Marker().WithName("Integrate"))
    Integrate(deltaTime: deltaTime, maxSpeed: maxSpeed);
    }
  2. One marker per loop. FlockSimulation.Steering.Agent sits in the loop over the agents: one row, with Calls equal to the agent count.

  3. More agents. In Play Mode, set Count on Flock to 400: Calls becomes 400.

  4. Not only MonoBehaviour. FlockSimulation is a plain C# class. The marker in the local function CreateAgent takes the method's name, Flock.InitializeAgents (58), and shows up in the frame where Count changes.

  5. The line number in the name. Every name ends with the line of its call, FlockSimulation.Steering (37), so two markers in one method never share a name.

  6. Release builds. In a player build without Development Build the markers measure nothing.

Where to look​

FileShows
Scripts/FlockSimulation.csMethod, block and per-iteration markers in a plain class
Scripts/Flock.csA marker in a local function

Reference: ProfilerMarkers.