*: Regenerate.
[gcc.git] / libstdc++-v3 / doc / html / manual / bk01pt03ch19s02.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Design</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="
2 C++
3 ,
4 library
5 ,
6 profile
7 "><meta name="keywords" content="
8 ISO C++
9 ,
10 library
11 "><meta name="keywords" content="
12 ISO C++
13 ,
14 runtime
15 ,
16 library
17 "><link rel="home" href="../index.html" title="The GNU C++ Library"><link rel="up" href="profile_mode.html" title="Chapter 19. Profile Mode"><link rel="prev" href="profile_mode.html" title="Chapter 19. Profile Mode"><link rel="next" href="bk01pt03ch19s03.html" title="Extensions for Custom Containers"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Design</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="profile_mode.html">Prev</a> </td><th width="60%" align="center">Chapter 19. Profile Mode</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt03ch19s03.html">Next</a></td></tr></table><hr></div><div class="section" title="Design"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="manual.ext.profile_mode.design"></a>Design</h2></div></div></div><p>
18 </p><div class="table"><a name="id635111"></a><p class="title"><b>Table 19.1. Profile Code Location</b></p><div class="table-contents"><table summary="Profile Code Location" border="1"><colgroup><col align="left" class="c1"><col align="left" class="c2"></colgroup><thead><tr><th align="left">Code Location</th><th align="left">Use</th></tr></thead><tbody><tr><td align="left"><code class="code">libstdc++-v3/include/std/*</code></td><td align="left">Preprocessor code to redirect to profile extension headers.</td></tr><tr><td align="left"><code class="code">libstdc++-v3/include/profile/*</code></td><td align="left">Profile extension public headers (map, vector, ...).</td></tr><tr><td align="left"><code class="code">libstdc++-v3/include/profile/impl/*</code></td><td align="left">Profile extension internals. Implementation files are
19 only included from <code class="code">impl/profiler.h</code>, which is the only
20 file included from the public headers.</td></tr></tbody></table></div></div><br class="table-break"><p>
21 </p><div class="section" title="Wrapper Model"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.wrapper"></a>Wrapper Model</h3></div></div></div><p>
22 In order to get our instrumented library version included instead of the
23 release one,
24 we use the same wrapper model as the debug mode.
25 We subclass entities from the release version. Wherever
26 <code class="code">_GLIBCXX_PROFILE</code> is defined, the release namespace is
27 <code class="code">std::__norm</code>, whereas the profile namespace is
28 <code class="code">std::__profile</code>. Using plain <code class="code">std</code> translates
29 into <code class="code">std::__profile</code>.
30 </p><p>
31 Whenever possible, we try to wrap at the public interface level, e.g.,
32 in <code class="code">unordered_set</code> rather than in <code class="code">hashtable</code>,
33 in order not to depend on implementation.
34 </p><p>
35 Mixing object files built with and without the profile mode must
36 not affect the program execution. However, there are no guarantees to
37 the accuracy of diagnostics when using even a single object not built with
38 <code class="code">-D_GLIBCXX_PROFILE</code>.
39 Currently, mixing the profile mode with debug and parallel extensions is
40 not allowed. Mixing them at compile time will result in preprocessor errors.
41 Mixing them at link time is undefined.
42 </p></div><div class="section" title="Instrumentation"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.instrumentation"></a>Instrumentation</h3></div></div></div><p>
43 Instead of instrumenting every public entry and exit point,
44 we chose to add instrumentation on demand, as needed
45 by individual diagnostics.
46 The main reason is that some diagnostics require us to extract bits of
47 internal state that are particular only to that diagnostic.
48 We plan to formalize this later, after we learn more about the requirements
49 of several diagnostics.
50 </p><p>
51 All the instrumentation points can be switched on and off using
52 <code class="code">-D[_NO]_GLIBCXX_PROFILE_&lt;diagnostic&gt;</code> options.
53 With all the instrumentation calls off, there should be negligible
54 overhead over the release version. This property is needed to support
55 diagnostics based on timing of internal operations. For such diagnostics,
56 we anticipate turning most of the instrumentation off in order to prevent
57 profiling overhead from polluting time measurements, and thus diagnostics.
58 </p><p>
59 All the instrumentation on/off compile time switches live in
60 <code class="code">include/profile/profiler.h</code>.
61 </p></div><div class="section" title="Run Time Behavior"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.rtlib"></a>Run Time Behavior</h3></div></div></div><p>
62 For practical reasons, the instrumentation library processes the trace
63 partially
64 rather than dumping it to disk in raw form. Each event is processed when
65 it occurs. It is usually attached a cost and it is aggregated into
66 the database of a specific diagnostic class. The cost model
67 is based largely on the standard performance guarantees, but in some
68 cases we use knowledge about GCC's standard library implementation.
69 </p><p>
70 Information is indexed by (1) call stack and (2) instance id or address
71 to be able to understand and summarize precise creation-use-destruction
72 dynamic chains. Although the analysis is sensitive to dynamic instances,
73 the reports are only sensitive to call context. Whenever a dynamic instance
74 is destroyed, we accumulate its effect to the corresponding entry for the
75 call stack of its constructor location.
76 </p><p>
77 For details, see
78 <a class="link" href="http://dx.doi.org/10.1109/CGO.2009.36" target="_top">paper presented at
79 CGO 2009</a>.
80 </p></div><div class="section" title="Analysis and Diagnostics"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.analysis"></a>Analysis and Diagnostics</h3></div></div></div><p>
81 Final analysis takes place offline, and it is based entirely on the
82 generated trace and debugging info in the application binary.
83 See section Diagnostics for a list of analysis types that we plan to support.
84 </p><p>
85 The input to the analysis is a table indexed by profile type and call stack.
86 The data type for each entry depends on the profile type.
87 </p></div><div class="section" title="Cost Model"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.cost-model"></a>Cost Model</h3></div></div></div><p>
88 While it is likely that cost models become complex as we get into
89 more sophisticated analysis, we will try to follow a simple set of rules
90 at the beginning.
91 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><span class="emphasis"><em>Relative benefit estimation:</em></span>
92 The idea is to estimate or measure the cost of all operations
93 in the original scenario versus the scenario we advise to switch to.
94 For instance, when advising to change a vector to a list, an occurrence
95 of the <code class="code">insert</code> method will generally count as a benefit.
96 Its magnitude depends on (1) the number of elements that get shifted
97 and (2) whether it triggers a reallocation.
98 </p></li><li class="listitem"><p><span class="emphasis"><em>Synthetic measurements:</em></span>
99 We will measure the relative difference between similar operations on
100 different containers. We plan to write a battery of small tests that
101 compare the times of the executions of similar methods on different
102 containers. The idea is to run these tests on the target machine.
103 If this training phase is very quick, we may decide to perform it at
104 library initialization time. The results can be cached on disk and reused
105 across runs.
106 </p></li><li class="listitem"><p><span class="emphasis"><em>Timers:</em></span>
107 We plan to use timers for operations of larger granularity, such as sort.
108 For instance, we can switch between different sort methods on the fly
109 and report the one that performs best for each call context.
110 </p></li><li class="listitem"><p><span class="emphasis"><em>Show stoppers:</em></span>
111 We may decide that the presence of an operation nullifies the advice.
112 For instance, when considering switching from <code class="code">set</code> to
113 <code class="code">unordered_set</code>, if we detect use of operator <code class="code">++</code>,
114 we will simply not issue the advice, since this could signal that the use
115 care require a sorted container.</p></li></ul></div></div><div class="section" title="Reports"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.reports"></a>Reports</h3></div></div></div><p>
116 There are two types of reports. First, if we recognize a pattern for which
117 we have a substitute that is likely to give better performance, we print
118 the advice and estimated performance gain. The advice is usually associated
119 to a code position and possibly a call stack.
120 </p><p>
121 Second, we report performance characteristics for which we do not have
122 a clear solution for improvement. For instance, we can point to the user
123 the top 10 <code class="code">multimap</code> locations
124 which have the worst data locality in actual traversals.
125 Although this does not offer a solution,
126 it helps the user focus on the key problems and ignore the uninteresting ones.
127 </p></div><div class="section" title="Testing"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.design.testing"></a>Testing</h3></div></div></div><p>
128 First, we want to make sure we preserve the behavior of the release mode.
129 You can just type <code class="code">"make check-profile"</code>, which
130 builds and runs the whole test suite in profile mode.
131 </p><p>
132 Second, we want to test the correctness of each diagnostic.
133 We created a <code class="code">profile</code> directory in the test suite.
134 Each diagnostic must come with at least two tests, one for false positives
135 and one for false negatives.
136 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="profile_mode.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="profile_mode.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt03ch19s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 19. Profile Mode </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Extensions for Custom Containers</td></tr></table></div></body></html>