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