Search Unity

Resolved How to measure time used from start App-> to finished rendering entities

Discussion in 'Graphics for ECS' started by Haneferd, Apr 18, 2021.

  1. Haneferd

    Haneferd

    Joined:
    Feb 3, 2018
    Posts:
    36
    Hi.
    I am trying to "time" the startup time from starting an application, till it has finished rendered all the entities.

    I have tried using UnityEngine.Time.realtimeSinceStartup, but I suspect that might not be right when initializing from either Entities or MonoBehaviour. At least when I use parallel processing.

    When spawning using MonoBehaviour, I have put this code in LateUpdate:

    Code (CSharp):
    1.  
    2.     {
    3.         if (!once)
    4.         {
    5.             Debug.Log("Time since startup: " + UnityEngine.Time.realtimeSinceStartup);
    6.             once = true;
    7.         }
    8.     }
    It returns one result:
    Time since startup: 0.8476899)


    But when trying the other option, and spawning from Entities, using the same code snip in OnStopRunning() , it returns two results (Make sense, since it is scheduled in parallel)

    Time since startup: 0.8806602
    Time since startup: 0.9899601


    So, my question is basically, What is the best way to measure time it takes for an app/program ,when using either MonoBehaviour or Entity (System), to spawn a large number of entities?

    Is there a finished rendering method somewhere I have not found yet?

    I might just spawn everything and then make som movement and check time when one of the entities collide. That will probably give me the result, but I suspect there are an easier method...
     
    Last edited: Apr 18, 2021
  2. apkdev

    apkdev

    Joined:
    Dec 12, 2015
    Posts:
    284
    I'm not sure what you mean by rendering here - do you mean when the entities (eg. a subscene) has finished loading? (Rendering typically refers to drawing entities on the screen, which happens every frame).

    In general I think I'd measure these things separately:
    1. App startup time until an empty scene loads
    2. Time to load your specific scene

    Measuring startup time seems like the more complicated part. If I were you, I'd try making a build that loads an empty scene and immidiately quits, and measure the time externally using some shell script.

    Measuring scene load time is easier because you can do it directly in Unity. ECS complicates things because subscenes load asynchronously. I do scene loading in a coroutine and use a piece of code similar to this to wait for the subscenes to finish loading:
    Code (CSharp):
    1. foreach (var scene in FindObjectsOfType<SubScene>())
    2. {
    3.     var query = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(typeof(LocalToWorld), typeof(SceneSection));
    4.     query.SetSharedComponentFilter(new SceneSection { SceneGUID = scene.SceneGUID });
    5.     yield return new WaitWhile(() => query.IsEmpty);
    6. }
    (Note that this assumes that there's objects with LocalToWorld in the subscene, so it could fail if your subscene is actually empty. I haven't found any better API to do this, unfortunately)
     
    Haneferd likes this.
  3. Haneferd

    Haneferd

    Joined:
    Feb 3, 2018
    Posts:
    36
    Hi. Thank you for the answer. I ment the scene finished loading, so actually when everything is displayed.

    I also think you have solved my question with the suggestion of using a shell script with an imidiatly termination. I'll do that.

    I am onsly experimenting with one scene, but the scene loadning can also be handy to measure as I see it.

    Thanks again!
     
    apkdev likes this.