*: Regenerate.
[gcc.git] / libstdc++-v3 / doc / html / manual / profile_mode.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Chapter 19. Profile Mode</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="extensions.html" title="Part III.  Extensions"><link rel="prev" href="bk01pt03ch18s05.html" title="Testing"><link rel="next" href="bk01pt03ch19s02.html" title="Design"></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">Chapter 19. Profile Mode</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt03ch18s05.html">Prev</a> </td><th width="60%" align="center">Part III. 
18 Extensions
19
20 </th><td width="20%" align="right"> <a accesskey="n" href="bk01pt03ch19s02.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter 19. Profile Mode"><div class="titlepage"><div><div><h2 class="title"><a name="manual.ext.profile_mode"></a>Chapter 19. Profile Mode</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="profile_mode.html#manual.ext.profile_mode.intro">Intro</a></span></dt><dd><dl><dt><span class="section"><a href="profile_mode.html#manual.ext.profile_mode.using">Using the Profile Mode</a></span></dt><dt><span class="section"><a href="profile_mode.html#manual.ext.profile_mode.tuning">Tuning the Profile Mode</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s02.html">Design</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.wrapper">Wrapper Model</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.instrumentation">Instrumentation</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.rtlib">Run Time Behavior</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.analysis">Analysis and Diagnostics</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.cost-model">Cost Model</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.reports">Reports</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s02.html#manual.ext.profile_mode.design.testing">Testing</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s03.html">Extensions for Custom Containers</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s04.html">Empirical Cost Model</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html">Implementation Issues</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.stack">Stack Traces</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.symbols">Symbolization of Instruction Addresses</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.concurrency">Concurrency</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.stdlib-in-proflib">Using the Standard Library in the Instrumentation Implementation</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.malloc-hooks">Malloc Hooks</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s05.html#manual.ext.profile_mode.implementation.construction-destruction">Construction and Destruction of Global Objects</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s06.html">Developer Information</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s06.html#manual.ext.profile_mode.developer.bigpic">Big Picture</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s06.html#manual.ext.profile_mode.developer.howto">How To Add A Diagnostic</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s07.html">Diagnostics</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.template">Diagnostic Template</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.containers">Containers</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.hashtable_too_small">Hashtable Too Small</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.hashtable_too_large">Hashtable Too Large</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.inefficient_hash">Inefficient Hash</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.vector_too_small">Vector Too Small</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.vector_too_large">Vector Too Large</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.vector_to_hashtable">Vector to Hashtable</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.hashtable_to_vector">Hashtable to Vector</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.vector_to_list">Vector to List</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.list_to_vector">List to Vector</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.list_to_slist">List to Forward List (Slist)</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.assoc_ord_to_unord">Ordered to Unordered Associative Container</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.algorithms">Algorithms</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.algorithms.sort">Sort Algorithm Performance</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.locality">Data Locality</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.locality.sw_prefetch">Need Software Prefetch</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.locality.linked">Linked Structure Locality</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.mthread">Multithreaded Data Access</a></span></dt><dd><dl><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.mthread.ddtest">Data Dependence Violations at Container Level</a></span></dt><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.mthread.false_share">False Sharing</a></span></dt></dl></dd><dt><span class="section"><a href="bk01pt03ch19s07.html#manual.ext.profile_mode.analysis.statistics">Statistics</a></span></dt></dl></dd><dt><span class="bibliography"><a href="profile_mode.html#profile_mode.biblio">Bibliography</a></span></dt></dl></div><div class="section" title="Intro"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="manual.ext.profile_mode.intro"></a>Intro</h2></div></div></div><p>
21 <span class="emphasis"><em>Goal: </em></span>Give performance improvement advice based on
22 recognition of suboptimal usage patterns of the standard library.
23 </p><p>
24 <span class="emphasis"><em>Method: </em></span>Wrap the standard library code. Insert
25 calls to an instrumentation library to record the internal state of
26 various components at interesting entry/exit points to/from the standard
27 library. Process trace, recognize suboptimal patterns, give advice.
28 For details, see
29 <a class="link" href="http://dx.doi.org/10.1109/CGO.2009.36" target="_top">paper presented at
30 CGO 2009</a>.
31 </p><p>
32 <span class="emphasis"><em>Strengths: </em></span>
33 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
34 Unintrusive solution. The application code does not require any
35 modification.
36 </p></li><li class="listitem"><p> The advice is call context sensitive, thus capable of
37 identifying precisely interesting dynamic performance behavior.
38 </p></li><li class="listitem"><p>
39 The overhead model is pay-per-view. When you turn off a diagnostic class
40 at compile time, its overhead disappears.
41 </p></li></ul></div><p>
42 </p><p>
43 <span class="emphasis"><em>Drawbacks: </em></span>
44 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
45 You must recompile the application code with custom options.
46 </p></li><li class="listitem"><p>You must run the application on representative input.
47 The advice is input dependent.
48 </p></li><li class="listitem"><p>
49 The execution time will increase, in some cases by factors.
50 </p></li></ul></div><p>
51 </p><div class="section" title="Using the Profile Mode"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.using"></a>Using the Profile Mode</h3></div></div></div><p>
52 This is the anticipated common workflow for program <code class="code">foo.cc</code>:
53 </p><pre class="programlisting">
54 $ cat foo.cc
55 #include &lt;vector&gt;
56 int main() {
57 vector&lt;int&gt; v;
58 for (int k = 0; k &lt; 1024; ++k) v.insert(v.begin(), k);
59 }
60
61 $ g++ -D_GLIBCXX_PROFILE foo.cc
62 $ ./a.out
63 $ cat libstdcxx-profile.txt
64 vector-to-list: improvement = 5: call stack = 0x804842c ...
65 : advice = change std::vector to std::list
66 vector-size: improvement = 3: call stack = 0x804842c ...
67 : advice = change initial container size from 0 to 1024
68 </pre><p>
69 </p><p>
70 Anatomy of a warning:
71 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
72 Warning id. This is a short descriptive string for the class
73 that this warning belongs to. E.g., "vector-to-list".
74 </p></li><li class="listitem"><p>
75 Estimated improvement. This is an approximation of the benefit expected
76 from implementing the change suggested by the warning. It is given on
77 a log10 scale. Negative values mean that the alternative would actually
78 do worse than the current choice.
79 In the example above, 5 comes from the fact that the overhead of
80 inserting at the beginning of a vector vs. a list is around 1024 * 1024 / 2,
81 which is around 10e5. The improvement from setting the initial size to
82 1024 is in the range of 10e3, since the overhead of dynamic resizing is
83 linear in this case.
84 </p></li><li class="listitem"><p>
85 Call stack. Currently, the addresses are printed without
86 symbol name or code location attribution.
87 Users are expected to postprocess the output using, for instance, addr2line.
88 </p></li><li class="listitem"><p>
89 The warning message. For some warnings, this is static text, e.g.,
90 "change vector to list". For other warnings, such as the one above,
91 the message contains numeric advice, e.g., the suggested initial size
92 of the vector.
93 </p></li></ul></div><p>
94 </p><p>Three files are generated. <code class="code">libstdcxx-profile.txt</code>
95 contains human readable advice. <code class="code">libstdcxx-profile.raw</code>
96 contains implementation specific data about each diagnostic.
97 Their format is not documented. They are sufficient to generate
98 all the advice given in <code class="code">libstdcxx-profile.txt</code>. The advantage
99 of keeping this raw format is that traces from multiple executions can
100 be aggregated simply by concatenating the raw traces. We intend to
101 offer an external utility program that can issue advice from a trace.
102 <code class="code">libstdcxx-profile.conf.out</code> lists the actual diagnostic
103 parameters used. To alter parameters, edit this file and rename it to
104 <code class="code">libstdcxx-profile.conf</code>.
105 </p><p>Advice is given regardless whether the transformation is valid.
106 For instance, we advise changing a map to an unordered_map even if the
107 application semantics require that data be ordered.
108 We believe such warnings can help users understand the performance
109 behavior of their application better, which can lead to changes
110 at a higher abstraction level.
111 </p></div><div class="section" title="Tuning the Profile Mode"><div class="titlepage"><div><div><h3 class="title"><a name="manual.ext.profile_mode.tuning"></a>Tuning the Profile Mode</h3></div></div></div><p>Compile time switches and environment variables (see also file
112 profiler.h). Unless specified otherwise, they can be set at compile time
113 using -D_&lt;name&gt; or by setting variable &lt;name&gt;
114 in the environment where the program is run, before starting execution.
115 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
116 <code class="code">_GLIBCXX_PROFILE_NO_&lt;diagnostic&gt;</code>:
117 disable specific diagnostics.
118 See section Diagnostics for possible values.
119 (Environment variables not supported.)
120 </p></li><li class="listitem"><p>
121 <code class="code">_GLIBCXX_PROFILE_TRACE_PATH_ROOT</code>: set an alternative root
122 path for the output files.
123 </p></li><li class="listitem"><p>_GLIBCXX_PROFILE_MAX_WARN_COUNT: set it to the maximum
124 number of warnings desired. The default value is 10.</p></li><li class="listitem"><p>
125 <code class="code">_GLIBCXX_PROFILE_MAX_STACK_DEPTH</code>: if set to 0,
126 the advice will
127 be collected and reported for the program as a whole, and not for each
128 call context.
129 This could also be used in continuous regression tests, where you
130 just need to know whether there is a regression or not.
131 The default value is 32.
132 </p></li><li class="listitem"><p>
133 <code class="code">_GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC</code>:
134 set a limit on how much memory to use for the accounting tables for each
135 diagnostic type. When this limit is reached, new events are ignored
136 until the memory usage decreases under the limit. Generally, this means
137 that newly created containers will not be instrumented until some
138 live containers are deleted. The default is 128 MB.
139 </p></li><li class="listitem"><p>
140 <code class="code">_GLIBCXX_PROFILE_NO_THREADS</code>:
141 Make the library not use threads. If thread local storage (TLS) is not
142 available, you will get a preprocessor error asking you to set
143 -D_GLIBCXX_PROFILE_NO_THREADS if your program is single-threaded.
144 Multithreaded execution without TLS is not supported.
145 (Environment variable not supported.)
146 </p></li><li class="listitem"><p>
147 <code class="code">_GLIBCXX_HAVE_EXECINFO_H</code>:
148 This name should be defined automatically at library configuration time.
149 If your library was configured without <code class="code">execinfo.h</code>, but
150 you have it in your include path, you can define it explicitly. Without
151 it, advice is collected for the program as a whole, and not for each
152 call context.
153 (Environment variable not supported.)
154 </p></li></ul></div><p>
155 </p></div></div><div class="bibliography" title="Bibliography"><div class="titlepage"><div><div><h2 class="title"><a name="profile_mode.biblio"></a>Bibliography</h2></div></div></div><div class="biblioentry"><a name="id638547"></a><p><span class="citetitle"><em class="citetitle">
156 Perflint: A Context Sensitive Performance Advisor for C++ Programs
157 </em>. </span><span class="author"><span class="firstname">Lixia</span> <span class="surname">Liu</span>. </span><span class="author"><span class="firstname">Silvius</span> <span class="surname">Rus</span>. </span><span class="copyright">Copyright © 2009 . </span><span class="publisher"><span class="publishername">
158 Proceedings of the 2009 International Symposium on Code Generation
159 and Optimization
160 . </span></span></p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt03ch18s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="extensions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt03ch19s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Testing </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Design</td></tr></table></div></body></html>