Profiling Issue

Hi, I am facing an issue where I dont know what is going wrong on profiler window. I am testing a game on iOS ( iphone-15) and sometimes i see a continuous lag pattern in my game, when it starts showing up it keeps on until i kill the app. Sometimes it runs well, no overheat issue.

I am attaching SS which shows : Main Thread, Render thread data

Render Thread :

Timeline :

Main Thread :

I cant do gpu profiling on editor.

Its kind of related to v-sync, I have set targetfps = 60 and even -1. still get same spike.
Gpu may be taking a lot of time here so render thread is blocked and so our main thread.

Render thread is stalled at:

Gfx.WaitForGfxCommandsFromMainThread (75ms)
→ Semaphore.WaitForSignal

Dont know why is it happening on iOS phone and didnt see this pattern on android device.
Can anyone help here

Just to rule out the usual suspect: background processes. Just like with desktop computers from time to time we ought to restart the device, particularly if there’s something inexplicable going on. It wouldn’t be the first time that after a reboot the issue went away.

And try profiling on another device to be sure this issue isn’t just on a specific device.

Don’t set targetFrameRate if your goal is to get 60 Hz because that’s what the device will render anyway. VsyncCount has no effect on mobile, vsync is always on.

Quite the opposite. The “wait for commands from main thread” would indicate that the main thread is stalling, it isn’t a GPU / rendering issue, the GPU is merely waiting and the main thread is WaitingForTargetFPS. That’s the keyword you should search for. It’s possible that the device is being throttled either due to excess heat or energy saving features, or just background processes.

See also these threads (there’s more):

Have you tried profiling this with XCode Instruments?

yes, I found the problem using xcode instruments and fixed it.
:slight_smile:

@MartinTilo, There is one thing i want to discuss,
I am doing profiling of the game through a script at run time on mobile device.
I am saving the raw data , per frame json on device when i stop profiling.

I am using ProfilerRecorder class to get a lot of data.
var gcMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, “GC Reserved Memory”); var mainThreadTimeRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Internal, “Main Thread”, 15);

I also used FrameTiming Manager method to collect data.

My observation is these 2 techniques gives different output about cpu and rendering and maybe more module. Difference i see in these data : like RenderThread , draw calls count, verts, tries count etc… I compared it with stat window and with profiler recorder class data.

so for now, i only used profilerrecorder class for data collection..

Another thing is :

{
Profiler.logFile = binaryLogPath;
Profiler.enabled = true;
Profiler.enableBinaryLog = true;

}

earlier i set Profiler.enabled = false; and did profiling. i was able to save the raw data locally but later on some cases or device, i didnt get the raw data.. dont know why ??

Then i did this : Profiler.enabled = true; and now i get the raw data every time .
and when i load the raw data on profiler window, i only see the data of cpu , no memory, audio, render , physics etc….

`if (baseProfiler.enableCpuGpuProfiling)
{
mainThreadRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Scripts, “Main Thread”);
renderThreadRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “CPU Render Thread Frame Time”);
gpuFrameTimeRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “GPU Frame Time”);
}

if (baseProfiler.enableMemoryProfiling)
{
gcAllocatedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, “GC Allocated In Frame”);
gcReservedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, “GC Reserved Memory”);
systemUsedMemoryRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Memory, “System Used Memory”);
}

if (baseProfiler.enableRenderProfiling)
{
drawCallsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “Draw Calls Count”);
trianglesRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “Triangles Count”);
verticesRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “Vertices Count”);
batchesRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, “Batches Count”);`

This is how i get data…
Do you know what could be the problem ?