# Profiling Issue

**URL:** https://discussions.unity.com/t/profiling-issue/1667705
**Category:** Profiling Tools
**Tags:** Profiling, Profile-Analyzer, CPU-Profiler, 2022.3-lts, Question, Build-Profiles
**Created:** [July 16, 2025, 12:38pm UTC](https://discussions.unity.com/t/profiling-issue/1667705 "2025-07-16T12:38:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![santosh\_unity244](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@santosh\_unity244](https://discussions.unity.com/u/santosh_unity244)
#### Post date: [July 16, 2025, 12:38pm UTC](https://discussions.unity.com/t/profiling-issue/1667705/1 "2025-07-16T12:38:56Z")

</div>

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 :

 ![Screenshot 2025-07-16 at 4.08.51 PM](https://europe1.discourse-cdn.com/unity/original/4X/1/e/0/1e0ed954e61b9aaddd6808b50cf3361b69109eb4.png)

Timeline :

 ![Screenshot 2025-07-16 at 3.15.26 PM](https://europe1.discourse-cdn.com/unity/original/4X/7/2/d/72dff51dac20c8e1691db71635d92d74244ac357.jpeg)

Main Thread :

 ![Screenshot 2025-07-16 at 5.57.19 PM](https://europe1.discourse-cdn.com/unity/original/4X/8/8/4/884f2c6e04f48175a82a9052700dc7b787fc384b.jpeg)

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

---

<div class="post-metadata">

### Author: ![CodeSmile](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/codesmile/32/82968_2.png) [@CodeSmile](https://discussions.unity.com/u/CodeSmile)
#### Post date: [July 16, 2025, 1:30pm UTC](https://discussions.unity.com/t/profiling-issue/1667705/2 "2025-07-16T13:30:12Z")

</div>

> [@santosh\_unity244](#):
>
> Dont know why is it happening on iOS phone and didnt see this pattern on android device.

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.

> [@santosh\_unity244](#):
>
> Gpu may be taking a lot of time here so render thread is blocked and so our main thread.

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):

> [@Graphics profiler GFX.WaitForCommands, What is does it mean?](https://discussions.unity.com/t/graphics-profiler-gfx-waitforcommands-what-is-does-it-mean/699539):
>
> I get some long frames when rendering on Android. On these long frames GFX.WaitForCommands() appears on the Rendering thread and I’m wondering what it is and why it might happen. The difference between a short and long frame is 6ms for rendering and 26ms for rendering. Any advice would be helpful. Profiler screenshot attached. Slow frame with lots of GFX.WaitForCommands() calls (the grey boxes down the bottom) Fast frame with a…

> [@WaitForTargetFPS on PlayerLoop after GPU is done, why?](https://discussions.unity.com/t/waitfortargetfps-on-playerloop-after-gpu-is-done-why/860817):
>
> Hi, With 1 mesh on the scene with unlit shader I get profiler output as pictured: I’m running this on iPhone 5s with frame rate set to 60FPS (2019.4.29f1). In the frame showing in the profiler there is a minor spike displayed (I see these all the time). If I understand the profiling documentation correctly there should be no reason for WaitForTargetFPS to still wait past 16.6ms (red arrow) on the PlayerLoop. So why is it? The green …

> [@Why Unity WaitForTargetFPS cost too much time?](https://discussions.unity.com/t/why-unity-waitfortargetfps-cost-too-much-time/323984):
>
> I am new on unity profiler.I publish my game on iphone13 and debug it with unity profiler. I set targetFrameRate 60, so one frame should cost 16.67ms. However I find that PlayerLoop cost 33.48ms and WaitForTargetFPS cost 27.09ms.Subtraction equals 6.39ms, far less then 16.67ms. I have checked the render thread and it is waiting all the time. So I am really confused about this. Why WaitForTargetFPS cost so much and without WaitForTargetFPS this frame can finish in 16.67ms? (I am not an English…

> [@Why WaitForTargetFPS takes so much CPU - when targteFPS = -1?](https://discussions.unity.com/t/why-waitfortargetfps-takes-so-much-cpu-when-targtefps-1/1507314):
>
> Here is a screenshot from my profiler analyze of my small 2d game: My question is why it takes so long and how to eliminate it. My TargetFrameRate is -1 as default. I questions like: [waitfortargetfps high cpu usage - Unity Engine - Unity Discussions](https://discussions.unity.com/t/waitfortargetfps-high-cpu-usage/707967)[unity - Massive CPU Usage by WaitForTargetFPS in the Profiler - Game Development Stack Exchange](https://gamedev.stackexchange.com/questions/124496/massive-cpu-usage-by-waitfortargetfps-in-the-profiler) But finally, I didn’t understand how to solve it and it take almost 50% of CPU… Render thread screenshot (of the same frame) if needed: …

---

<div class="post-metadata">

### Author: ![MartinTilo](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/martintilo/32/91392_2.png) [@MartinTilo](https://discussions.unity.com/u/MartinTilo)
#### Post date: [August 7, 2025, 10:42am UTC](https://discussions.unity.com/t/profiling-issue/1667705/4 "2025-08-07T10:42:14Z")

</div>

Have you tried profiling this with XCode Instruments?

---

<div class="post-metadata">

### Author: ![santosh\_unity244](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@santosh\_unity244](https://discussions.unity.com/u/santosh_unity244)
#### Post date: [August 8, 2025, 5:47am UTC](https://discussions.unity.com/t/profiling-issue/1667705/5 "2025-08-08T05:47:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![santosh\_unity244](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@santosh\_unity244](https://discussions.unity.com/u/santosh_unity244)
#### Post date: [August 8, 2025, 6:05am UTC](https://discussions.unity.com/t/profiling-issue/1667705/6 "2025-08-08T06:05:06Z")

</div>

@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.

> **[Detecting performance bottlenecks with Unity Frame Timing Manager](https://unity.com/blog/engine-platform/detecting-performance-bottlenecks-with-unity-frame-timing-manager)**
>
> Creating a standout experience that runs smoothly on a variety of devices and platforms can be extremely challenging. That’s why we continue to refine our tools for optimization across the board, such as our improved Frame Timing Manager. Read on to...

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 ?
