Search Unity

Get Results by Code from Performance Testing Extension

Discussion in 'Testing & Automation' started by Maeslezo, Mar 4, 2020.

  1. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    Hello,

    I have been playing around with Performance Testing Extension:
    https://blogs.unity3d.com/es/2018/09/25/performance-benchmarking-in-unity-how-to-get-started/
    https://docs.unity3d.com/Packages/com.unity.test-framework.performance@2.0/manual/index.html

    The framework is quite interesting and useful.

    But, can I somehow take the results to make a test with them?

    This code is from the example project:
    https://github.com/Unity-Technologies/XRAutomatedTests/releases
    Code (CSharp):
    1.     [PerformanceUnityTest]
    2.     public IEnumerator RealtimeLighting_Directional()
    3.     {
    4.         yield return SceneManager.LoadSceneAsync(realTimeLightingDirectionalTestSceneName, LoadSceneMode.Additive);
    5.  
    6.         SetActiveScene(realTimeLightingDirectionalTestSceneName);
    7.  
    8.         // Instantiate performance test object in scene
    9.         var renderPerformanceTest = SetupPerfTest<DynamicRenderPerformanceMonoBehaviourTest>();
    10.  
    11.         // allow time to settle before taking measurements
    12.         yield return new WaitForSecondsRealtime(SettleTimeSeconds);
    13.  
    14.         // use ProfilerMarkers API from Performance Test Extension
    15.         using (Measure.ProfilerMarkers(SamplerNames))
    16.         {
    17.             // Set CaptureMetrics flag to TRUE; let's start capturing metrics
    18.             renderPerformanceTest.component.CaptureMetrics = true;
    19.  
    20.             // Run the MonoBehaviour Test
    21.             yield return renderPerformanceTest;
    22.         }
    23.  
    24.         yield return SceneManager.UnloadSceneAsync(realTimeLightingDirectionalTestSceneName);
    25.     }


    For example, imagine I want a test that fails if the fps are below 45 fps

    I would like to do something like this:

    var minFps = Measure.GetSample("FPS").Min; //GetSample and Min don't exists, just for illustrating the idea
    Assert.GreaterOrEqual(45f, minFps);


    I know this information has to be somewhere, because it's printed in the log, probably by ProfilerMeasurement.Dispose
    The printed info is this:
    RealtimeLighting_Directional (5.444s)
    ---
    FPS None Median:60.31 Min:30.12 Max:7119.97 Avg:129.99 Std:702.53 Zeroes:0 SampleCount: 100 Sum: 12999.23
    Camera.Render Millisecond Median:2.12 Min:0.35 Max:5.21 Avg:2.66 Std:1.22 Zeroes:0 SampleCount: 100 Sum: 266.46
    Render.Mesh Millisecond Median:0.00 Min:0.00 Max:0.00 Avg:0.00 Std:0.00 Zeroes:1 SampleCount: 100 Sum: 0.22
    AppStartupTime 0.00 Millisecond
    ObjectCount 4.00 None
    Triangles 6996.00 None
    Vertices 2267.00 None

    ##performancetestresult:{"TestName":"DynamicScene_RenderPerfTests.RealtimeLighting_Directional","TestCategories":["Performance"],"TestVersion":"1","StartTime":1583332433780.76,"EndTime":1583332439204.07,"SampleGroups":[{"Definition":{"Name":"FPS","SampleUnit":8,"AggregationType":1,"Threshold":0.15,"IncreaseIsBetter":true,"Percentile":0.0,"FailOnBaseline":true},"Samples":[7119.9677734375,59.42738342285156,30.998443603515626,30.115285873413087,58.41385269165039,59.99976348876953,59.91980743408203,60.117000579833987,59.83802032470703,59.114871978759769,60.36117935180664,60.36221694946289,60.36221694946289,59.307796478271487,60.36221694946289,60.33833694458008,59.79517364501953,59.93209457397461,58.880653381347659,60.36117935180664,60.36325454711914,60.36117935180664,60.36221694946289,59.97001266479492,60.36117935180664,59.77071762084961,60.07890319824219,59.851295471191409,59.17171859741211,60.36117935180664,60.36325454711914,59.760528564453128,60.36221694946289,59.908546447753909,60.36117935180664,60.01618957519531,58.27796173095703,59.14377975463867,60.36221694946289,60.36221694946289,60.36221694946289,60.36117935180664,60.36325454711914,59.71779251098633,60.36117935180664,60.01310729980469,59.053157806396487,60.03982162475586,60.36117935180664,60.36221694946289,60.36221694946289,60.12215805053711,60.36117935180664,59.445518493652347,60.36221694946289,60.36325454711914,59.78498077392578,59.32686233520508,60.36221694946289,60.30720520019531,59.78905487060547,59.89728927612305,60.36117935180664,60.2202262878418,59.71168899536133,60.159278869628909,60.34975051879883,58.937049865722659,60.26575469970703,58.41190719604492,60.36221694946289,60.36325454711914,60.36117935180664,60.2481575012207,60.13555908203125,59.691368103027347,59.68425369262695,60.36014175415039,60.36325454711914,59.3288688659668,60.36221694946289,60.36117935180664,60.3206901550293,59.332881927490237,58.57579803466797,59.30078125,60.36221694946289,60.36221694946289,60.36221694946289,60.36221694946289,60.36117935180664,60.36325454711914,60.36325454711914,60.36221694946289,60.29476547241211,59.454586029052737,60.36221694946289,60.36325454711914,58.90141677856445,60.36117935180664],"Min":30.115285873413087,"Max":7119.9677734375,"Median":60.30720520019531,"Average":129.9922910499573,"StandardDeviation":702.5312405684915,"PercentileValue":0.0,"Sum":12999.229104995728,"Zeroes":0,"SampleCount":100},{"Definition":{"Name":"Camera.Render","SampleUnit":2,"AggregationType":1,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[2.119909,5.2106699999999999,2.1290329999999999,0.347283,3.435193,3.286072,2.084838,1.993598,3.420366,3.3234239999999999,1.9662259999999999,2.251637,2.112495,2.122475,3.420366,3.289209,2.0021519999999999,1.484934,3.5013419999999999,3.266969,2.115347,2.106508,3.4078209999999999,4.836015,2.3636909999999999,2.499411,4.960045,4.892469999999999,2.352286,2.514522,4.9346689999999999,4.834019,2.461204,2.481163,4.912999,4.94921,2.578105,2.527923,4.990838,4.891044,1.942275,2.403609,5.03874,4.956338,2.510531,1.427053,5.038169,4.964607,2.47489,2.4714679999999999,4.924119,4.890474,2.387641,2.540469,4.804366,4.717403,2.0509079999999999,2.0799909999999999,3.436619,1.649451,2.014982,2.028953,1.980197,3.3145849999999998,3.302895,2.02154,2.0375069999999999,2.108218,3.4668419999999999,3.4369039999999999,1.435037,1.5593519999999999,1.95197,1.842196,1.5174379999999999,1.6460299999999999,1.893519,1.8464729999999999,1.6072529999999999,1.557926,1.826514,1.835353,1.4070939999999999,1.645745,1.945697,1.891808,1.3820029999999999,1.4567059999999999,1.865862,1.8342129999999999,1.526562,1.4664009999999999,1.825089,1.768349,1.341516,1.475239,1.826514,1.7797539999999999,1.5134459999999999,1.19325],"Min":0.347283,"Max":5.2106699999999999,"Median":2.119909,"Average":2.664635339999998,"StandardDeviation":1.2201945561024786,"PercentileValue":0.0,"Sum":266.4635339999998,"Zeroes":0,"SampleCount":100},{"Definition":{"Name":"Render.Mesh","SampleUnit":2,"AggregationType":1,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[0.002851,0.001995,0.0025659999999999999,0.002851,0.002281,0.002281,0.002851,0.002281,0.002851,0.002281,0.002281,0.00171,0.002851,0.0025659999999999999,0.003136,0.001995,0.00171,0.002281,0.003421,0.0014249999999999999,0.002281,0.001995,0.0025659999999999999,0.0025659999999999999,0.0025659999999999999,0.0025659999999999999,0.001995,0.0014249999999999999,0.002281,0.001995,0.001995,0.0025659999999999999,0.003136,0.002281,0.001995,0.001995,0.002281,0.0025659999999999999,0.002281,0.002281,0.002281,0.002281,0.00171,0.00171,0.001995,0.001995,0.001995,0.001995,0.00171,0.002281,0.002851,0.002851,0.00171,0.00171,0.0014249999999999999,0.0025659999999999999,0.002281,0.0014249999999999999,0.002281,0.00114,0.0025659999999999999,0.001995,0.0025659999999999999,0.0025659999999999999,0.002281,0.0025659999999999999,0.002281,0.0025659999999999999,0.002281,0.001995,0.00171,0.001995,0.0025659999999999999,0.002281,0.002281,0.003136,0.0025659999999999999,0.002281,0.002851,0.001995,0.002281,0.002281,0.00171,0.0025659999999999999,0.0025659999999999999,0.0025659999999999999,0.001995,0.003136,0.00171,0.0014249999999999999,0.0025659999999999999,0.0025659999999999999,0.002281,0.001995,0.002281,0.001995,0.001995,0.00171,0.002281,0.0],"Min":0.0,"Max":0.003421,"Median":0.002281,"Average":0.002235020000000002,"StandardDeviation":0.00048690966266854867,"PercentileValue":0.0,"Sum":0.2235020000000002,"Zeroes":1,"SampleCount":100},{"Definition":{"Name":"AppStartupTime","SampleUnit":2,"AggregationType":3,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[0.0],"Min":0.0,"Max":0.0,"Median":0.0,"Average":0.0,"StandardDeviation":0.0,"PercentileValue":0.0,"Sum":0.0,"Zeroes":1,"SampleCount":1},{"Definition":{"Name":"ObjectCount","SampleUnit":8,"AggregationType":3,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[4.0],"Min":4.0,"Max":4.0,"Median":4.0,"Average":4.0,"StandardDeviation":0.0,"PercentileValue":0.0,"Sum":4.0,"Zeroes":0,"SampleCount":1},{"Definition":{"Name":"Triangles","SampleUnit":8,"AggregationType":3,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[6996.0],"Min":6996.0,"Max":6996.0,"Median":6996.0,"Average":6996.0,"StandardDeviation":0.0,"PercentileValue":0.0,"Sum":6996.0,"Zeroes":0,"SampleCount":1},{"Definition":{"Name":"Vertices","SampleUnit":8,"AggregationType":3,"Threshold":0.15,"IncreaseIsBetter":false,"Percentile":0.0,"FailOnBaseline":true},"Samples":[2267.0],"Min":2267.0,"Max":2267.0,"Median":2267.0,"Average":2267.0,"StandardDeviation":0.0,"PercentileValue":0.0,"Sum":2267.0,"Zeroes":0,"SampleCount":1}]}

    Thank you
     
  2. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    If someone want to do something like this:


    PerformanceTest info = PerformanceTest.Active;
    info.CalculateStatisticalValues();
    var fps = info.SampleGroups.Find(s => s.Name == "FPS");

    Assert.GreaterOrEqual(fps.Min, 60f);