Search Unity

Unity 5 - Profiler shows physics spikes on Android device.

Discussion in 'Physics' started by kimcgm, Apr 8, 2015.

  1. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Do you have a date its been there for ages, and as mentioned before ages ago, Android needs the boost..
     
  2. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    "post GDC" is the best I know. That has not changed.
     
  3. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    I just became aware of the issue. I'm using Unity 5.3.1f and I'm getting 30ms spikes ( 60ms, 120ms depending on frequency of the spikes) in Editor Profiler for Physics.Processing and not even using any 3D Physics in the scene.

    Does any fix exists? This still hasn't been fixed?

    At least give us the ability to disable 3D Physics in 2D games....
     
  4. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Have you read the 5.3.4 changelog and 5.3.2 changelogs?
     
  5. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    136
    Can you please enlighten me? Because I've been reading the release notes because I'm afraid to update Unity and I usually update when I see a worthwhile change that helps my project. But I can't find anything related to this. Maybe I don't know what I'm looking for?

    Cheers
     
  6. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    I'm not having these issues in 5.4.0b10, but I haven't tested in any meaningful way.
     
  7. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    137
    Wanted to say the physics spikes are being actively worked on. It is not a physics problem but a job system problem.
    There are job system fixes for the problem in the 5.4 beta release which you are welcome to try and give feedback about.
    Internally at Unity we are testing the job system fixes on the 5.3 release and so far it has fixed the problems found on the user projects we have tested it on.
    We are also actively performing automated stress and soak testing on the job system to validate the new code.
     
    ohbane and Stormy102 like this.
  8. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hi Jake,

    Whats the latest on this, are the fixes being added slowely?

    Cheers
     
    Stormy102 likes this.
  9. Bunky2K

    Bunky2K

    Joined:
    Jul 21, 2015
    Posts:
    1
    I am getting the same spikes in the profiler and also in windows builds (32 and 64 bit). I am not using physics at all.
    Often multiple spikes per second; i'm trying to tune character movement - impossible and frustrating with the spikes!

    Edit:
    Same problem with empty scene.
    Setup: i5 quad core, GTX 750Ti

    5.4.0 b16 resolves this issue for me.
     
    Last edited: Apr 28, 2016
    Stormy102 likes this.
  10. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    On my desktop PC with a Quad-Core i5 I don't experience any drops (fortunately) however switch to my i3 Dual-Core and even the Main Menu (which doesn't include a single rigidbody!) is unusable with spikes every 5-15 seconds. I have also noticed this in other games on Unity 5.3.x, such as Unturned. Really need a fix for this ASAP please UT, as it's making on-the-go development impossible, especially as I have such little time on my desktop.
     
  11. TommySKD

    TommySKD

    Joined:
    Jul 23, 2014
    Posts:
    25
    I encounter those annoying physics.processing spikes as well
    I tried 5.4.0 b16, now the spikes in Physics.processing are gone BUT instead you get even more enormous spikes in Rendering (something about jobs). And by enormous im talking 6-7 seconds "spikes" (while I was getting like ~1 second physics spikes before).
     
  12. GameArt

    GameArt

    Joined:
    Feb 24, 2013
    Posts:
    86
    I'm just going to post in here that the physics spikes are a big issue for us as well (on PC). They seem to randomly show up, some days everything is just fine- other days our physics graph matches the android ones posted. It does seem worse in editor vs packaged build.
     
    Stormy102 likes this.
  13. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    [Learning English]

    All day Debugging rendering Spikes since U3.4f 4.7f up to 5.4b for you! hope you like it!

    At first I found that the spicks are in Deferred Lighting only and they are not present in Forward rendering or Vertex Lit. But this fast conclusion is not the case as I explane later in the 2° theory.

    Using sync on off, Linear or Gamma, Dynamic or Static batching, Dx11 or Dx12 do not make any difference.


    A "Forward" (linear) rendering using U4.7 renders at 1111 frames per seconds and picks are at 1110 fps


    4.7.0.f1 1111fps min spick 1110fps quality: Fastest sync off

    Also vertex lit looks like has no problems at first result

    4.7.0.f1 1111fps min spick 1110fps quality: Fastest sync off

    We all start using Unity in Forward mode since is the default and then, when we are more advance users, we jump to Deferred. Passing from Forward rendering to Deferred Lighting you will notice there is more spicks oscillation in the frame rate up to the point spicks are half the fps average.

    4.7.0.f1 1111fps min spick 510fps quality: Fastest sync off

    So if you have an average of 40 fps the spikes will be close to 20.
    Since in editor there is lag if you try vertex Lit, Forward or Deferred there is no difference. But if you try it in a build & run game you will look to the difference. All test must be done in build & run version outside the editor.

    All the test from Unity 3 up to Unity 5.4:

    I Just Build Game Empty Scene that includes one directional light and a Main Camera rendering Sky box.

    The build game renders in full screen. In my example I'm using Windows 10, i7 16Gb, SSD, Ati7970, render quality: Fastest, sync off and I put 1000 frames per second as minimum target.

    Vertex Lit
    3.4.0.f1 1111fps min spick 1110fps
    4.7.0.f1 1111fps min spick 1110fps

    Forward Rendering
    3.4.0.f1 1111fps min spick 1110fps
    4.7.0.f1 1111fps min spick 1110fps
    5.4.0.b17 1111fps min spick 1110fps

    Deferred Lighting
    3.4.0.f1 1111fps min spick 200fps <-----------<<<
    4.7.0.f1 1110fps min spick 506fps
    5.3.4.f1 1100fps min spick 622fps
    5.4.0.b17 1050fps min spick 633fps

    Other test in Unity 4.7
    4.7.0.f1 1110fps min spick 506fps Use Direct 11 (true)
    4.7.0.f1 1110fps min spick 544fps Use Direct 11 (false)
    4.7.0.f1 1110fps min spick 526fps Direct11(f) StaticBatching (f)
    4.7.0.f1 1110fps min spick 511fps Direct11(f) Static(f) Dynamic(f)

    All data is +-50fps

    DrictX11 is not the problem, nor the Dynamic or the Static batching.

    The problem is the big delta between the average fps and the fps spicks.

    I push for this, reporting this bug, since Unity 4.1 but was close because there is this thread follow by @MortenSkaaning. I know he is not rendering guru but there is a chance is not a rendering problem and not a physics problem. The physics problem Inherited visually from the rendering. But also rendering can Inherited from something else.

    A 2° theory: My machine is making 1111 fps maximum so is not posible to debug the problem over the 1111fps range. There is a chance that there is spikes at VetexLit and Forward. So I make a test Thousand of objects been render at the same time in the oldest Unity version.

    In Unity 3.4
    3.4.0.f5 0150fps min spick 100fps VertexLit
    3.4.0.f5 0140fps min spick 80fps Forward
    3.4.0.f5 0130fps min spick 74fps Deferred

    My personal Conclusion: The spicks are much more notable in Deferred than Vertex Lit and Forward but the problem can be outside the rendering code. I was not able to find the origen of it because there is no earlier Unity version than 3.4 . When you push Unity to the limite spikes became the main problem.

    The Script for the test: Since I'm a intermediate or beginner user I put here my code use for the test so you can improve it. I'm using Time.deltaTime hopping is accurate.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.  
    4. public class DebugMinFPS : MonoBehaviour {
    5.  
    6.     [Tooltip("Minimum amount of frame per speed that will trigger the GUI (FPS spikes) value")]
    7.     public float
    8.         minFrameRate = 1000f;// example 60 frames per second
    9.  
    10.     private float actualFPS, FpsSpike, FpsMinSpike = 1000000f;
    11.  
    12.  
    13.  
    14.  
    15.     void Update()
    16.     {
    17.         actualFPS = 1f / Time.deltaTime;    // 1 second divided the minimum 60fps = 0,0166... of a second
    18.  
    19.         // if the && Time.realtimeSinceStartup >= 3f
    20.         if (actualFPS < minFrameRate )
    21.         {          
    22.             FpsSpike = actualFPS;
    23.  
    24.             if (FpsSpike < FpsMinSpike)
    25.                 FpsMinSpike = FpsSpike;
    26.         }
    27.     }
    28.  
    29.     void OnGUI()
    30.     {
    31.         if (GUILayout.Button("QUIT"))
    32.             Application.Quit();
    33.  
    34.         GUILayout.Label("FPS actual:" + actualFPS);
    35.  
    36.         GUILayout.Label("FPS spikes:" + FpsSpike);
    37.         GUILayout.Label("Min spikes:" + FpsMinSpike);
    38.  
    39.         if (GUILayout.Button("RESET MIN"))      
    40.             FpsMinSpike = FpsSpike = actualFPS;
    41.  
    42.         // Delete starting spikes: Reset values after few seconds from start
    43.         if (Time.realtimeSinceStartup > 2f && Time.realtimeSinceStartup < 3f)      
    44.             FpsMinSpike = FpsSpike = actualFPS;      
    45.     }
    46. }



     
    Last edited: May 17, 2016
    MrEsquire likes this.
  14. traunay

    traunay

    Joined:
    Oct 24, 2013
    Posts:
    16
    Yeah it happened to my project as well, really a bummer since I can't answer what's going on here to my boss :(
    I'm still on 5.3.0f though
     
  15. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Screenshot (18).png
    Still finding the lack of Unity Tech/Q&A support extremely disappointing. This isn't just Android, it's PC too!!! This is running the realtime GI Day/Night cycle by Glen Rhodes and the Physics spike is CRAZY, especially when, looking at the inspector I don't have a single Rigidbody in my scene!!! If someone can show this is fixed in 5.4b, I don't care how unstable it is, I'm switching to it because going from 60fps one second to 0.1fps the next is really stopping effective development on-the-go.
     
  16. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Hi Morten is this spikes problem in the road map and where(alpha beta development, etc) how is call to track it and follow?
     
  17. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    They're not in the 5.4 betas.

    The 5.4 betas are probably more stable than 5.3. The whole point of betas being free now is because 5.3.x have all been buggy beta quality anyway, so the open betas of 5.4 will allow 5.4 to be stable.
     
    Last edited: May 21, 2016
    Stormy102 likes this.
  18. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Might as well upgrade then. I've heard a few people say it is fixed in 5.4b, some say it isnt. I guess i should just take the plunge.
     
  19. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Other spikes:
    "The source of the issue was Wifi...! Yes wifi, i have connected my device to my PC to profile my game but something weird happened which is that the profiler did start profiling via wifi but not USB!. I disabled wifi in my device and tried to profile again via USB and the magic did happen, i'm only getting an overhead of 7.04ms and lag disappeared!

    Seems like profiling via wifi isn't efficient and will not make good results..."

    from:
    http://answers.unity3d.com/questions/1041984/overhead-spike-of-462ms-when-profiling-on-android.html
     
  20. Para-bellum

    Para-bellum

    Joined:
    Aug 7, 2013
    Posts:
    3
    If you do not use physics and fixed update, try to set Fixed timestep = 1 (Edit->Project settings->Time)
     
  21. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    U 5.4.0.18b
    "timestep" or time In my case did not affect default Unity spikes problem.

    For debug purpose here is my new script. Sorry if my English is not good.
    Use it in build and run. Not in Editor.

    Screenshot.jpg

    Screen shot using Unity 5.4.18b, Win10, i7, ati7970 x2

    The Input "Stress Value" let you add job to the CPU. It reduce the frame per second average.
    The "Percentage Limite" input value let you debug the spikes. If the frame is lower than 10% the frame average then it print it in the "FPS spike" value.


    In an empty scene drag and drop this component script to a game object or camera.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.  
    4. /***********************************************************************
    5.  
    6.     Debuger for minimum frame per second spikes.
    7.     A debuging tool in "Build & Run" mode. Do not use it in Editor.
    8.  
    9.      1920 x 1200 Window, full screen, NoVsync.
    10.         U 3.4.0f  
    11.         U 4.7.0f  
    12.         U 5.2.3f  
    13.         U 5.3.2f      
    14.         U 5.4.18b
    15.  
    16.     In Older versions of Unity take out [Tooltip...]
    17.  
    18.     *******************************************************************/
    19.  
    20. public class DebugFPSmin : MonoBehaviour
    21. {
    22.     [Tooltip("Stress the CPU to achieve a FPS average (Frames Per Second)")]
    23.     public string stressStringInput = "1";  
    24.  
    25.     [Tooltip("FPS (Frames Per Second) lower than this percentage % value will trigger to show the spike value.")]
    26.     public string spikesLimitePercentage = "10";
    27.  
    28.     [Tooltip("Minimum amount of time before starting showing FPS spikes (Frames Per Second)")]
    29.     public float
    30.         startAfterSeconds = 2f;
    31.  
    32.     [Tooltip("How many frames is needed to make a FPS average (Frames Per Second)")]
    33.     public int
    34.         fPSAverage = 100;
    35.  
    36.  
    37.     private float j, Fps, percentageSpikeLimite, FpsSpikesLimite, percentSpikeLimite, stressValue, minimumFrameTime, FpsSpike, FpsMinSpike = 1000000f;
    38.     private float fpsTotData, fpsAverageData;
    39.     private float[] fps;
    40.  
    41.  
    42.  
    43.  
    44.     void Start ()
    45.     {
    46.         fps = new float[fPSAverage];
    47.         percentSpikeLimite = percentageSpikeLimite / 100f;
    48.     }
    49.  
    50.  
    51.  
    52.  
    53.     void Update ()
    54.     {
    55.         CalculateFPS_Average();
    56.  
    57.         JobStress();
    58.  
    59.         CalculateFPS_Spikes();              
    60.     }
    61.  
    62.  
    63.  
    64.  
    65.     // print information on screen
    66.     void OnGUI ()
    67.     {
    68.         using (var horizontalScope = new GUILayout.HorizontalScope("box"))
    69.         {
    70.             GUILayout.Label("Stress value:");
    71.             stressStringInput = GUILayout.TextField(stressStringInput, 6);
    72.         }
    73.         stressValue = ToFloat(stressStringInput);
    74.  
    75.         //GUILayout.Label ("FPS actual:" + Fps);
    76.         GUILayout.Label ("FPS average is: " + fpsAverageData);
    77.         GUILayout.Label ("FPS spikes are: " + FpsSpike);
    78.         GUILayout.Label ("Min spikes was: " + FpsMinSpike);
    79.  
    80.         if (GUILayout.Button("RESET MINIMUM"))
    81.             FpsMinSpike = 1f / Time.deltaTime;
    82.  
    83.         using (var horizontalScope = new GUILayout.HorizontalScope("box"))
    84.         {
    85.             GUILayout.Label("Percentage Limite");
    86.             spikesLimitePercentage = GUILayout.TextField(spikesLimitePercentage, 3);
    87.         }
    88.         percentageSpikeLimite = ToFloat(spikesLimitePercentage);
    89.         percentSpikeLimite = percentageSpikeLimite / 100f;
    90.  
    91.         GUILayout.Label(" ");// make space
    92.         if (GUILayout.Button("EXIT"))
    93.             Application.Quit();
    94.     }
    95.  
    96.  
    97.  
    98.    
    99.  
    100.     private void CalculateFPS_Average()
    101.     {
    102.         Fps = 1f / Time.deltaTime;
    103.  
    104.         for (int i = (fps.Length - 1); i > -1; i--)
    105.         {
    106.             //print("Frame Number " + i + " is fps: " + fps[i].ToString());
    107.  
    108.             if ( i == 0 )
    109.             {
    110.                 fps[0] = Fps;
    111.             } else
    112.             {
    113.                 fps[i] = fps[i - 1];
    114.             }          
    115.  
    116.             fpsTotData = fpsTotData + fps[i];
    117.  
    118.         }
    119.         fpsAverageData = fpsTotData / (1.0f * fps.Length); // make the average (fast convertion of length int to float)
    120.         fpsTotData = 0f;
    121.     }
    122.  
    123.  
    124.  
    125.  
    126.     private void CalculateFPS_Spikes()
    127.     {
    128.         if (Time.realtimeSinceStartup > startAfterSeconds)
    129.         {
    130.            
    131.             FpsSpikesLimite = fpsAverageData - (fpsAverageData * percentSpikeLimite); // spikes smaller than 10% lower the fps average (or percentageSpikesLimite value)
    132.             minimumFrameTime = 1f / FpsSpikesLimite;
    133.  
    134.             if (Time.deltaTime >= minimumFrameTime)
    135.             {
    136.  
    137.                 FpsSpike = Fps;
    138.  
    139.                 if (FpsSpike < FpsMinSpike)
    140.                     FpsMinSpike = FpsSpike;
    141.             }
    142.         }
    143.     }
    144.  
    145.  
    146.  
    147.  
    148.     private void JobStress()
    149.     {
    150.         while (j < stressValue)
    151.         {
    152.             j = j + 0.00001f;
    153.             Fps = 1f / Time.deltaTime;
    154.  
    155.             // Hhile Loop Exit Fuse Cap: Is this while loop taking too long?
    156.             if (Fps < 5f)
    157.             {
    158.                 // if takes longer than 5fps cap then exit the while loop              
    159.                 stressStringInput = "1";    // reset the stress cap value
    160.                 j = stressValue + 1f;       //  go out from the while loop
    161.             }
    162.         }
    163.  
    164.         j = 0f;
    165.     }
    166.  
    167.  
    168.  
    169.  
    170.     private float ToFloat(string stringValue)
    171.     {
    172.         float result = 0f;
    173.         float.TryParse(stringValue, out result);
    174.         return result;
    175.     }
    176. }


     
  22. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    This line in the Unity 5.4 beta looks like it solves the issue where PhysX processing is being done without a single rigidbody in the scene:
    Good enough reason for me to upgrade.
     
  23. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Well after scouring the Unity 5.4b19 patch notes and seeing these lines, I think that I'm gonna upgrade:
    Looks promising.
     
  24. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Windows 10 , i7 , 7970x2

    U 5.4.018b

    Screenshot 5.4.0b18.jpg


    U 5.4.019b
    Screenshot 5.4.0b19.jpg
     
  25. Sokharev

    Sokharev

    Joined:
    Oct 10, 2013
    Posts:
    7
    Hello, i've fixed Physics.Processing "strange spikes" at windows 10 with

    start /affinity 1 mySuperGame.exe -batchmode. Spikes is gone and "average cpu load" lowered from 2.2% to 0.8%.
     
    Stormy102 likes this.
  26. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    GDC gone, whats the latest?
     
    Stormy102 likes this.
  27. MortenSkaaning

    MortenSkaaning

    Joined:
    Jan 16, 2015
    Posts:
    120
    Hi,

    The fixes are public in 5.3.5p3 and 5.4b21.

    Regards,
    Morten
     
    Stormy102, AlanMattano and MrEsquire like this.
  28. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    The facts prove:

    Rendering spikes over 100fps [good for VR]. Rendering spikes drop only 15%.
    Also Unity increase in CPU performance from 5.6 to 5.8.

    Windows 10 , i7 , 7970x2

    U 5.3.5 f1
    Unity 5.3.5f1.jpg



    U 5.4.022b
    Unity 5.4.22b.jpg

    All data is +-5 frames per second.

    Thanks Morten Skaaning and the rendering team! Hope that I was helpful pushing here with my little english.

    PS:If is possible add a warming in the build to preventing Unity beta to return triggering deep spikes.
     
    MrEsquire and Stormy102 like this.
  29. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    @MortenSkaaning I'm seeing some performance improvements, but this issue is STILL present :( The FPS still drops to 0.1-1FPS without a single rigidbody in my main menu screen.
    CPU: Intel Core i3-5157U Dual-Core @ 2.5GHz
    RAM: 8GB
    GPU: Intel Iris Graphics 6100
    Unity 5.3.5p5
     
  30. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    LagIssues.PNG
    Actually, now the ParticleSystem appears to be my issue. No more physics issues. Thanks @MortenSkaaning
     
  31. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    I don't really get this :( StillGotPhysicsIssuesSomehow.PNG
    Still got issues... But I can definitely say they're much reduced on the main menu at least...
     
  32. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,712
    Hey man, if you have time can you try beta 23 and 5.3.5 patch 4.. Big pain installing things i know more curiosy
     
    Stormy102 likes this.
  33. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    I'm on 5.3.5p5 :(
     
  34. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    If you play in editor threre are spikes, but If you make a final build (without Profiler) there are chances that you do not has this issue.
     
    Stormy102 likes this.
  35. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Building on my laptop takes 40 min :( So I either wait, get a new laptop or put up with it. It appears that now ParticleSystem.WaitingForJob is causing most of the issues now - hopefully 5.4 will rectify this.
     
  36. liuyang61

    liuyang61

    Joined:
    Nov 25, 2013
    Posts:
    3
    I updated NVidia driver (which includes physX update) and restarted Windows. Problem was gone. on 5.3.5f1
     
  37. Ziherl

    Ziherl

    Joined:
    Apr 30, 2016
    Posts:
    1
    The problem persists for me on 5.3.5f1 when running scene on an Android device. I have therefore upgraded to 5.4.0f2, where the problem seems to be gone. In debug mode (in 5.4.0f2) there are still frequent spikes of "Unaccounted" (as seen in the attached image), which slow down the framerate, but there are no problems in non-debug mode, so I guess those "Unaccounted" spikes can be ignored in the debug profiling.
     

    Attached Files:

  38. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Any updates on this ?
    is it fixed in the latest 5.4 release ?
    - is there any patch for 5.2 ?

    Thanks
     
  39. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    137
    I do not think the problem will be fixed in 5.2.

    The specific problem I know about which contributed to the above reported problems are fixed in 5.4. Without profiling your specific problem I can't say that your specific problem is fixed e.g. you might have found something new.

    Can you give me some more details on what you project is doing or which systems it is using in Unity
     
    Last edited: Nov 26, 2016
  40. Ali_V_Quest

    Ali_V_Quest

    Joined:
    Aug 2, 2015
    Posts:
    138
    Thanks for the help, will test it in unity 5.4 & report more info when available
     
  41. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Just wanted to point out that on 5.4.4 this still occurs pretty intensely for me.
    Anyone know if this is legit fixed in 5.5? I'm trying to avoid upgrading to it because of many other issues.
     
  42. JakeTurner

    JakeTurner

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    137
    Can you get a screenshot of the profiler window with the Timeline mode activated to show the threads at the point when you get the spikes. Without knowing what is causing your spike very hard to know if it is fixed in 5.5.

    Also what is your project doing? 2D or 3D, intensive rendering, lots of physics, graphics jobs? Any more info would be helpful.
     
  43. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    @JakeTurner Making test I discover that moving the mouse the frame rate drops 2% and also triggers spikes under 25% the average frame rate.

    Unity 5.5.1f1 and Widows 10 ( cpu i7 good video card )

    U 5.5.1 f1 Rendering path default
    upload_2017-2-22_12-54-53.png

    U 5.4.3 f1 Deferred
    upload_2017-2-22_12-54-14.png


    U 5.4.3 f1 Forward
    upload_2017-2-22_12-53-50.png

    Ps: In this new tests all the stress value are lower than before. The reason for that can be a GPU driver update.

    Tray to disable your antivirus.

    Here is my Unity 5.5.1 test debugging spikes.
    Use my tool to replicate minimum frame rate stress test:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3.  
    4. /***********************************************************************
    5.     Debuger for minimum frame per second spikes.
    6.     If you are looking spikes that not go under 20 percent your average FPS,
    7.     this tool will tell you how low are your minimum frame rate spikes.
    8.     A debugging tool in "Build & Run" mode. Do not use it in Editor.
    9.  
    10.     same spikes can be trigger by antivirus itself or other open tasks
    11.  
    12.     Using 5.5 and Windows.
    13.     Open a new clean Unity Project for making this test.
    14.     Go to Edite --> Project Settings --> Quality
    15.         Select Fantastic
    16.         from V Sync Count select Don't Sync
    17.     Go to Edit --> Project Settings --> Player
    18.         Other settings, Rendering, Color space to Linear.
    19.     Save the Project
    20.     Go to the main camera, for the clear flag choose Solid Colour
    21.         Drag&drop this script DebugFPSmin to the main camera.
    22.     Delete the "Directional light" from the Hierarchy
    23.     Save the scene name "Minimum FPS Spikes".
    24.     Go to "Lighting" window, select the "Scene" tab.
    25.         Disable Precomputed Realtime
    26.         Disable Baked GI
    27.         Disable Auto Build and press Build to build the light map.
    28.         Close Lighting window.
    29.     Save the scene one more time.
    30.     Go to File --> Build Settings
    31.         Press "Add Open Scene" button
    32.         Disable if is enable the Development toggle.
    33.         Choose your target and build it. example "FPS Spikes U551"
    34.     Close Unity.
    35.     Launch and run this new build scene. At game start configuration
    36.         Disable Windowed (go full screen)
    37.         and select resolution: your maximum resolution
    38.         in graphics quality Fantastic
    39.         Play
    40.     In the game add stress value to look reducing the FPS.
    41.         Reset will reset the minimum
    42.         percentage limite triggers the spikes when FPS are low under that % percerntage value.
    43.          if you put 10% and your FPS are 100, each time FPS go under 90 will pop up.
    44.  
    45.  
    46.  
    47.      1920 x 1200 Window, full screen, NoVsync.
    48.         U 3.4.0f
    49.         U 4.7.0f
    50.         U 5.2.3f
    51.         U 5.3.2f
    52.         U 5.4.18b
    53.         U 5.5.1f
    54.     In Older versions of Unity take out [Tooltip...]
    55.  
    56.     *******************************************************************/
    57.  
    58. public class DebugFPSmin : MonoBehaviour
    59. {
    60.     [Tooltip("Stress the CPU to achieve a FPS average (Frames Per Second)")]
    61.     public string stressStringInput = "1";
    62.  
    63.     [Tooltip("FPS (Frames Per Second) lower than this percentage % value will trigger to show the spike value.")]
    64.     public string spikesLimitePercentage = "10";
    65.  
    66.     [Tooltip("Minimum amount of time before starting showing FPS spikes (Frames Per Second)")]
    67.     public float
    68.         startAfterSeconds = 2f;
    69.  
    70.     [Tooltip("How many frames is needed to make a FPS average (Frames Per Second)")]
    71.     public int
    72.         fPSAverage = 100;
    73.  
    74.  
    75.     private float j, Fps, percentageSpikeLimite, FpsSpikesLimite, percentSpikeLimite, stressValue, minimumFrameTime, FpsSpike, FpsMinSpike = 1000000f;
    76.     private float fpsTotData, fpsAverageData;
    77.     private float[] fps;
    78.  
    79.  
    80.  
    81.  
    82.     void Start()
    83.     {
    84.         fps = new float[fPSAverage];
    85.         percentSpikeLimite = percentageSpikeLimite / 100f;
    86.     }
    87.  
    88.  
    89.  
    90.  
    91.     void Update()
    92.     {
    93.         CalculateFPS_Average();
    94.  
    95.         JobStress();
    96.  
    97.         CalculateFPS_Spikes();
    98.     }
    99.  
    100.  
    101.  
    102.  
    103.     // print information on screen
    104.     void OnGUI()
    105.     {
    106.         using (var horizontalScope = new GUILayout.HorizontalScope("box"))
    107.         {
    108.             GUILayout.Label("Stress value:");
    109.             stressStringInput = GUILayout.TextField(stressStringInput, 6);
    110.         }
    111.         stressValue = ToFloat(stressStringInput);
    112.  
    113.         //GUILayout.Label ("FPS actual:" + Fps);
    114.         GUILayout.Label("FPS average is: " + fpsAverageData);
    115.         GUILayout.Label("FPS spikes are: " + FpsSpike);
    116.         GUILayout.Label("Min spikes was: " + FpsMinSpike);
    117.  
    118.         if (GUILayout.Button("RESET MINIMUM"))
    119.             FpsMinSpike = 1f / Time.deltaTime;
    120.  
    121.         using (var horizontalScope = new GUILayout.HorizontalScope("box"))
    122.         {
    123.             GUILayout.Label("Percentage Limite");
    124.             spikesLimitePercentage = GUILayout.TextField(spikesLimitePercentage, 3);
    125.         }
    126.         percentageSpikeLimite = ToFloat(spikesLimitePercentage);
    127.         percentSpikeLimite = percentageSpikeLimite / 100f;
    128.  
    129.         GUILayout.Label(" ");// make space
    130.         if (GUILayout.Button("EXIT"))
    131.             Application.Quit();
    132.     }
    133.  
    134.  
    135.  
    136.  
    137.  
    138.     private void CalculateFPS_Average()
    139.     {
    140.         Fps = 1f / Time.deltaTime;
    141.  
    142.         for (int i = (fps.Length - 1); i > -1; i--)
    143.         {
    144.             //print("Frame Number " + i + " is fps: " + fps[i].ToString());
    145.  
    146.             if (i == 0)
    147.             {
    148.                 fps[0] = Fps;
    149.             }
    150.             else
    151.             {
    152.                 fps[i] = fps[i - 1];
    153.             }
    154.  
    155.             fpsTotData = fpsTotData + fps[i];
    156.  
    157.         }
    158.         fpsAverageData = fpsTotData / (1.0f * fps.Length); // make the average (fast convertion of length int to float)
    159.         fpsTotData = 0f;
    160.     }
    161.  
    162.  
    163.  
    164.  
    165.     private void CalculateFPS_Spikes()
    166.     {
    167.         if (Time.realtimeSinceStartup > startAfterSeconds)
    168.         {
    169.  
    170.             FpsSpikesLimite = fpsAverageData - (fpsAverageData * percentSpikeLimite); // spikes smaller than 10% lower the fps average (or percentageSpikesLimite value)
    171.             minimumFrameTime = 1f / FpsSpikesLimite;
    172.  
    173.             if (Time.deltaTime >= minimumFrameTime)
    174.             {
    175.  
    176.                 FpsSpike = Fps;
    177.  
    178.                 if (FpsSpike < FpsMinSpike)
    179.                     FpsMinSpike = FpsSpike;
    180.             }
    181.         }
    182.     }
    183.  
    184.  
    185.  
    186.  
    187.     private void JobStress()
    188.     {
    189.         while (j < stressValue)
    190.         {
    191.             j = j + 0.00001f;
    192.             Fps = 1f / Time.deltaTime;
    193.  
    194.             // Hhile Loop Exit Fuse Cap: Is this while loop taking too long?
    195.             if (Fps < 5f)
    196.             {
    197.                 // if takes longer than 5fps cap then exit the while loop        
    198.                 stressStringInput = "1";    // reset the stress cap value
    199.                 j = stressValue + 1f;       //  go out from the while loop
    200.             }
    201.         }
    202.  
    203.         j = 0f;
    204.     }
    205.  
    206.  
    207.  
    208.  
    209.     private float ToFloat(string stringValue)
    210.     {
    211.         float result = 0f;
    212.         float.TryParse(stringValue, out result);
    213.         return result;
    214.     }
    215. }
    216.  
     
    Last edited: Feb 22, 2017
  44. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501