How can I save a large number of calls to OutputDebugString () from degrading my application in the Delphi 6 IDE?

This happened to me more than once and led to the fact that many lost watches chased a ghost. As usual, when I debug some really complex time-related code, I start adding tons of calls to OutputDebugString (), so I can get a good idea of ​​the sequence of related operations. The problem is that the Delphi 6 IDE seems to be able to handle this situation for so long. I will use the specific example that I just went through to avoid common ones (as far as possible).

I spent several days debugging my cross-threading semaphore code, as well as the DirectShow timestamp code, which caused some very annoying problems. After fixing every error that I could think of, I still had a problem with Skype , which my application sends audio to.

After about 10 seconds between my conversations and my hearing, my voice came out of Skype on the second PC, which I used for testing, at the far end of the call, it began to grow. After about 20-30 seconds, the delay began to increase exponentially, and at that moment a code was launched that checks if the critical section is too long.

Fortunately, it wasn't too late, and having done this earlier, I decided to stop relentlessly monitoring and disable most of OutputDebugString (). Fortunately, most of them were wrapped in a conditional compiler, so it was easy to do. At the moment I did this, the problems disappeared, and it turned out that my code was working fine.

So, it looks like the Delphi 6 IDE is starting to really be afraid when the amount of OutputDebugstring () traffic exceeds a certain threshold. Perhaps this is just the task of adding lines to the event log debug panel, which contains all the OutputDebugString () reports. I don’t know, but I saw similar problems in my applications when TMemo or a similar control starts to contain too many lines.

What have you done to prevent this? Is there a way to clear the event log through some method call, or at least a way to limit its size? Also, what methods do you use with conditional definitions, IDE plugins, or something else to handle this situation?

+8
debugging logging delphi outputdebugstring
source share
4 answers

A similar problem occurred to me earlier with Delphi 2007. Disable event viewer in the IDE and use DebugView from Sysinternals instead.

+4
source share

I rarely use OutputDebugString. It's hard for me to parse the output in the IDE, and it takes extra effort to run multiple sets of multiple runs.

I really prefer a good set of registration components (CodeSite, SmartInspect) and usually register in different files. For example, the standard files are “General”, “Debugging” (standard debugging information that I want to collect using client installation as well), “Configuration”, “Services”, “Clients”. They are all set to "overflow" a set of numbered files, which allows you to keep logs of several runs, simply allowing more numbered files. Comparing log information from different runs becomes much easier.

In the situation described, I would add debug instructions that are written to a separate log file. For example, "Trace". The code to make Trace available is between the conditional definitions. This makes it pretty simple.

In order not to leave these additional debugging reports, I try to ensure that the changes include the "Trace" log without checking it from the source control. Thus, the compiler of the build server will throw "identifier undefined" errors for any unintentionally abandoned statements. If I want to save these additional instructions, I will either modify them to go to the Debug log, or put them between conditional defines.

+2
source share

The first thing I would like to do is make sure that the problem is what you think. It has been a long time since I used Delphi, so I'm not sure about the limitations of the IDE, but I'm a little skeptical that the event log will begin to clog exponentially over time with the same number of debug lines written in 20-30 seconds . It seems more likely that the number of debugging lines that are being written, for some reason, increases over time, which may indicate an error in the application control thread, which is not so obvious when disabling the log.

To be sure that I will try to write a simple application that simply starts in a loop, writing out debugging lines in pieces of 100 or so, and start recording the time it takes for each fragment and see if the time starts to increase significantly over 20 -30 seconds.

If you are convinced that this is a problem - or even if it is not, I would recommend using some type of logging library. OutputDebugString really loses efficiency when you use it for bulk dumps of logs. Even if you find a way to reset or restrict the output window, you will lose all registration data.

+2
source share

IDE Fix Pack has optimization to improve OutputDebugString performance

Optimization has also appeared in IDEs Debug Log View. The debugger now updates the log view only when the IDE is inactive. This allows the IDE to remain responsive when hundreds of OutputDebugString messages or other debug messages are written to the debug log view.

Please note that this only works on Delphi 2007 and above.

+1
source share

All Articles