简体   繁体   English

如何在Delphi 6 IDE中保留大量的OutputDebugString()调用降级我的应用程序?

[英]How can I keep a large amount of OutputDebugString() calls from degrading my application in the Delphi 6 IDE?

This has happened to me on more than one occasion and has led to many lost hours chasing a ghost. 这种情况不止一次发生在我身上,导致许多人失去了追逐幽灵的时间。 As typical, when I am debugging some really difficult timing-related code I start adding tons of OutputDebugString() calls, so I can get a good picture of the sequence of related operations. 通常,当我调试一些非常困难的与时序相关的代码时,我开始添加大量的OutputDebugString()调用,因此我可以很好地了解相关操作的顺序。 The problem is, the Delphi 6 IDE seems to be able to only handle that situation for so long. 问题是,Delphi 6 IDE似乎只能处理这种情况这么久。 I'll use a concrete example I just went through to avoid generalities (as much as possible). 我将使用一个具体的例子,我只是为了避免一般性(尽可能多)。

I spent several days debugging my inter-thread semaphore locking code along with my DirectShow timestamp calculation code that was causing some deeply frustrating problems. 我花了好几天调试我的线程间信号量锁定代码以及我的DirectShow时间戳计算代码,这导致了一些非常令人沮丧的问题。 After having eliminated every bug I could think of, I still was having a problem with Skype , which my application sends audio to. 在消除了我能想到的每一个错误之后,我仍然遇到了Skype的问题,我的应用程序发送了音频。

After about 10 seconds the delay between my talking and hearing my voice come out of Skype on the second PC that I was using for testing, the far end of the call, started to grow. 大约10秒钟之后,我在谈话和听到我的声音之间的延迟来自于我用于测试的第二台PC上的Skype,呼叫的远端开始增长。 At around 20 - 30 seconds the delay started to grow exponentially and at that point triggered code I have that checks to see if a critical section was being held too long. 在大约20-30秒时,延迟开始呈指数级增长,此时触发的代码我检查了一个关键部分是否持有时间过长。

Fortunately it wasn't too late at night and having been through this before, I decided to stop relentlessly tracing and turned off the majority of the OutputDebugString(). 幸运的是,它并没有太晚,并且在此之前经历过这一切,我决定停止无情地跟踪并关闭大部分的OutputDebugString()。 Thankfully I had most of them wrapped in a conditional compiler define so it was easy to do. 值得庆幸的是,我将大部分内容包装在条件编译器定义中,因此很容易做到。 The instant I did this the problems went away, and it turned out my code was working fine. 我这样做的那一刻问题消失了,事实证明我的代码工作正常。

So it looks like the Delphi 6 IDE starts to really bog down when the amount of OutputDebugstring() traffic is above some threshold. 因此,当OutputDebugstring()流量超过某个阈值时,看起来Delphi 6 IDE开始陷入困境。 Perhaps it's just the task of adding strings to the Event Log debugger pane, which holds all the OutputDebugString() reports. 也许只是向事件日志调试器窗格添加字符串的任务,该窗格包含所有OutputDebugString()报告。 I don't know, but I have seen similar problems in my applications when a TMemo or similar control starts to contain too many strings. 我不知道,但是当TMemo或类似控件开始包含太多字符串时,我在应用程序中看到了类似的问题。

What have those of you out there done to prevent this? 那些人为了防止这种情况做了什么? Is there a way of clearing the Event Log via some method call or at least a way of limiting its size? 有没有办法通过某种方法调用清除事件日志或至少是限制其大小的方法? Also, what techniques do you use via conditional defines, IDE plug-ins, or whatever, to cope with this situation? 此外,您通过条件定义,IDE插件或其他什么技术来应对这种情况?

在使用Delphi 2007之前,我遇到了类似的问题。在IDE中禁用事件查看,而是使用来自Sysinternals的 DebugView

I hardly ever use OutputDebugString. 我几乎没有使用OutputDebugString。 I find it hard to analyze the output in the IDE and it takes extra effort to keep several sets of multiple runs. 我发现很难分析IDE中的输出,并且需要额外的努力才能保留多组多次运行。

I really prefer a good logging component suite (CodeSite, SmartInspect) and usually log to various files. 我真的更喜欢一个好的日志记录组件套件(CodeSite,SmartInspect),并且通常会记录到各种文件。 Standard files for example are "General", "Debug" (standard debug info that I want to collect from a client installation as well), "Configuration", "Services", "Clients". 例如,标准文件是“常规”,“调试”(我想从客户端安装中收集的标准调试信息),“配置”,“服务”,“客户端”。 These are all set up to "overflow" to a set of numbered files, which allows you to keep the logs of several runs by simply allowing more numbered files. 这些都被设置为“溢出”到一组编号的文件,这允许您通过简单地允许更多编号的文件来保留几个运行的日志。 Comparing log info from different runs becomes a whole lot easier that way. 比较来自不同运行的日志信息变得更加容易。

In the situation you describe I would add debug statements that log to a separate logfile. 在您描述的情况下,我将添加记录到单独日志文件的调试语句。 For example "Trace". 例如“Trace”。 The code to make "Trace" available is between conditional defines. 使“跟踪”可用的代码在条件定义之间。 That makes turning it on pretty simple. 这使它变得非常简单。

To avoid leaving in these extra debug statements, I tend to make the changes to turn on the "Trace" log without checking it out from source control. 为了避免留在这些额外的调试语句中,我倾向于进行更改以打开“跟踪”日志而不从源代码控制中检出它。 That way, the compiler of the build server will throw out "identifier not defined" errors on any statements unintentionally left in. If I want to keep these extra statements I either change them to go to the "Debug" log, or put them between conditional defines. 这样,构建服务器的编译器会在无意中留下的任何语句中抛出“标识符未定义”错误。如果我想保留这些额外的语句,我要么将它们更改为“调试”日志,要么将它们放在条件定义。

The first thing I would do is make certain that the problem is what you think it is. 我要做的第一件事就是确保问题就是你认为的问题。 It has been a long time since I've used Delphi, so I'm not sure about the IDE limitations, but I'm a bit skeptical that the event log will start bogging down exponentially over time with the same number of debug strings being written in a period of 20-30 seconds. 自从我使用Delphi以来已经很长时间了,所以我不确定IDE的限制,但我有点怀疑事件日志会随着时间的推移而开始呈指数级下降,调试字符串的数量相同写在20-30秒的时间。 It seems more likely that the number of debug strings being written is increasing over time for some reason, which could indicate a bug in your application control flow that is just not as obvious with the logging disabled. 由于某些原因,写入的调试字符串数量似乎越来越有可能随着时间的推移而增加,这可能表明应用程序控制流中的错误在禁用日志记录时并不明显。

To be sure I would try writing a simple application that just runs in a loop writing out debug strings in chunks of 100 or so, and start recording the time it takes for each chunk, and see if the time starts to increase as significantly over a 20-30 second timespan. 为了确保我会尝试编写一个简单的应用程序,它只是在一个循环中运行,以大约100个块的方式写出调试字符串,并开始记录每个块所花费的时间,并查看时间是否开始显着增加20-30秒的时间。

If you do verify that this is the problem - or even if it's not - then I would recommend using some type of logging library instead. 如果确实确认这是问题 - 或者即使不是 - 那么我建议使用某种类型的日志库。 OutputDebugString really loses it's effectiveness when you use it for massive log dumps like that. 当你将它用于大规模的日志转储时,OutputDebugString确实失去了它的有效性。 Even if you do find a way to reset or limit the output window, you'd be losing all of that logging data. 即使您确实找到了重置或限制输出窗口的方法,您也会丢失所有这些日志记录数据。

IDE Fix Pack has an optimisation to improve performance of OutputDebugString IDE Fix Pack具有优化以提高OutputDebugString的性能

The IDE's Debug Log View also got an optimization. IDE的调试日志视图也得到了优化。 The debugger now updates the Log View only when the IDE is idle. 调试器现在仅在IDE空闲时更新日志视图。 This allows the IDE to stay responsive when hundreds of OutputDebugString messages or other debug messages are written to the Debug Log View. 这允许IDE在将数百个OutputDebugString消息或其他调试消息写入调试日志视图时保持响应。

Note that this only runs on Delphi 2007 and above. 请注意,这仅适用于Delphi 2007及更高版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Delphi中调试OutputDebugString调用 - Debugging OutputDebugString calls in Delphi 如何从服务接收OutputDebugString? - How can I receive OutputDebugString from a service? Delphi - hook \\ bypass \\从系统中将所有OutputDebugString捕获到我的应用程序中,并带有进程ID和名称 - Delphi - hook\bypass\catch all the OutputDebugString from the system into my application with process id and name 如何在不使用IDE的情况下编译Delphi应用程序? - How can I compile a Delphi application without using the IDE? 如何从Delphi服务中调用另一个应用程序? - How can I call another application from my Delphi service? 如何在Delphi IDE启动时停止打开表单 - How can I stop forms from opening on Delphi IDE startup 如何让FindDialog保持最佳状态(Delphi)? - How Can I Keep the FindDialog from Staying on Top (Delphi)? 如何将我的应用程序保留在前台? - How can I keep my application in the foreground? 如何在不重新安装 IDE 的情况下恢复我的 Delphi 关联? - How can I restore my Delphi associations without re-installing the IDE? (Delphi 10.2) 如何从我的应用程序在 Android 的 Web 浏览器中打开 URL? - (Delphi 10.2) How can I open a URL in Android's web browser from my application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM