您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 广告经营 > Unity3D性能消耗分析器
分析器(仅专业版)Profiler(Proonly)Date:2012-02-2504:56TheUnityProfilerhelpsyoutooptimizeyourgame.Itreportsforyouhowmuchtimeisspentinthevariousareasofyourgame.Forexample,itcanreportthepercentageoftimespentrendering,animatingorinyourgamelogic.Unity分析器可以帮助你优化你的游戏。它为您报告在你的游戏的各个领域所花费的时间。例如,它可以报告渲染、动画或在你的游戏逻辑花费时间的百分比。YoucanplayyourgameintheEditorwithProfilingon,anditwillrecordperformancedata.TheProfilerwindowthendisplaysthedatainatimeline,soyoucanseetheframesorareasthatspike(takemoretime)thanothers.Byclickinganywhereinthetimeline,thebottomsectionoftheProfilerwindowwilldisplaydetailedinformationfortheselectedframe.在编辑器中,你可以将你的游戏在分析器运行着的状态下运行,它会记录性能数据。分析器窗口,在时间轴上显示数据,所以你可以看到帧或区域峰值(比其他需要更多的时间)。在时间轴中的任何地方按一下,分析器窗口的底部区域会显示选定的帧的详细信息。Notethatprofilinghastoinstrumentyourcode.Thisinstrumentationhasasmallimpactontheperformanceofyourgame.Typicallythisoverheadissmallenoughtonotaffectthegameframerate.Whenusingprofilingitistypicaltoconsideronlytheratio(orpercentage)oftimespentincertainareas.Also,toimproveperformancefocusonthosepartsofthegamethatconsumethemosttime.Compareprofilingresultsbeforeandaftercodechangesanddeterminetheimprovementsyoumeasure.Sometimeschangesyoumaketoimproveperformancemighthaveanegativeeffectonframerate;unexpectedconsequencesofcodeoptimizationshouldbeexpected.请注意,分析时必须检测你的代码。这检测会对你的游戏性能有小小影响。通常情况下,这种开销是足够小,不会影响游戏的帧率。当使用分析时,它是典型的考虑时间花费在某些领域的比例(或百分比)。此外,为了提高性能,重点在游戏消耗的时间最多的那些部分。代码更改前后比较分析结果,并确定您测量的改进。有时,您所做的更改来提高性能,可能对帧速率有负面影响;应预计代码优化的意外的后果。ProfilerwindowAttachingtoUnityplayers附加到Unity播放器Toprofileyourgamerunningonanotherdeviceoraplayerrunningonanothercomputer,itispossibletoconnecttheeditortothatotherplayer.ThedropdownActiveProfilerwillshowallplayersrunningonthelocalnetwork.TheseplayersareidentifiedbyplayertypeandthehostnamerunningtheplayeriPhonePlayer(TomsiPhone).Tobeabletoconnecttoaplayer,theplayermustbelaunchedwiththeDevelopmentBuildcheckboxfoundintheBuildSettingsdialog.FromhereitisalsopossibletotickacheckboxtomaketheEditorandPlayerAutoconnectatstartup.要分析你的游戏运行在其他设备上或者在另一台计算机上运行的播放器,可以连接编辑器到其他播放器。ActiveProfiler下拉菜单显示在本地网络上运行的所有播放器。这些播放器通过播放器的类型和运行播放器的主机名iPhonePlayer(TomsiPhone)被识别。要能够连接到一个播放器,播放器必须在BuildSettings对话框中找到DevelopmentBuild复选框勾上的情况下打包生成。从这里也可以勾选一个复选框,使编辑器和播放器在启动时自动连接。ProfilerControls分析器控件Profilercontrolsareinthetoolbaratthetopofthewindow.Usethesetoturnprofilingonandoff,navigatethroughprofiledframesandsoon.Thetransportcontrolsareatthefarrightendofthetoolbar.Notethatwhenthegameisrunningandtheprofileriscollectingdataclickingonanyofthesetransportcontrolswillpausethegame.Thecontrolsgotothefirstrecordedframe,steponeframeback,steponeframeforwardandgotothelastframerespectively.Theprofilerdoesnotkeepallrecordedframes,sothenotionofthefirstframeshouldreallybethoughofastheoldestframethatisstillkeptinmemory.Thecurrenttransportbuttoncausestheprofilestatisticswindowtodisplaydatacollectedinreal-time.TheActiveProfilerpopupmenuallowsyoutoselectwhetherprofilingshouldbedoneintheeditororaseparateplayer(forexample,agamerunningonanattachediOSdevice).分析器控件在窗口顶部的工具栏。使用这些控件打开和关闭分析,浏览分析好的帧等。传输控件在工具栏的最右端。请注意,当游戏运行、分析器收集数据时,点击任何这些传输控件(那两个小箭头)将暂停游戏。控件转到记录的第一帧,一步一帧向前(左箭头),一步一帧向后(右箭头),分别去到最后一帧。分析器不保留所有记录的帧,因此第一帧的概念,事实上应该是仍然保存在内存中的最旧的一帧。current按钮会使得分析统计窗口显示实时采集的数据。激活分析器(ActiveProfiler)弹出菜单让你选择是否应在编辑器或一个或独立播放器进行分析(例如,一个游戏运行在iOS设备)。DeepProfiling深度分析WhenyouturnonDeepProfile,allyourscriptcodeisprofiled-thatis,allfunctioncallsarerecorded.Thisisusefultoknowwhereexactlytimeisspentinyourgamecode.当你打开深度分析(DeepProfile),所有脚本代码将被分析-也就是说,所有的函数调用被记录。知道确切在你的游戏代码中花费的时间,这是有用的。NotethatDeepProfilingincursaverylargeoverheadandusesalotofmemory,andasaresultyourgamewillrunsignificantlyslowerwhileprofiling.Ifyouareusingcomplexscriptcode,DeepProfilingmightnotbepossibleatall.Deepprofilingshouldworkfastenoughforsmallgameswithsimplescripting.IfyoufindthatDeepProfilingforyourentiregamecausestheframeratetodropsomuchthatthegamebarelyruns,youshouldconsidernotusingthisapproach,andinsteadusetheapproachdescribedbelow.Youmayfinddeepprofilingmorehelpfulasyouaredesigningyourgameanddecidinghowtobestimplementkeyfeatures.NotethatforlargegamesdeepprofilingmaycauseUnitytorunoutofmemoryandsoforthisreasondeepprofilingmaynotbepossible.注意深度分析(DeepProfiling)会造成非常大的开销,并使用大量的内存,结果你的游戏在分析同时运行明显变慢。如果您使用的是复杂的脚本代码,深度分析可能不会完全有效。深度分析为使用简单的脚本的小游戏工作足够快。如果您发现您的整个游戏在深度分析时运行,导致帧速率下降很多,以至于游戏几乎不能运行,你应该考虑不采用这种方法,而是使用下面描述的方法。您可能会发现深度分析更有利于设计你的游戏,并确定如何最好地实现关键特性。注意深度分析,对于大型游戏可能会导致Unity耗尽内存,基于这个原因,深度分析未必有效。ManuallyprofilingblocksofyourscriptcodewillhaveasmalleroverheadthanusingDeepProfiling.UseProfiler.BeginSampleandProfiler.EndSamplescriptingfunctionstoenableanddisableprofilingaroundsectionsofcode.手动分析脚本代码块比使用深度分析产生更小的开销。使用Profiler.BeginSample和Profiler.EndSample函数,启用和禁用分析代码段(从Profiler.BeginSample到Profiler.EndSample间的代码)。ViewSyncTime查看SyncTimeWhenrunningatafixedframerateorrunninginsyncwiththeverticalblank,UnityrecordsthewaitingtimeinWaitForTargetFPS.Bydefaultthisamountoftimeisnotshownintheprofiler.Toviewhowmuchtimeisspentwaiting,youcantoggleViewSyncTime.Thisisalsoameasureofhowmuchheadroomyouhavebefore
本文标题:Unity3D性能消耗分析器
链接地址:https://www.777doc.com/doc-7034929 .html