Download User Manual

Transcript
Software Diagnostics Developer Edition 1.0
© 201 0 Software Diagnostics
SD Developer Edition
User Guide for Software Diagnostics Developer Edition 1.0
by Software Diagnostics
This document describes the features of SD Dev Edition and
prov ides quickstart tutorials to enable y ou to apply the tool
right away .
Throughout the manual, the abbrev iation SD Dev Edition is used
to refer to Software Diagnostics Dev eloper Edition.
Thank y ou for using Software Diagnostics Dev eloper Edition.
SD Developer Edition
© 201 0 Software Diagnostics
All rights reserv ed. No parts of this work may be reproduced in any form or by any means graphic, electronic, or mechanical, including photocopy ing, recording, taping, or information
storage and retriev al sy stems - without the written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered
trademarks of the respectiv e owners. The publisher and the author make no claim to these
trademarks.
While ev ery precaution has been taken in the preparation of this document, the publisher and the
author assume no responsibility for errors or omissions, or for damages resulting from the use of
information contained in this document or from the use of programs and source code that may
accompany it. In no ev ent shall the publisher and the author be liable for any loss of profit or any
other commercial damage caused or alleged to hav e been caused directly or indirectly by this
document.
Author and Company Informations:
Software Diagnostics
August Bebel Straße 26-53
D-1 4482 Potsdam
Germany
CEO: Marc Hildebrandt
Johannes Bohnet
Amtsgericht Potsdam
HRB 221 23 P
Finanzamt Potsdam Stadt
Phone: +49 331 7 062340
Fax : +49 331 7 062341
EMail: [email protected]
Internet: http://www.softwarediagnostics.com
Printed: Mai 201 0 in Potsdam, Germany
V ersion: SD Dev eloper Edition 1 .0.5400
4
SD Dev eloper Edition
Table of Contents
7
Part I Quickstart
1.1
Tracing Methods
7
1.2
Tracing Strategies
8
Part II Operational Requirements and Installation
10
2.1
Operational Requirements
10
2.2
Installation
10
Part III Prepare Your Software System
3.1
Initial Preparation
Part IV Trace Your System's Behavior
12
12
15
4.1
Optional Preparation Step
15
4.2
Start Tracing
15
4.2.1
TraceOv er
15
4.2.2
AttachToProcess
18
4.2.3
StartWithTracing
18
4.3
SD Recorder
19
4.4
Polluting Functions
20
4.5
Probes
21
4.5.1
DataProbes
21
4.5.2
MemAccessProbes (ex perimental)
24
4.5.3
ParamProbes
25
Part V Import Traces
28
5.1
Create Project Dialog
28
5.2
Import Dialog
28
5.3
Manage and Delete Traces
29
Part VI Visual Analysis
32
6.1
CallStackView
32
6.2
CallGraphView
34
6.3
SingleCallView
34
6.4
SearchView
35
Part VII Tutorials
37
7.1
Bug: Erroneous Database Entry
37
7.2
Bug: XML Content Written in Wrong Order
39
7.3
Feature Location: Privacy Data in Google Chrome
43
© 2010 Softw are Diagnos tics
Ex perimental Features
Part VIII Experimental Features
Part IX Problems and Known Issues
© 2010 Softw are Diagnos tics
5
47
49
Part I
Quickstart
Quickstart
1
7
Quickstart
This chapter briefly describes the m ost im portant steps for using SD Dev Edition.
1.1
Tracing Methods
There are three different way s to trace y our application. All three m ethods are started by
clicking the Tracing icon in the Visual Studio toolbar. The m ethods av ailable are dependent
on the state of the Visual Studio debugger.
(1 ) StartWithTracing
You hav en't started y our app y et. Click the Tracing icon. Click Start Debugger. The app starts
in tracing m ode. Record a trace with the SD Recorder.
You alway s should start tracing with a low polluting functions threshold, e.g., 1 0.
(2 ) AttachToProcess
Your app is running, howev er, not under control of the Visual Studio debugger. For instance,
y ou hav e started it with Visual Studio's Ctrl-F5 StartWithoutDebugging. Click Tracing icon.
Choose the process ID of y our app. Click AttachToProcess. With the SD Recorder y ou record a
trace.
You alway s should start tracing with a sm all polluting functions threshold, e.g., 1 0.
(3 ) TraceOv er
Your app is currently debugged by the Visual Studio debugger and it is in break m ode. You
© 2010 Softw are Diagnos tics
8
SD Dev eloper Edition
are probably perform ing StepInto and StepOv er operations to nav igate through the
execution. If y ou are at a point in the execution where y ou are not sure if StepInto is a waste of
tim e or if StepOv er skips an im portant part of the execution, then use TraceOv er. Click the
Tracing icon. Choose the point in the code where tracing should be stopped by clicking the
m ore and less buttons. Choose one of the TraceOv er options.
Be sure that the control flow passes the code line where the blue region ends. If the
control flow m isses this point in the code, TraceOv er won't stop. You m ay be concerned when
TraceOv er takes a long tim e and nothing happens. In this case, use the Stop icon in the Visual
Studio toolbar to interrupt tracing.
- Prepare Your Software Sy stem After preparing y our software sy stem , y ou should at least exclude com pilergenerated functions and functions of the Standard Tem plate Library STL from being traced.
Otherwise, y ou get huge traces with lots of inform ation on com piler and STL internals. For
details read the respectiv e chapter.
1.2
Tracing Strategies
The m ain strategy is to identify the core part of execution that is of interest for y our current
task. Hence, the goal is to do a TraceOv er of a reasonably sm all num ber of function calls, e.g.,
1 0.000, and trace them with full detail, e.g., with detailed Param Probes.
- Find a good place for a breakpoint Start y our app without Visual Studio debugging support (Ctrl-F5). Do the necessary
interactions with y our app. Do AttachToProcess. Choose a low polluting functions threshold,
e.g., 1 0. Click Record in SD Recorder. Interact with y our app. Click Stop. Analy ze the trace.
Identify the interesting part of execution, i.e., the responsible call that triggers this part of
the execution. Switch to Visual Studio's code v iew v ia the context m enu of the call and place a
breakpoint.
Click the (Software Diagnostics) Stop icon in the Visual Studio toolbar and switch the process
to the Visual Studio debugger. Click run in Visual Studio and interact with y our app such
that the control flow hits the breakpoint.
Do TraceOv er. If y ou don't know how m any calls are triggered by TraceOv er try a polluting
functions threshold of 50-1 00 and do not use Param Probes. (With Param Probes the polluting
functions m echanism won't find m any of these functions.) Analy ze the trace and find an ev en
m ore detailed part of the execution that is of interest.
Do TraceOv er again. If y ou are sure that y ou trace less than 1 0.000 calls, use
DetailedParam Probes to record not only the calls but also all param eter v alues that are
passed into the functions. Analy ze the trace.
The search v iew also searches Param Probes which lets y ou search for suspicious
param eter v alues.
© 2010 Softw are Diagnos tics
Part II
Operational Requirements and Installation
10
2
SD Dev eloper Edition
Operational Requirements and Installation
This chapter outlines the operational requirem ents of SD Dev Edition and guides y ou through
the installation process.
2.1
Operational Requirements
SD Dev Edition depends on software packages of other v endors. You need to hav e installed at
least:
Microsoft Windows XP, Microsoft Windows Vista or Microsoft Windows 7
Microsoft Visual Studio 2 008
x86 com patible env ironm ent (on x6 4 it runs as an x86 application)
.NET Fram ework 3 .5 (latest updates)
Microsoft Debugging Tools for Windows x86 (tested with 6 .1 1 .1 .4 04 )
SD Dev Edition requires m inim al hardware support:
Graphics Card with OpenGL 1 .4 support
2.2
Installation
If y ou hav e a prev ious v ersion of SD Dev Edition, please uninstall this v ersion first before
installing the new v ersion. The uninstall executable is found in the start m enu.
To install SD Dev Edition, run the installer executable. The following com ponents are
installed:
SD Dev Edition: the m ain application is installed to "Program Files/Software Diagnostics/
Dev eloper Edition" ("Program Files (x86 )/Software Diagnostics/Dev eloper Edition" on x6 4
operating sy stem s) [env ironm ent v ariable SD_HOME]
sd_v saddin_2 008.dll: is the Microsoft Visual Studio addin com ponent of SD Dev Edition and
is placed in "My Docum ents/Visual Studio 2 008/Addins/".
SD Recorder: is the trace recording com ponent. It is installed into "My Docum ents/
Traces/" [env ironm ent v ariable SD_TRACING].
All traces and other docum ents while using the SD Dev Edition are stored in the location:
"My Docum ents/Traces/" [env ironm ent v ariable SD_TRACING].
The installer creates the env ironm ent v ariables SD_HOME and SD_TRACING.
If y ou encounter problem s, look at the Problem s and Known Issues chapter.
© 2010 Softw are Diagnos tics
Part III
Prepare Your Software System
12
3
SD Dev eloper Edition
Prepare Your Software System
Before y ou can use SD Dev Edition to analy ze the dy nam ics of y our software sy stem , y ou need
to perform an initial preparation step.
3.1
Initial Preparation
SD Dev Edition uses dy nam ic analy sis techniques to create a trace of y our sy stem 's internal
behav ior. To enable y our sy stem , y ou need to perform an initial autom ated preparation step.
This step induces a com plete rebuild of y our code. Howev er, y ou only need to do this once.
After this, y ou can dev elop y our code as usual - there is no increased build tim e or
perform ance ov erhead at runtim e.
1 . Open y our solution (y our code) in Microsoft Visual Studio.
2 . Click the prepare solution icon in the Microsoft Visual Studio SDAddin Toolbar (stethoscope
sy m bol).
Microsoft Visual Studio SDAddin
Toolbar
3 . Choose the configuration that y ou work with (e.g., Debug) and check all projects. You hav e
the option to repeat this for other configurations.
[EX PERIMENT A L]
Tracing optim ized code, which is ty pically done in the Release configuration, is an
experim ental feature at the m om ent.
4 . Click "Patch projects".
5. Perform a full build of y our code.
6 . Click the function selection icon in the Microsoft Visual Studio SDAddin Toolbar (f sy m bol).
Microsoft Visual Studio SDAddin
Toolbar
7.
Check all projects (exe/dll) and uncheck all directories that y ou do not want to trace.
You ty pically do not want to trace com piler generated functions ("???") and functions from
© 2010 Softw are Diagnos tics
Prepare Y our Software Sy stem
13
the standard tem plate library STL (".../m icrosoft v isual studio 9 .0").
FunctionSelector Dialog
8. Click "Apply Selection".
As y ou see in the FunctionSelector Dialog, y ou can select parts of 3 rd-party libraries.
Howev er, note that the 3 rd-party libraries only appear in the dialog because their header
files contain com pilable code, e.g., due to inlined code or to tem plate usage. You will ty pically
deactiv ate tracing for these functions because they im plem ent low-lev el, utility
functionality . For instance, the STL internals as part of the "m icrosoft v isual studio 9 .0" folder
in the figure abov e ty pically won't be of interest. Unfortunately , "interesting" API calls to 3 rdparty libraries are not traceable if y ou don't hav e the source code and y ou don't integrate
their Microsoft Visual Studio projects into y our application's Microsoft Visual Studio solution.
A workaround could be to encapsulate a specific API function of interest with a wrapper
function that is part of y our application. This way , the call to the wrapper function is traced
which prov ide equiv alent inform ation than directly tracing the call to the original API
function.
© 2010 Softw are Diagnos tics
Part IV
Trace Your System's Behavior
Trace Y our Sy stem's Behav ior
4
15
Trace Your System's Behavior
With SD Dev Edition y ou are able to "see" the inner workings of y our software sy stem at
runtim e. The behav ior is first captured as a trace and then v isualized.
This chapter explains how to create a trace.
4.1
Optional Preparation Step
As an optional step, y ou m ay want to restrict the functions whose calls are captured in a
trace. To do so, follow the instructions giv en in the preparation chapter.
4.2
Start Tracing
Click the StartTracing icon
in t h e Microsoft Visual Studio SDAddin Toolbar. Depending on
the state of Microsoft Visual Studio, y ou hav e 3 different tracing options:
1 . TraceOv er
2 . AttachToProcess
3 . StartWithTracing
Be aware that tracing refers to the current "StartUp Project" in y our Visual Studio
solution. Hence, assure that the StartUp Project is set correctly before apply ing tracing.
4.2.1
TraceOver
To use TraceOv er, y ou need to run y our application with the Microsoft Visual Studio
Debugger. Just debug as usual and stop y our application at a breakpoint. You hav e the option
of perform ing the usual Microsoft Visual Studio step-ov er or step-into operations to m ov e
forward within the execution.
Debugging ty pically m eans that y ou hav e to decide whether to follow a call (step-into) or to
skip it (step-ov er). At som e point, this decision is difficult: Step-into would probably inv olv e
wasting tim e because y ou div e into too detailed an execution, whereas step-ov er probably
m ov es y ou ov er im portant parts of the execution.
In these situations, use TraceOv er. Click
© 2010 Softw are Diagnos tics
for the TraceOv er dialog.
16
SD Dev eloper Edition
Setting the Code Range
Now define the code range to trace. The last line of the selection defines a "stop tracing
breakpoint". Hence, it defines when tracing is finished.
Be sure that control passes the last code line of the selected range.
If this is not the case, TraceOv er will not stop autom atically . You then hav e to stop it
m anually by clicking the stop icon in the Microsoft Visual Studio SDAddin Toolbar.
Polluting Function Threshold
The polluting function m echanism perm its tracing with different tracing granularities. For a
detailed description see the polluting functions section.
© 2010 Softw are Diagnos tics
Trace Y our Sy stem's Behav ior
17
Param Probes
Clicking "TraceOv er without Param Probes" traces function calls. Additionally , DataProbes
and Mem AccessProbes are traced if they hav e been set. After tracing, the trace is
autom atically im ported into SD Dev Edition and v isualized.
If y ou want to trace the param eter v alues that are passed into the functions, click either
"TraceOv er with norm al Param Probes" or "TraceOv er with detailed Param Probes". Both
tracing ty pes slow down execution significantly . Hence, apply them only if y ou are sure that
less than approx. 50.000 function calls are executed in the selected code range. Be aware that
due to the slow down, the polluting function m echanism s will m ost likely not identify a single
function as polluting. Hence, y ou trace ev ery call which in turn m ight increase the num ber
of traced calls.
"TraceOv er with norm al Param Probes": For all function calls, the param eter v alues are
traced. For sim ple data ty pes such as int, char*, float, etc. this tracing technique is the
appropriate choice. Passed objects, howev er, are not resolv ed. Only the pointer v alue is
shown.
"TraceOv er with detailed Param Probes": In contrast to norm al Param Probes, the nested
structure of a param eter is resolv ed. Object pointers, e.g., a "this" pointer, are not just pointer
v alues, but all their attribute v alues are resolv ed. This technique is significantly slower than
norm al Param Probes.
Select Modules
You m ay choose which loaded dlls to trace. Additionally , y ou m ay exclude functions.
Visual Studio Debugging
After a TraceOver operation, the Visual Studio's stop button does not kill
the app anymore. In contrast, Visual Studio detaches itself and keeps the app
running.
© 2010 Softw are Diagnos tics
18
4.2.2
SD Dev eloper Edition
AttachToProcess
AttachToProcess is av ailable v ia clicking on
in t h e Microsoft Visual Studio SDAddin
Toolbar if y ou started y our application as a freely running process, i.e., without being under
the control of the Microsoft Visual Studiodebugger. If y ou started y our app with the Microsoft
Visual Studiodebugger, sim ply detach the Microsoft Visual Studiodebugger.
Choose the process ID that corresponds to y our application. You can use the filter text field to
quickly find the process. Optionally , choose "select m odules" to define the loaded dlls and the
functions to trace.
After attaching the tracing engine to the process, the SD Recorder pops up. It is used to start
and stop the tracing.
4.2.3
StartWithTracing
StartWithTracing is av ailable v ia clicking on
in t h e Microsoft Visual Studio SDAddin
Toolbar if y our application is not started y et.
© 2010 Softw are Diagnos tics
Trace Y our Sy stem's Behav ior
19
Start y our application, optionally with com m and line param eters. After this, the application
is started and the SD Recorder pops up, which is used to start and stop the tracing.
4.3
SD Recorder
The SD Recorder is used to start and stop tracing sim ilar to a screen capturing tool.
You hav e the option of defining a threshold v alue for the polluting functions m echanism .
© 2010 Softw are Diagnos tics
20
SD Dev eloper Edition
Click record and then stop to create a trace. You can create sev eral traces without needing to
restart y our application.
After y ou hav e stopped tracing, the trace is autom atically im ported into SD Dev Edition and
v isualized.
4.4
Polluting Functions
The polluting functions m echanism is a technique to cope with the v ast am ount of runtim e
data that is accum ulated during long tracing tim es. The m echanism enables y ou to trace for
large tim e ranges (up to 3 0 m inutes).
The key idea is to apply a data m ining technique during tracing that identifies polluting
functions and to autom atically disable the tracing technique for them . The data m ining
technique is steered by a threshold v alue: the polluting functions threshold.
You should adjust the threshold v alue according to the tracing tim e that y ou expect. A lower
threshold v alue m eans that fewer functions are contained in the trace. Howev er, the ones
that giv e y ou a broad picture of the behav ior are guaranteed to rem ain in the trace. There is
a trade-off: Trace for a long tim e period but receiv e a coarse-grained picture of the behav ior
only , or trace for a short tim e period and get full details.
Exam ples:
Expected tracing tim e: 1 0 m inutes
Threshold v alue: 2
Expected tracing tim e: 1 m inute
Threshold v alue: 2 0
Expected tracing tim e: 0.1 seconds
Threshold v alue: m ax
The data m ining technique is to som e degree sensitiv e to the algorithm s that are
im plem ented in y our code. Hence, y ou need to choose the threshold v alue that is appropriate
for y our code and y our problem at hand.
A good strategy is to first use SD Recorder and trace with a low threshold v alue (e.g.,
1 0) to get an ov erv iew of the execution, then analy ze the trace and identify a key call that
triggers the functionality that is of interest. Second, set a breakpoint to the corresponding
function and use Microsoft Visual Studio Debugger to nav igate to this point in the execution.
Third, apply TraceOv er to obtain a highly detailed trace that only cov ers the part of the
execution that is of interest.
© 2010 Softw are Diagnos tics
Trace Y our Sy stem's Behav ior
4.5
21
Probes
Probes are tracing com ponents that enrich control flow inform ation (sequence of function
calls) by inform ation on the sy stem state. 3 ty pes of probes are av ailable:
DataProbes
Mem AccessProbes
Param Probes
4.5.1
DataProbes
A DataProbe is attached to a code line and a v ariable that is reachable from this line. The
DataProbe traces the v alue of the v ariable when the control flow passes the code line.
Hence, DataProbes are an autom ated way of the usually tedious debugging cy cle of setting a
breakpoint, breaking execution at a specific code line, observ ing the v ariable's v alue, and
continuing execution until the breakpoint is hit again.
Another com m on technique to collect the data that DataProbes prov ide, is to integrate cout()
or printf() statem ents into the code. With DataProbes, y ou don't need to change the code, and
in particular, y ou don't need to recom pile it. Just add a DataProbe where a v ariable is of
interest.
Setting a DataProbe
The prerequisite to setting a probe is that y our application is not running.
In the Microsoft Visual Studio code v iew put the cursor on the code line where y ou want to
trace a v ariable. Right click and choose: "Add DataProbe".
You can only set DataProbes on code lines that are part of the executable that is
currently set as StartUp Project y our Microsoft Visual Studio solution.
© 2010 Softw are Diagnos tics
22
SD Dev eloper Edition
Local Variables
You can recursiv ely crawl through all v ariables that are accessible at the code line. Choose a
top-lev el or nested v ariable.
Global Variables (experimental)
Alternativ ely , ty pe a search pattern to search for a global v ariable.
Don't start with * if y ou hav e a large code base. Retriev ing all m atching global
© 2010 Softw are Diagnos tics
Trace Y our Sy stem's Behav ior
23
v ariables m ay take a considerable am ount of tim e. It's better to start with choosing a m ore
restricted pattern.
To cancel the operation if it takes too long, click on the SD tray icon in Window's m enu
bar (located near Window's clock icon).
Deleting a DataProbe
After setting a DataProbe, a m arker is shown at the corresponding line in the Microsoft Visual
Studio code v iew. To delete the DataProbe sim ply click on the m arker.
© 2010 Softw are Diagnos tics
24
4.5.2
SD Dev eloper Edition
MemAccessProbes (experimental)
Mem AccessProbes are used to observ e read and write operations on m em ory locations. They
are in particular helpful to answer questions in situations like this:
Why does v ariable X contain an erroneous v alue?
I know that the v alue was still OK when it was accessed at a prev ious execution point v ia
v ariable Y!
When and why did the erroneous v alue com e in?
To use Mem AccessProbes y ou define:
the code line where the Mem AccessProbe is activ ated,
the condition when the Mem AccessProbe is activ ated, and
the v ariable whose m em ory location is observ ed.
In the screenshots, the Mem AccessProbe gets activ ated when control passes code line 6 4 of file
© 2010 Softw are Diagnos tics
Trace Y our Sy stem's Behav ior
25
pa_cpuload.c and the v ariable sam pleRate is equal to 4 4 000.
After this, ev ery access on the m em ory location is recorded where the v alue of the v ariable
m easurer-> av erageLoad is stored.
4.5.3
ParamProbes
Param Probes record the param eter v alues that are passed into the function for each function
call. Param Probes are not attached to indiv idual code lines such as DataProbes or
Mem AccessProbes. Param Probes are activ ated globally in the TraceOv er dialog. Two ty pes of
Param Probes exist:
Param Probes: This is the light-weight approach. For each function call, the plain
© 2010 Softw are Diagnos tics
26
SD Dev eloper Edition
param eter v alues are recorded. If an object pointer is passed into a function, for instance,
only the m em ory address is recorded. For prim itiv e data ty pes such as int, float, char*, the
"real" v alues are recorded.
DetailedParam Probes: This is the heav y -weight approach: For each function call, the
param eter v alue and all further referenced v ariable v alues are recorded. If an object
pointer is passed into a function, for instance, the m em ory address and all attributes of the
object are recorded. This is especially useful as one can look into this pointer. Recording
ov erhead for DetailedParam Probes is approxim ately 1 0 tim es larger than for norm al
Param Probes.
© 2010 Softw are Diagnos tics
Part V
Import Traces
28
5
SD Dev eloper Edition
Import Traces
After tracing y our application (see Trace Your Sy stem 's Behav ior), SD Dev Edition starts
autom atically . If this is the first trace, y ou need to create an SD project for y our current
Visual Studio solution.
For each recorded trace, the Im portDialog of SD Dev Edition autom atically pops up, which
im ports the trace into the SD Dev Edition database and prepares it for v isual analy sis.
If there are m any DLLs used by y our application, it m ight take a while until the debug
inform ation is loaded and the trace im port begins. The next trace im port will be m uch faster,
howev er, when the corresponding pdb files are cached by the operating sy stem 's disk caching
m echanism .
5.1
Create Project Dialog
When im porting the v ery first trace for y our current Visual Studio solution, the Create
Project Dialog pops up. Ty pically , y ou should keep the default v alues for "Nam e" and "Project
Folder". The "Source Folder" m ight be shortened to the root folder of y our source code. In the
case shown below, one would rem ov e the "win", for instance.
5.2
Import Dialog
After recording a trace, the Im port Dialog pops up. The dialog is used to choose the threads to
im port and to reduce the size of the trace. SD Dev Edition currently supports traces with a
m axim um size of 2 00.000 calls. Hence, y ou hav e to elim inate the functions with an
extraordinary high call count or polluting function v alue in the Im port Dialog .
© 2010 Softw are Diagnos tics
Import Traces
29
First, choose the threads to im port. Second, choose for ev ery thread which functions to
elim inate from the trace until each thread has a reasonably sm all num ber of calls.
There are three way s to elim inate functions:
Elim inate functions with polluting function v alues abov e a certain threshold. For this,
adjust the threshold v alue.
Elim inate functions with high call counts. For this, sort the list, m ark a function, hold the
shift key , m ark another function, and deselect the functions by pressing the "space" key .
Deselect indiv idual functions.
5.3
Manage and Delete Traces
In the m enu of SD Dev Edition y ou will find the Manage Traces Dialog.
© 2010 Softw are Diagnos tics
30
SD Dev eloper Edition
With it, y ou can rem ov e traces from y our SD project that belongs to y our current Visual
Studio solution.
Furtherm ore, y ou can m anually add traces. Traces are stored in %SD_TRACING%\logs\app.
exe\< tim estam p> . Choose a *.sdt to im port.
© 2010 Softw are Diagnos tics
Part VI
Visual Analysis
32
6
SD Dev eloper Edition
Visual Analysis
Im ported traces are v isualized by a set of sy nchronized v iews. The m ain v iews are the
CallStackView, the CallGraphView, and the SingleCallView. Furtherm ore, the SearchView is
helpful to quickly find entry points in the trace.
6.1
CallStackView
This v iew shows the trace in its tem poral order. In the upper, ov erv iew part, the com plete
trace is depicted. You can identify the different phases in the execution.
The lower part display s a tim e range in detail. For orientation, this tim e range is m arked in
the ov erv iew.
Tim e is display ed horizontally from left to right. Bars are function calls. They are stacked
which represents the call stack. In contrast to usual debuggers, this v iew perm its the call
stack to be analy zed not for a single point in tim e but for a full tim e range.
Using the m ouse wheel, y ou can seam lessly adjust the tim e range shown.
© 2010 Softw are Diagnos tics
V isual Analy sis
33
If Probes are recorded they are shown in the CallStackView, too.
DataProbes and Param Probes are attached to the calls as blue dots. Mem AccessProbes appear
on top; with the arrow sy m bol y ou can nav igate to the points in the execution where the
Mem AccessProbe was hit.
This v iew highlights all occurrences of a function that the m ouse is pointing to.
Right clicking on a function offers y ou a context m enu with options to nav igate in the
CallStackView, to create a call graph in the CallGraphView, to show the call in the
SingleCallView, or to jum p to Visual Studio's code v iew.
Execution tim e is not shown linearly . That is, y ou should use a different v iew if y ou
are interested in perform ance.
© 2010 Softw are Diagnos tics
34
6.2
SD Dev eloper Edition
CallGraphView
This v iew shows call relations between functions. Functions are em bedded into their m odule
structure, i.e., files and directories. Edges are annotated with inform ation on the relativ e call
costs and the call count.
Optionally , the call graph can be restricted to a specific tim e range. For this, use the context
m enu in the CallStackView. To rem ov e a tim e constraint, click on the button that appears in
the upper right corner of the CallGraphView.
Double-clicking on a function extends the graph by all called functions.
Double-clicking with the shift-key pressed, extends the graph by the functions that call
the function that is clicked.
6.3
SingleCallView
This v iew shows all calls for a call "foo()" that are triggered by it, in chronological order.
© 2010 Softw are Diagnos tics
V isual Analy sis
Hence, this is a condensed v isualization of the code with all loop structures enrolled by their
sequential execution order.
Cursor, enter, and backspace key s perm it y ou to nav igate to subcall or parent calls,
respectiv ely .
Right clicking on a function offers y ou a context m enu with options to nav igate in the
CallStackView, to create a call graph in the CallGraphView, to show the call in the
CallStackView, or to jum p to Visual Studio's code v iew.
6.4
SearchView
This v iew enables the quick nav igation within the execution to points of interest. All data
contained in a trace is searched including function nam es, file nam es, and probes.
Right clicking on a function or probes perm its y ou to focus other v iews on the selected
function or probe.
© 2010 Softw are Diagnos tics
35
Part VII
Tutorials
Tutorials
7
37
Tutorials
This chapter shows sev eral case studies in the form of short tutorials to illustrate how SD
Dev Edition can be applied to y our dev elopm ent process.
7.1
Bug: Erroneous Database Entry
Bug Description
Software Diagnostics Dev eloper Edition is applied during its own dev elopm ent. One of our
dev elopers noticed that the hierarchical structuring of directories in the call graph v iew was
wrong. Hence, he checked the database entry for the respectiv e directory “processrunner”
and saw that the entry “1 ” in the parent row was not correct (see screenshot).
Question and Hypothesis
Where in the code, when and why is this database entry set? During the im port of a trace (
import() ), there is a m ethod importFunctions() that indirectly also im ports directory
inform ation. The dev eloper's first guess was that the bug is located in this m ethod. The table
is filled with sev eral hundred entries. Hence, the database is accessed frequently when the
table is populated.
Approach with SD DevEdition
1 . Set breakpoint in m ethod import() (Microsoft Visual Studio).
2 . Open the FunctionSelector Dialog and ensure that the suspicious functions are activ ated
for tracing.
3 . Add a DataProbe to record the SQL com m ands that are passed to the database and open the
class that encapsulates the database com m unication in Microsoft Visual Studio :
void SQLiteImpl::execQuery(QSqlQuery& query, const QString& queryString)
{
query.exec(queryString);
lastInsertId_ = query.lastInsertId().toULongLong();
}
4 . On the code line query.exec() , right click to add a DataProbe.
5. In the dialog, choose to observ e the v ariable queryString.
© 2010 Softw are Diagnos tics
38
SD Dev eloper Edition
6 . Start the application in the usual debugging m ode of Microsoft Visual Studio [Menu> Debug-> Start Debugging].
7 . Interact with the application such that the im port trace feature is activ ated.
8. If the breakpoint is hit, the application stops in m ethod import().
9 . Perform a TraceOv er. Thereby , m ov e the stop breakpoint to the end of the import()
m ethod.
1 0. Trace without Param Probes
1 1 . Analy ze the resulting trace (~4 0.000 calls and 1 000 DataProbes were recorded):
Analysis results
Som e of the im portFunction() calls indirectly trigger insertDirectory () as hy pothesized
Search for “processrunner” to find the DataProbe records that are related to the wrong
database entry : this giv es us 6 DataProbe records - the last entry shows how the erroneous
database entry is inserted.
© 2010 Softw are Diagnos tics
Tutorials
39
Right click on the DataProbe record and choose “Jum p to tim e”.
The CallStackView shows an unexpected and surprising fact: the database entry is not
inserted as part of im portFunction() as hy pothesized but m uch earlier in the execution. The
entry com es in when a “PathAssignDialog” checks “include directories” - obv iously the bug
is located here.
Bug Solution
After that discov ery , the dev eloper set a breakpoint into the ok() m ethod of the
PathAssignDialog and continued usual debugging with Microsoft Visual Studio. He quickly
identified the erroneous logic and fixed the bug.
7.2
Bug: XML Content Written in Wrong Order
The open-source audio tool Audacity com prises approxim ately 2 00.000 lines-of-code. When
recording wav e data, it triggers an autosav e() function that autom atically stores the current
project settings. The settings are written into an XML file. Howev er, the XML content was
written in wrong order. SD Dev Edition was applied to analy ze the autosav e() function.
© 2010 Softw are Diagnos tics
40
SD Dev eloper Edition
The trace data for this tutorial is part of the installer of SD Dev Edition. You'll find it in
the help m enu.
Tracing
Audacity is started within the Microsoft Visual Studio debugger (F5). As we know, where the
autosav e() function is triggered, we set a breakpoint on the respectiv e code line.
When the execution hits the breakpoint, we press the Tracing icon in the Microsoft Visual
Studio SDAddin Toolbar. In the TraceOv er dialog, we define the tracing endpoint (line 4 2 9 1 ).
© 2010 Softw are Diagnos tics
Tutorials
41
As we know that autosav e() triggers less than 5.000 calls, we press "TraceOv er with Detailed
Param Probes".
After TraceOv er execution is stopped at the code line that was defined as tracing endpoint.
The Microsoft Visual Studio debugger is attached to the process and ready for further
com m ands.
Visual Analysis
© 2010 Softw are Diagnos tics
42
SD Dev eloper Edition
In the trace im port dialog, we do not exclude functions and im port the com plete trace.
Next, we analy ze in the CallStackView and the CallGraphView how the XML file is written.
By pointing on the blue Param Probes circles, we understand the order in which the strings
are written into the XML file. As we are in particular interested to understand the context of
writing the "http://audacity .sourceforge.net" string, we search for it in the SearchView, find
the Param Probe that contains the string, and jum p to the point in tim e where the
Param Probe was recorded v ia the context m enu on the search result.
© 2010 Softw are Diagnos tics
Tutorials
7.3
43
Feature Location: Privacy Data in Google Chrome
The source code of the open-source web browser Google Chrom e com prises approxim ately 4
m illion lines-of-code. We were interested how Chrom e collects priv acy data on the user's usage
behav ior. Hence, this tutorial reflects a ty pical "feature location" task: Find feature-relev ant
code in weakly -known code.
The trace data for this tutorial is part of the installer of SD Dev Edition. You'll find it in
the help m enu.
Traced Feature
Trace Chrom e while the user enables the priv acy data feature in the browser's options dialog.
© 2010 Softw are Diagnos tics
44
SD Dev eloper Edition
Visual Analysis
The trace rev eals that there are different execution phases. Below y ou see the internal
workings when the options dialog is painted.
In the search v iew, we ty pe "priv acy " to find any function that is related to priv acy data. We
obtain two results. Via the context m enu, we jum p to the point in tim e where ButtonPressed()
is called.
We quickly identify that the class MetricsServ ice is responsible for collecting usage behav ior.
This serv ice is started when the user enables the priv acy data feature.
© 2010 Softw are Diagnos tics
Tutorials
45
The CallGraphView helps to understand how the control flow is passed from the "button click"
to the start of the MetricsServ ice.
© 2010 Softw are Diagnos tics
Part VIII
Experimental Features
Ex perimental Features
8
47
Experimental Features
Som e of the features of SD Dev Edition are experim ental.
Tracing optim ized code:
Tracing y our application in the Release configuration m ight crash y our application in
specific circum stances. To av oid this, trace y our application in the Debug configuration.
Mem AccessProbes:
The size of the m em ory location that is observ ed by a Mem AccessProbe cannot be resolv ed
autom atically in specific circum stances. Setting a wrong size m ight cause SD Dev Edition to
ignore the Mem AccessProbe.
DataProbes on Global Variables:
Obtaining the list of global v ariables in the DataProbe dialog m ight take a long tim e.
© 2010 Softw are Diagnos tics
Part IX
Problems and Known Issues
Problems and Known Issues
9
49
Problems and Known Issues
Please send us an em ail if y ou hav e a feature request or any other idea to im prov e SD
Dev Edition: serv [email protected]
Possible Interferences with Other Development Tools
If y ou are using IncrediBuild (Xoreax Ltd.), y ou m ight need to disable its "distributed
linking" feature.
Tracing Issues
Tracing stops im m ediately after starting . There m ight be the error m essage that y our
application crashed.
Open folder %SD_TRACING%\logs\< y our-app> . Delete all *.cm d files.
Your app hangs and cannot be killed:
Kill all cdb processes.
After TraceOv er, Microsoft Visual Studio does not display the call stack and the threads
correctly :
Double-click on another thread and than on the original back. The call stack and thread
window is now as usual.
Another solution is to detach Microsoft Visual Studio from the process and attach it again.
The SolutionPreparation Dialog say s that y our Visual Studio Project Files are corrupt:
There are VS projects in y our VS solution that refer to VS configurations, e.g., Debug|x6 4 ,
that do not exist. Please open < %MS_VS%> 's configuration m anager dialog (in the build
m enu) dialog and check that all projects refer to v alid configurations.
Probes Issues
© 2010 Softw are Diagnos tics
50
SD Dev eloper Edition
DataProbes or Mem AccessProbes cannot be set:
You m ight try to set a Probe on a code line that is not part of the executable that is
currently set as StartUp Project y our Microsoft Visual Studio solution. Ensure that the
correct StartUp Project is chosen.
Additionally , DataProbes and Mem AccessProbes are not supported for dy nam ically loaded
DLLs at runtim e, e.g., with the LoadLibrary () Windows function.
DataProbes or Mem AccessProbes cannot be deleted:
Clicking on a Probe to delete it just toggles a usual breakpoint. Close the respectiv e file and
open it again. After this, deletion should work as expected.
Visual Analysis Issues
My sterious Call Relations:
If C+ + exceptions occurred during tracing, the call stack is not guaranteed to be recorded in
the correct order. Hence, y ou m ight see m y sterious call relations in the trace in these
situations.
The CallStackView or the CallGraphView is gone:
You can m ov e the line between the two v iews by dragging it with the m ouse. Mov ing the
line to the top fully hides the CallStackView. Mov ing it to the bottom hides the
CallGraphView. To m ake it v isible again, grab the line at the top or bottom , respectiv ely ,
and m ov e it to the center again. On som e Microsoft Windows platform s, the line is inv isible
(due to Windows standard GUI sty le).
The labels in the CallGraphView are distorted:
This is probably a problem of y our graphics card driv er. Please download the latest driv er
from the hom epage of y our graphics card v endor and install it. Another solution is to
disable 3 D graphics support in general or only for the executable "sd_tracer.exe", which is
placed in the %SD_HOME% folder. The option for disabling 3 D graphics support is ty pically
at the sam e dialog where y ou can change the screen resolution.
Call m arkers, DataProbes, and Mem AccessProbes are not shown in the Microsoft Visual
Studio code v iew:
Close the respectiv e source code file and open it again. You m ay open it with Microsoft
Visual Studio or v ia the context m enu on the respectiv e function or call in SD Dev Edition.
The context m enu entry for switching to Microsoft Visual Studio is m issing in the
CallStackView and the CallGraphView:
You hav e started SD Dev Edition as stand-alone tool. Close SD Dev Edition, start Microsoft
© 2010 Softw are Diagnos tics
Problems and Known Issues
51
Visual Studio, and start SD Dev Edition again by clicking the respectiv e icon in the toolbar.
© 2010 Softw are Diagnos tics
© 201 0 Software Diagnostics