0
\$\begingroup\$

I'm working on a map generator, which is used in Awake(), so I couldn't see it in the profiler.

So I created a new scene, where right clicking generates the map.

Now I can see the generation process (Update method), but not the specific parts of it.

Only GC.Alloc-s, GC.Collect-s and Mono.JIT-s.

Why?

enter image description here

\$\endgroup\$
5
  • 2
    \$\begingroup\$ Did you remember to click the "Deep Profile" toggle at the top of the window? Or if deep profiling is too heavy for your case, did you add profiler markers to the sections you want to inspect? \$\endgroup\$
    – DMGregory
    Apr 8, 2020 at 13:14
  • \$\begingroup\$ Oh, I didn't know about those. Now I tried deep profiling once, but everything got thrown out of memory, applications closed, screen went black, etc. Should I try again, or this is an obvious sign, and not just bad luck? Instead of profile markers, I used stopwatches, but this seems pretty handy. Thanks! \$\endgroup\$
    – Tudvari
    Apr 8, 2020 at 15:42
  • 1
    \$\begingroup\$ I've never seen the symptoms you describe with the deep profiler. If it's reproducible, it may be worth logging as a bug report for Unity. \$\endgroup\$
    – DMGregory
    Apr 8, 2020 at 15:58
  • 1
    \$\begingroup\$ That said, if you've solved your problem, please feel free to document your solution as an Answer below. That way it can help other developers who find this thread. \$\endgroup\$
    – DMGregory
    Apr 8, 2020 at 16:07
  • \$\begingroup\$ It did again. My computer's 16 GB of RAM was full under a few seconds. And only Unity was open. Will send a report. \$\endgroup\$
    – Tudvari
    Apr 8, 2020 at 17:02

2 Answers 2

2
\$\begingroup\$

I would like to drop my trick for Deep Profile in addition to OP's answer. I also got thrown out of memory when using Deep profile.

What is problem?

The problem become clear if developer were to Deep Profile on logic-heavy part, that's happen in single frame, let's say, also in my case, map generation. Which has several O^2 or worse stuff that would result in calling over something in magnitude of 100,000 times. Deep Profile will try to document EVERY function calls (!) which can bring editor or your entire PC to its knee.

The screenshot below demonstrate what happen when I record only 1 frame that happen to contain very logic heavy stuffs.

Unity memory usage

Solution

The only workaround is to divide your logic-heavy part into coroutine, and have it run over several frames, so that profiler does not cough up in one go. Between it you could "Clear" profiler anytime and that will also release memory.

Convert your function into coroutine. Divide and conquer until you can isolate heaviest part that you want to profile or cause profiler to crash.

My trick here is to use Debug.LogError which will print error to console. If Console has Error Pause option on, editor will auto-pause, with the help of yield return null which jump out of coroutine and wait for next frame, effectively it will pause just before that code part will run. So you can easily press Step in editor to advance frame manually.

IEnumerator MapGeneration( )
{
    Debug.LogError( "Before part 1" );
    yield return null;
    /* Code part 1 here */

    Debug.LogError( "Before part 2" );
    yield return null;
    /* Code part 2 here */

    ... // And more, you get the idea

    // If there is subfunction that need to break down
    // You could also convert it to Coroutine too and call it this way
    yield return SubFunction( );
}
\$\endgroup\$
0
\$\begingroup\$

I had to turn on Deep Profile.

Also, if it's too heavy for you computer, then instead add profile markers to the sections you want to inspect.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Did the profile markers give you the visibility you needed? Any tips you can share on where you needed to add them could be helpful for other devs working with them for the first time. \$\endgroup\$
    – DMGregory
    Apr 8, 2020 at 17:18
  • \$\begingroup\$ By the time your answer arrived, I already solved it with stopwatches, so markers weren't needed. Next time I will use them, and write about them! :) \$\endgroup\$
    – Tudvari
    Apr 9, 2020 at 7:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .