Unity Performance Analysis

Source: Internet
Author: User
Tags manual garbage collection memory usage thread class

The following are the ports used by the Unity Analyzer:

	Multicast port (multicastport): 54998
	listening Port (listenports): 55000-55511 multicast
	(unit test): 55512-56023

You should access these ports within the network node. That is, when the profiler is turned on in the Unity editor (editor), the device you are trying to analyze should see these ports on the machine. The first step

Unity relies on the CPU to handle skinning, batching, physics, user scripts, particles, and so on (for example, the SIMD portions of it (such as SSE on x86 or NEON on ARM) are highly optimized.

The GPU handles shaders, draw calls, and image effects. CPU or GPU bindings use an internal parser to detect CPU and GPU Ms Pareto analysis

Most questions (80%) is made up of several key reasons (20%) Caused by. Use the editor Profiler to get most of the problematic function calls and optimize them first. Make sure that you run the script only when necessary. Use Onbecamevisible/onbecameinvisible to disable inactive objects. If you do not need to use some scripts to run each frame, use a synergistic program.

Do some stuff every frame:
void Update () {
}

//do some stuff every 0.2 seconds:
IEnumerator Start () _ {
while (true) {
yield return new waitforseconds (0.2f);
   }
}
Use the. NET System.Threading.Thread class to put tedious computations into other threads. This allows you to run on multiple cores, but the Unity API does not guarantee thread safety. As a result, buffers are entered, output, read, and assigned on the main thread. CPU Performance Analysis User Code Analysis

Not all user code will appear in the parser (profiler). However, you can use Profiler.beginsample and profiler.endsample to have the parser display the required user code. GPU Performance Analysis

The Unity Editor (editor) parser is currently unable to display GPU data. We are working with the hardware manufacturer to display it in the editor Profiler first, together with the Tegra device. IOS IOS Tools Unity Internal parser (not editor). This shows the GPU time for the entire scene. PowerVR Pvrunisco Shader parser. See below. The Ios:xcode OpenGL ES driver Tool (Driver Instruments) displays only high-level information: Device utilization%-the total GPU time occupied by rendering.

>95% means that the application is bound to the GPU. Renderer utilization%-the GPU time occupied by drawing pixels. Tile utilization%-the GPU time occupied by processing vertices. Split Count-the number of times the frame splits when the vertex data does not match the allocated buffer.

PowerVR is a tiled-based delay renderer, so the GPU timing of each draw call cannot be obtained. However, you can use the Unity built-in parser (the parser that prints the results to the Xcode output) to get the GPU time for the entire scene. Currently, the Apple tool can only tell you how busy the GPU and its parts are, and does not provide you with accurate time-to-millisecond reporting.

The Pvrunisco provides the period of the entire shader and the approximate period of each line in that shader code. Windows and mac! But anyway, it will not exactly match the task that the Apple driver is performing. Still, it's a good alternative. Android Android Tools Adreno (Qualcomm) Nvperfhud (NVIDIA) Pvrtune, Pvrunisco (PowerVR)

In Tegra, NVIDIA provides tools that can run on Windows, OSX, and Linux systems, with performance that meets your needs, such as the GPU time of each draw call, the period of each shader, the forced 2x2 texture, and the empty view rectangle. Perfhud ES is difficult to be compatible with consumer devices, and you need to use the NVIDIA Development Board.

Qualcomm provides a performance-Adreno Profiler (used only on Windows), although it can only be used on Windows, but is compatible with consumer devices. It features time axis (Timeline) graphics, frame capture, frame debugging, API invocation, shader (Shader) parser, and real-time editing. graphics-related CPU performance analysis

The internal profiler provides a good overview of each module: the time-consuming batch processing efficiency of the OpenGL ES API skinning, animation, particle memory

It contains Unity memory and mono memory. Mono Memory

Mono memory handles script objects and wrappers for Unity objects (game objects, resources, components, and so on). The garbage collector (garbage Collector) cleans up space when the resource allocation does not match the available memory or is on a System.GC.Collect () call.

The memory is in a heap block. If memory cannot load data into the allocated block, more blocks can be allocated. The heap blocks are saved in Mono before the application is closed. In other words, Mono does not release any memory space for the OS (Unity 3.x). Once you have allocated a certain amount of memory, the system will reserve the memory for mono and cannot be used by the OS. Even when you release the memory, it will only be used within Mono and will not be used by the OS. The heap memory value in the Profiler (Profiler) will only increase, never decrease.

If the system cannot load new data into the allocated heap block, Mono invokes a "GC" and assigns a new heap block (for example, because of fragmentation).

Too many heap sections mean that Mono memory is exhausted (caused by fragmentation or heavy use of memory).

Use System.GC.GetTotalMemory to get the total Mono memory used.

Generally, we recommend that you use the smallest possible allocation. Unity Memory

Unity Memory handles resource (Asset) data (textures (textures), grids (Meshes), audio, animations (Animation), and so on), game objects (games object), and built-in engines (engine) (Rendering (Rend ering), particles (particles), Physics (Physics), etc.). Use Profiler.usedheapsize to get the total Unity memory used. Memory Mapping

There are currently no tools, but you can use the following methods. Unity Analyzer – Imperfect phased product, but a general understanding of its features will help you. It can be run on this device. The internal parser shows the used heap and the allocated heap – see mono memory. Displays the number of mono allocations per frame. Xcode Tools-IOS Xcode tool Activity Monitor (Instruments Activity Monitor) – Real Memory spatial column chart. Xcode tool Assignment (Instruments allocations) – Net assignment of created objects to active objects. VM Tracker (Tracker) Typically, textures are assigned IOKit labels. Grids are typically stored in VM allocations (Allocate). Make your own tools Findobjectsoftypeall (Type:type): object[] Findobjectsoftype (type:type): object[] Getruntimememorysize (o:o bject): int getmonoheapsize getmonousedsize profiler.beginsample/endsample– analyze Your own code unloadunusedassets (): AsyncOperation system.gc.gettotalmemory/profiler.usedheapsize Download Object reference file – cannot find it. One workaround is to find the scene references for the public variables.Memory InterruptWhen the garbage collector system cannot load new data into the allocated heap block, it begins to work. Do not use Ongui on mobile devices It will be called several times per frame and it will redraw this view. It creates a large number of memory allocation calls, which require a call to garbage collection (garbage Collection). Too fast to create/remove too many objects. This can lead to fragmentation. Use the editor Profiler to track memory activity. The internal profiler tracks mono memory activity. System.GC.Collect () There is an outage, you can use this. Net function. New memory allocation interrupts use pre-allocated reusable class instance lists to implement their own memory management scenarios. Do not allocate too much space to each frame, but cache it and pre-allocate fragmentation issues. Pre-allocating memory pools. Save a list of inactive game objects (gameobjects), reuse them instead of instantiating them (instantiating) and destroying them (destroying). Mono memory exhaustion Analysis memory activity – When the first memory page fills up. Do you really need so many game objects? A single memory page is not available. For local data, use structs rather than classes. The class is stored in the heap, and the struct is stored on the stack.

Class MyClass {public
int A, b, C;
}

struct MyStruct {public
int A, b, C;
}

void Update () {
//bad
//allocated on the heap, 'll be garbage collected later!
MyClass C = new MyClass ();

Good
//allocated on the stack, no GC going to happen!
MyStruct s = new MyStruct ();
}

Read the link to the relevant section of the manual understandingautomaticmemorymanagement.html Insufficient memory crashes

While the game should theoretically work well, there are times when the game may crash due to "out of memory". When this problem occurs, compare your regular game memory usage and the amount of memory allocated when the crash occurs. If the values are far apart, there is a memory spike. Potential causes include the loading of two large scenes at the same time – using an empty scene between two large scenes to fix the problem. Load additional scenes – clean up unused portions and maintain the amount of memory space. Loading a huge resource bundle into memory is loaded through the instantiation of the WWW or (a large number of) large objects, for example: textures that are not properly compressed (not for mobile devices). Enables the Get/set (Get/set) pixel texture. This requires the use of an uncompressed copy of the texture in memory. The runtime basically does not decompress textures loaded from jpeg/png. Marks the large MP3 file as uncompressed when loaded. Saving unused resources in the exception cache, such as static Monobehavior fields, causes the memory to not be cleaned up when the scene is changed. Original address: http://docs.manew.com/Manual/MobileProfiling.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.