2014-08-14 20:53:37|?次阅读|上传:huigezrx【已有?条评论】发表评论

关键词:Unity3D, 游戏, 虚拟现实|来源:唯设编程网

Unity Manual > Advanced > Profiler



The Unity Profiler helps you to optimize your game. It reports for you how much time is spent in the various areas of your game. For example, it can report the percentage of time spent rendering, animating or in your game logic.


The profiler was added at Unity version 2.6. It is a Unity Pro feature. 分析器是加在Unity版本2.6里。这是一个Unity专业版的功能。

You can play your game in the Editor with Profiling on, and it will record performance data. The Profiler window then displays the data in a timeline, so you can see the frames or areas that spike (take more time) than others. By clicking anywhere in the timeline, the bottom section of the Profiler window will display detailed information for the selected frame.

你可以在编辑器里播放你的游戏并开启分析,它将记录性能数据。 分析器窗口然后在一个时间线里显示数据,因此可以看到框架或区域,峰值(需要更多的时间)超过其它的。按一下在任何时间,该事件分析器窗口底部的部分将显示选定的帧的详细信息。

Note that profiling has to instrument your code. This instrumentation has a small impact on the performance of your game. Typically this overhead is small enough to not affect the game framerate. When using profiling it is typical to consider only the ratio (or percentage) of time spent in certain areas. Also, to improve performance focus on those parts of the game that consume the most time. Compare profiling results before and after code changes and determine the improvements you measure. Sometimes changes you make to improve performance might have a negative effect on frame rate; unexpected consequences of code optimization should be expected.


Profiler window 分析器窗口

Profiler Controls 分析器控制


Profiler controls are in the toolbar at the top of the window. Use these to turn profiling on and off, navigate through profiled frames and so on. The transport controls are at the far right end of the toolbar. Note that when the game is running and the profiler is collecting data clicking on any of these transport controls will pause the game. The controls go to the first recorded frame, step one frame back, step one frame forward and go to the last frame respectively. The profiler does not keep all recorded frames, so the notion of the first frame should really be though of as the oldest frame that is still kept in memory. The "current" transport button causes the profile statistics window to display data collected in real-time.

分析器控制在工具栏在窗口的顶部。使用这些分析打开和关闭,浏览分析框架等。传输控制在工具栏的最右侧。请注意,当游戏运行和分析器正在收集数据,点击任何这些传输控制将暂停游戏。这些控制转到第一个记录的框架,一步一帧回来,一步一帧前进到各自的最后一帧。分析器并没有记录全部的帧,所以第一帧的概念真正应该作为最原始的框架仍然保存在内存中。 “当前”传输按钮导致统计分析窗口去显示的实时收集的数据。

Deep Profiling 深度分析

When you turn on Deep Profile, all your script code is profiled - that is, all function calls are recorded. This is useful to know where exactly time is spent in your game code.


Note that Deep Profiling incurs a very large overhead and uses a lot of memory, and as a result your game will run significantly slower while profiling. If you are using complex script code, Deep Profiling might not be possible at all. Deep profiling should work fast enough for small games with simple scripting. If you find that Deep Profiling for your entire game causes the frame rate to drop so much that the game barely runs, you should consider not using this approach, and instead use the approach described below. You may find deep profiling more helpful as you are designing your game and deciding how to best implement key features. Note that for large games deep profiling may cause Unity to run out of memory and so for this reason deep profiling may not be possible.


Manually profiling blocks of your script code will have a smaller overhead than using Deep Profiling. Use Profiler.BeginSample and Profiler.EndSample scripting functions to enable and disable profiling around sections of code.


Profiler Timeline 时间线分析器


The upper part of the Profiler window displays performance data over time. When you run a game, data is recorded each frame, and the history of the last several hundred frames is displayed. Clicking on a particular frame will display it's details in the lower part of the window. Different details are displayed depending on which timeline area is currently selected.

发表评论0条 】