Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326706 - EDC code tracing has (relatively) high overhead
Summary: EDC code tracing has (relatively) high overhead
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-edc (show other bugs)
Version: 8.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ken Ryall CLA
QA Contact: Ken Ryall CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-30 15:04 EDT by John Cortell CLA
Modified: 2014-01-29 22:45 EST (History)
1 user (show)

See Also:


Attachments
Solution (93.70 KB, patch)
2010-10-04 15:22 EDT, John Cortell CLA
john.cortell: iplog-
Details | Diff
patch to make link to "how to" page clickable in javadoc pop-up (1.03 KB, patch)
2010-10-04 16:41 EDT, Kirk Beitz CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Cortell CLA 2010-09-30 15:04:05 EDT
I'm all for instrumenting plugin code with trace statements using Eclipse's DebugTrace facility. Every line identifies the time, thread, and what line of code is generating the trace. This is very useful for troubleshooting timing and performance issues. I'm glad to see EDC plugins using it. However, I think the way the trace statements are coded need improvement. 

First, trace statements should have as little overhead as possible. Ideally, they'd have zero overhead when tracing is turned off. That's not possible without jvm runtime support, but we should strive for as close to zero overhead as possible. Checking a static boolean is extremely fast, and that is what you see a lot of plugins do. E.g., see:

   org.eclipse.cdt.dsf.internal.DsfPlugin.start(BundleContext)

then, trace statements are coded as follows:

   if (TRACE_RUNCONTROL) { <trace statement> }

EDC, however, is relying on DebugTrace to determine whether or not to trace. While this is convenient, look at what it involves:

   EDCDebugger.getDefault().getTrace().traceEntry(option, ...);

...three method calls and a possible string creation for every trace statement *even when tracing is turned off*. I've taken some measurements and that's 500 X more expensive than checking a static field. There are quite a few CDT plugins tracing, and none but EDC rely on DebugTrace class for checking the option. I recommend we use static field checks to reduce overhead when tracing is off. We lose the ability to dynamically toggle tracing, but is that being used?

Also, the traceExit() call in EDC are unreliable since an exception throw will bypass them. Also, any methods with multiple return statements would have to be equipped with multiple exit traces statements. This is not only onerous and code-cluttering, but error prone. traceExit's should be done in a finally block. I've done some measurements here, too, and adding a finally block doesn't add any runtime overhead.

To summarize, my recommendations are:
1. Use static field checks before calling into DebugTrace methods (unless someone is relying on dynamically toggling on/off trace).
2. Use finally sections for exit trace statements

Objections?
Comment 1 Ken Ryall CLA 2010-10-01 08:31:31 EDT
No objections, tracing in EDC was created with good intentions but neglected. The last time I attempted to turn on tracing I got NPEs from some of the trace statements...

The use case I wanted to support was this: user reports bug, we tell them to turn on tracing, reproduce the bug, then send us the log.

But currently it's difficult to turn on tracing and I can never remember where the log files get created. We may need to create some UI for this and make the trace files more accessible.
Comment 2 John Cortell CLA 2010-10-04 10:37:23 EDT
(In reply to comment #1)
> The use case I wanted to support was this: user reports bug, we tell them to
> turn on tracing, reproduce the bug, then send us the log.

Yep. That's exactly the sort of thing the Eclipse tracing mechanism is supposed to allow.


> But currently it's difficult to turn on tracing and I can never remember where
> the log files get created. We may need to create some UI for this and make the
> trace files more accessible.

{workspace}/.metadata/trace.log

Yeah. It requires specifying switches when launching eclipse. The GUI developers have to turn these things on are in the PDE launch configuration. Equivalent GUI is not available for our end users. We could add it to the EDC launch configuration. I guess the question there is whether the tracing is used frequently enough to add the GUI. And if that is even the right approach--a more general GUI (as in in PDE launch configuration) may be a better solution, but then that becomes a platform thing.

For now, my concern is only the performance and the missing of function-exit statements. I'll address those.
Comment 3 John Cortell CLA 2010-10-04 11:53:13 EDT
(In reply to comment #0)
> Also, the traceExit() call in EDC are unreliable since an exception throw will
> bypass them. Also, any methods with multiple return statements would have to be
> equipped with multiple exit traces statements. This is not only onerous and
> code-cluttering, but error prone. traceExit's should be done in a finally
> block. I've done some measurements here, too, and adding a finally block
> doesn't add any runtime overhead.

Once I started trying to adjust these things, it occurred to me that perhaps the missed trace statements in the case of an exception is a good thing. It at least provides a hint that an exception was thrown whereas an exit trace put in a finally clause can make a successful and unsuccessful execution of the method indistinguishable. Also, consolidating multiple exit statements into one a finally clause can be messy since the result logged in the trace sometimes varies based on the flow. 

I'm going to address only the performance aspect of this bug.
Comment 4 John Cortell CLA 2010-10-04 15:22:58 EDT
Created attachment 180202 [details]
Solution
Comment 5 John Cortell CLA 2010-10-04 15:24:20 EDT
Committed to HEAD.
Comment 6 CDT Genie CLA 2010-10-04 16:23:03 EDT
*** cdt cvs genie on behalf of jcortell ***
Bug 326706: EDC code tracing has (relatively) high overhead

[+] EDCTrace.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/EDCTrace.java?root=Tools_Project&revision=1.1&view=markup
[*] EDCDebugger.java 1.5 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/EDCDebugger.java?root=Tools_Project&r1=1.4&r2=1.5
[-] IEDCTraceOptions.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/IEDCTraceOptions.java?root=Tools_Project&view=markup

[*] MemoryCache.java 1.8 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/services/dsf/MemoryCache.java?root=Tools_Project&r1=1.7&r2=1.8
[*] Breakpoints.java 1.22 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/services/dsf/Breakpoints.java?root=Tools_Project&r1=1.21&r2=1.22
[*] Expressions.java 1.19 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/services/dsf/Expressions.java?root=Tools_Project&r1=1.18&r2=1.19
[*] Memory.java 1.9 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/services/dsf/Memory.java?root=Tools_Project&r1=1.8&r2=1.9
[*] RunControl.java 1.39 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/services/dsf/RunControl.java?root=Tools_Project&r1=1.38&r2=1.39

[*] OperandValue.java 1.4 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/eval/ast/engine/instructions/OperandValue.java?root=Tools_Project&r1=1.3&r2=1.4

[*] DwarfInfoReader.java 1.18 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/symbols/dwarf/DwarfInfoReader.java?root=Tools_Project&r1=1.17&r2=1.18

[*] ASTInstructionCompiler.java 1.9 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/internal/eval/ast/engine/ASTInstructionCompiler.java?root=Tools_Project&r1=1.8&r2=1.9

[*] Stack.java 1.38 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/edc/org.eclipse.cdt.debug.edc/src/org/eclipse/cdt/debug/edc/services/Stack.java?root=Tools_Project&r1=1.37&r2=1.38
Comment 7 Kirk Beitz CLA 2010-10-04 16:41:57 EDT
Created attachment 180209 [details]
patch to make link to "how to" page clickable in javadoc pop-up

hey, john … if you format the javadoc in EDCTrace.java as shown in the attached patch, it will cause the link to be clickable from the javadoc window, and will take the user straight an eclipse editor window with the page at the URL you cite.
Comment 8 John Cortell CLA 2010-10-04 17:01:28 EDT
(In reply to comment #7)
> Created an attachment (id=180209) [details]
> patch to make link to "how to" page clickable in javadoc pop-up
> 
> hey, john … if you format the javadoc in EDCTrace.java as shown in the attached
> patch, it will cause the link to be clickable from the javadoc window, and will
> take the user straight an eclipse editor window with the page at the URL you
> cite.

Thanks. Applied.