本文介绍了跟踪时间花费调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想我已经措辞我原来的问题错了,所以我在下面痛失下来,并改写正是我想要知道的,对于未来的读者。 ][ [ EDIT 2x ] I think I have worded my original question wrong, so I have scooted it down below and rewrote exactly what I am trying to get at, for future readers. ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~结果 [新的,有光泽,具有更好的措辞清楚的问题]结果 ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[ New, Shiny, Clear Question with Better Wording ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~我有一个运行了模拟/游戏架构一个循环。这个循环中有几个地方需要确定多少时间 - 在现实中 - 已经过去了,让这些特殊场所中的逻辑 - 特别是,渲染和更新 - 能够正常工作。它拥有的是一个固定时间步长的选项(未定[更新/渲染] 为假)还是没有。I have a loop that is running for a simulation / gaming framework. This loop has several places in it where it needs to ascertain how much time - in reality - has passed, so that the logic within these special places - specifically, Rendering and Updating - can work correctly. It has the option of being a Fixed Time Step (unfixed[update/render] is false) or not.基于如何当基于断点,调试在应用程序的任何点完成,就会出现问题,因为它使用一个秒表来计算出多少实时已过(用于物理和动画在一个现实的速度移动的目的,而不是许多帧计算机可以生产出)。The problem arises when Breakpoint-based Debugging is done in any point in the application, since it uses a stopwatch to figure out how much realtime has passed (for the purpose of physics and animation moving at a realistic speed, and not based on how many frames the computer can churn out).看起来(大约)这个样子,使用的 多秒表每个部件应用循环需要知道多少时间,因为这部分上次发生已经过去了的:It looks (roughly) like this, using multiple stopwatches for each 'part' of the application loop that needs to know how much time has passed since that 'part' last occurred:while ( RunningTheSimulation ) { /* ... Events and other fun awesome stuff */ TimeSpan updatedifference = new TimeSpan( updatestopwatch.ElapsedTicks ); if ( unfixedupdate || updatedifference > updateinterval ) { Time = new GameTime( updatedifference, new TimeSpan( gamestopwatch.ElapsedTicks ) ); Update( Time ); ++updatecount; updatestopwatch.Reset( ); updatestopwatch.Start( ); } TimeSpan renderdifference = new TimeSpan( renderstopwatch.ElapsedTicks ); if ( unfixedrender || renderdifference > renderinterval ) { Time = new GameTime( renderdifference, new TimeSpan( gamestopwatch.ElapsedTicks ) ); Render( Time ); ++rendercount; renderstopwatch.Reset( ); renderstopwatch.Start( ); }} 有关变量的一些信息:Some info about the variables: updatestopwatch 是的为外界所花费的update()函数时秒表, renderstopwatch 是一个秒表为渲染()函数之外花费的时间,以及renderstopwatch is a Stopwatch for the time spent outside the Render() function, and gamestopwatch 是的秒表为模拟/游戏本身的总耗时。当我在调试应用程序的任何地方,就会出现问题。由于秒表正在测量实时,模拟将完全由任何一种基于断点调试的揭去因为秒表会继续计时,无论我是否正在调试应用程序。我没有用秒表来测量性能:我用它们来跟踪更新的再发生之间的时间,渲染,和其他活动,如那些如上图所示。当我断点,分析和修复更新()一个错误,但随后的渲染()的时间是如此的彻底关闭,仿真结果的任何显示在脸上vengefully踢这得到非常令人沮丧。The problem arises when I debug anywhere in the application. Because the stopwatches are measuring realtime, the Simulation will be completely thrown off by any kind of Breakpoint-based debugging because the Stopwatches will keep counting time, whether or not I'm debugging the application. I am not using the Stopwatches to measure performance: I am using them to keep track of time between re-occurrences of Update, Render, and other events like the ones illustrated above. This gets extremely frustrating when I breakpoint and analyze and fix an error in Update(), but then the Render() time is so completely off that any display of the results of the simulation is vengefully kicked in the face.这是说,当我停止调试完全它显然不是一个问题,但我有很多的开发工作要做,我要进行调试的很长一段时间,所以只是假装这是不是不方便将无法正常工作,很遗憾。 = [That said, when I stop debugging entirely it's obviously not a problem, but I have a lot of development work to do and I'm going to be debugging for a long time, so just pretending that this isn't inconvenient won't work, unfortunately. =[我看了看性能计数器,但我似乎无法换我围绕如何让他们的头在我尝试上下文工作这样做:渲染和更新可以包含任意代码的任何金额(他们具体到任何模拟对这个,而环路上运行),这意味着我不能稳定做一个 PerformanceCounter.Increment()为循环的各个组件。I looked at Performance Counters, but I can't seem to wrap my head around how to get them to work in the context of what I'm trying to do: Render and Update can contain any amount of arbitrary code (they're specific to whatever simulation is running on top of this while loop), which means I can't steadily do a PerformanceCounter.Increment() for the individual components of the loop.我要保持周围戳系统.Diagnostics和其它.NET命名空间,但到目前为止,我已经打开了就如何公正忽略在空白附调试花费的时间...I'll keep poking around System.Diagnostics and other .NET namespaces, but so far I've turned up blanks on how to just "ignore" the time spent in the attached Debugger...任何人有任何意见或见解?Anyone have any ideas or insight? 更正拼写错误,并确保一切的格式是正确的。对于那个很抱歉。 ][ [ EDITS 5x ] Corrected misspellings and made sure the formatting on everything was correct. Sorry about that. ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [原创,不太清楚的问题]结果 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[ Original, less-clear question ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~我有一个恒定的循环在C#应用程序,这是我调试所有的时间运行。我目前使用的是秒表,但我可以用任何其他的机制来跟踪通过时间。当我做事情喜欢使用断点我的问题开始在这个循环(封闭在一个典型的,而(真){...} 地方:I have a constant loop running in a C# application, which I debug all the time. I am currently using a Stopwatch, but I could use any other mechanism to track the passing time. My problem begins when I do things like use Breakpoints somewhere during this loop (enclosed in a typical while (true) { ... }:if ( unfixedupdate || updatedifference > updateinterval ){ Time = new GameTime( updatedifference, new TimeSpan( gamestopwatch.ElapsedTicks ) ); Update( Time ); ++updatecount; updatestopwatch.Reset( ); updatestopwatch.Start( );}时的措施本身很好,但它可以测量实际的实时 - 包括的任何的时候,我。花了调试这意味着,如果我在 updatestopwatch.Reset闲逛了17秒(),这得到复合到我环, - 至少1重新运行该循环 - 我必须处理额外的时间,我在实际花费的时间分解为我所有的计算The time measures itself fine, but it measures actual real time - including any time I spent debugging. Which means if I'm poking around for 17 seconds after updatestopwatch.Reset(), this gets compounded onto my loop and - for at least 1 rerun of that loop - I have to deal with the extra time I spent in real time factoring into all of my calculations.有什么办法,我可以挂接到调试器知道什么时候它的冻结的应用,这样我就可以应对措施时,并相应地减去了吗?作为标记,我使用这个.NET和C#,而是涉及到Visual Studio的东西以及可能会帮助让我在正确的方向前进。Is there any way I can hook into the debugger to know when its freezing the application, so I can counter-measure the time and subtract it accordingly? As tagged, I'm using .NET and C# for this, but anything related to Visual Studio as well might help get me going in the right direction. 提供更多的信息,我用几个秒表(进行更新,渲染和其他一些事件都在一个不同的消息队列)。如果我把里面的更新()断点,或应用程序的任何其他部分,则秒表会精确地测量实时这些花费之间。这包括时间,我花调试更新()或渲染()我的应用程序的各种完全不相关的组件,这些组件下游名为的或输入()等。显然模拟的时间(由传递到顶层更新GameTime参数控制,渲染等功能)将无法正常是否工作,即使如果CPU只用了13毫秒完成更新功能,我花的 13秒的额外调试的(看着变量,然后用模拟继续);问题是,我会看到其他秒表突然占 13额外秒的时间。如果仍然没有任何意义,我会再附和。[ EDIT ]To provide more information, I am using several stopwatches (for update, rendering, and a few other events all in a different message queue). If I set a breakpoint inside Update(), or in any other part of the application, the stopwatches will accurately measure the Real Time spent between these. This includes time I spend debugging various completely unrelated components of my application which are called downstream of Update() or Render() or Input() etc. Obviously the simulation's Timing (controlled by the GameTime parameter passed into the toplevel Update, Render, etc. functions) won't work properly if, even if the CPU only took 13 ms to finish the update function, I spend 13 extra seconds debugging (looking at variables and then Continue with the simulation); the problem being that I will see the other stopwatches suddenly accounting for 13 extra seconds of time. If it still doesn't make sense, I'll chime in again.推荐答案使用性能计数器来代替。该进程的CPU时间应该给一个很好的指标(但不准确作为实时秒表),不应与调试干扰。Use performance counters instead. The process CPU time should give a good indicator (but not as accurate as a realtime stopwatch) and should not interfere with debugging. 这篇关于跟踪时间花费调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-28 06:05