OSDN Git Service

7a94336bf84b74b126b320c01aa572cf0238e626
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / doc / html / manual / profile_mode.html
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">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 32. Profile Mode</title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /><meta name="keywords" content="&#10;      C++&#10;    , &#10;      library&#10;    , &#10;      profile&#10;    " /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="extensions.html" title="Part XII.  Extensions" /><link rel="prev" href="bk01pt12ch31s05.html" title="Testing" /><link rel="next" href="bk01pt12ch32s02.html" title="Design" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 32. Profile Mode</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt12ch31s05.html">Prev</a> </td><th width="60%" align="center">Part XII. 
4   Extensions
5   
6 </th><td width="20%" align="right"> <a accesskey="n" href="bk01pt12ch32s02.html">Next</a></td></tr></table><hr /></div><div class="chapter" title="Chapter 32. Profile Mode"><div class="titlepage"><div><div><h2 class="title"><a id="manual.ext.profile_mode"></a>Chapter 32. Profile Mode</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="profile_mode.html#manual.ext.profile_mode.intro">Intro</a></span></dt><dd><dl><dt><span class="sect2"><a href="profile_mode.html#manual.ext.profile_mode.using">Using the Profile Mode</a></span></dt><dt><span class="sect2"><a href="profile_mode.html#manual.ext.profile_mode.tuning">Tuning the Profile Mode</a></span></dt></dl></dd><dt><span class="sect1"><a href="bk01pt12ch32s02.html">Design</a></span></dt><dd><dl><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.wrapper">Wrapper Model</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.instrumentation">Instrumentation</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.rtlib">Run Time Behavior</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.analysis">Analysis and Diagnostics</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.cost-model">Cost Model</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.reports">Reports</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s02.html#manual.ext.profile_mode.design.testing">Testing</a></span></dt></dl></dd><dt><span class="sect1"><a href="bk01pt12ch32s03.html">Extensions for Custom Containers</a></span></dt><dt><span class="sect1"><a href="bk01pt12ch32s04.html">Empirical Cost Model</a></span></dt><dt><span class="sect1"><a href="bk01pt12ch32s05.html">Implementation Issues</a></span></dt><dd><dl><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.stack">Stack Traces</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.symbols">Symbolization of Instruction Addresses</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.concurrency">Concurrency</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.stdlib-in-proflib">Using the Standard Library in the Instrumentation Implementation</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.malloc-hooks">Malloc Hooks</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s05.html#manual.ext.profile_mode.implementation.construction-destruction">Construction and Destruction of Global Objects</a></span></dt></dl></dd><dt><span class="sect1"><a href="bk01pt12ch32s06.html">Developer Information</a></span></dt><dd><dl><dt><span class="sect2"><a href="bk01pt12ch32s06.html#manual.ext.profile_mode.developer.bigpic">Big Picture</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s06.html#manual.ext.profile_mode.developer.howto">How To Add A Diagnostic</a></span></dt></dl></dd><dt><span class="sect1"><a href="bk01pt12ch32s07.html">Diagnostics</a></span></dt><dd><dl><dt><span class="sect2"><a href="bk01pt12ch32s07.html#manual.ext.profile_mode.analysis.template">Diagnostic Template</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s07.html#manual.ext.profile_mode.analysis.containers">Containers</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s07.html#manual.ext.profile_mode.analysis.algorithms">Algorithms</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s07.html#manual.ext.profile_mode.analysis.locality">Data Locality</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s07.html#manual.ext.profile_mode.analysis.mthread">Multithreaded Data Access</a></span></dt><dt><span class="sect2"><a href="bk01pt12ch32s07.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="sect1" title="Intro"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.ext.profile_mode.intro"></a>Intro</h2></div></div></div><p>
7   <span class="emphasis"><em>Goal: </em></span>Give performance improvement advice based on
8   recognition of suboptimal usage patterns of the standard library.
9   </p><p>
10   <span class="emphasis"><em>Method: </em></span>Wrap the standard library code.  Insert
11   calls to an instrumentation library to record the internal state of
12   various components at interesting entry/exit points to/from the standard
13   library.  Process trace, recognize suboptimal patterns, give advice.
14   For details, see 
15   <a class="ulink" href="http://dx.doi.org/10.1109/CGO.2009.36" target="_top">paper presented at
16    CGO 2009</a>.
17   </p><p>
18   <span class="emphasis"><em>Strengths: </em></span>
19 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
20   Unintrusive solution.  The application code does not require any 
21   modification.
22   </p></li><li class="listitem"><p> The advice is call context sensitive, thus capable of
23   identifying precisely interesting dynamic performance behavior.
24   </p></li><li class="listitem"><p>
25   The overhead model is pay-per-view.  When you turn off a diagnostic class
26   at compile time, its overhead disappears.
27   </p></li></ul></div><p>
28   </p><p>
29   <span class="emphasis"><em>Drawbacks: </em></span>
30 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
31   You must recompile the application code with custom options.
32   </p></li><li class="listitem"><p>You must run the application on representative input.
33   The advice is input dependent.
34   </p></li><li class="listitem"><p>
35   The execution time will increase, in some cases by factors.
36   </p></li></ul></div><p>
37   </p><div class="sect2" title="Using the Profile Mode"><div class="titlepage"><div><div><h3 class="title"><a id="manual.ext.profile_mode.using"></a>Using the Profile Mode</h3></div></div></div><p>
38   This is the anticipated common workflow for program <code class="code">foo.cc</code>:
39 </p><pre class="programlisting">
40 $ cat foo.cc
41 #include &lt;vector&gt;
42 int main() {
43   vector&lt;int&gt; v;
44   for (int k = 0; k &lt; 1024; ++k) v.insert(v.begin(), k);
45 }
46
47 $ g++ -D_GLIBCXX_PROFILE foo.cc
48 $ ./a.out
49 $ cat libstdcxx-profile.txt
50 vector-to-list: improvement = 5: call stack = 0x804842c ...
51     : advice = change std::vector to std::list
52 vector-size: improvement = 3: call stack = 0x804842c ...
53     : advice = change initial container size from 0 to 1024
54 </pre><p>
55   </p><p>
56   Anatomy of a warning:
57   </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
58   Warning id.  This is a short descriptive string for the class
59   that this warning belongs to.  E.g., "vector-to-list".
60   </p></li><li class="listitem"><p>
61   Estimated improvement.  This is an approximation of the benefit expected
62   from implementing the change suggested by the warning.  It is given on
63   a log10 scale.  Negative values mean that the alternative would actually
64   do worse than the current choice.
65   In the example above, 5 comes from the fact that the overhead of
66   inserting at the beginning of a vector vs. a list is around 1024 * 1024 / 2,
67   which is around 10e5.  The improvement from setting the initial size to
68   1024 is in the range of 10e3, since the overhead of dynamic resizing is
69   linear in this case.
70   </p></li><li class="listitem"><p>
71   Call stack.  Currently, the addresses are printed without
72   symbol name or code location attribution.
73   Users are expected to postprocess the output using, for instance, addr2line.
74   </p></li><li class="listitem"><p>
75   The warning message.  For some warnings, this is static text, e.g.,
76   "change vector to list".  For other warnings, such as the one above,
77   the message contains numeric advice, e.g., the suggested initial size
78   of the hashtable.
79   </p></li></ul></div><p>
80   </p><p>Two files are generated.  <code class="code">libstdcxx-profile.txt</code>
81    contains human readable advice.  <code class="code">libstdcxx-profile.raw</code>
82    contains implementation specific data about each diagnostic.
83    Their format is not documented.  They are sufficient to generate
84    all the advice given in <code class="code">libstdcxx-profile.txt</code>.  The advantage
85    of keeping this raw format is that traces from multiple executions can
86    be aggregated simply by concatenating the raw traces.  We intend to
87    offer an external utility program that can issue advice from a trace.
88   </p><p>Advice is given regardless whether the transformation is valid.
89   For instance, we advise changing a map to an unordered_map even if the
90   application semantics require that data be ordered.
91   We believe such warnings can help users understand the performance
92   behavior of their application better, which can lead to changes
93   at a higher abstraction level.
94   </p></div><div class="sect2" title="Tuning the Profile Mode"><div class="titlepage"><div><div><h3 class="title"><a id="manual.ext.profile_mode.tuning"></a>Tuning the Profile Mode</h3></div></div></div><p>Compile time switches and environment variables (see also file
95    profiler.h).  Unless specified otherwise, they can be set at compile time
96    using -D_&lt;name&gt; or by setting variable &lt;name&gt;
97    in the environment where the program is run, before starting execution.
98   </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
99    <code class="code">[NO]_GLIBCXX_PROFILE_&lt;diagnostic&gt;</code>:
100    enable/disable specific diagnostics.
101    See section Diagnostics for possible values.
102    (Environment variables not supported.)
103    </p></li><li class="listitem"><p>
104    <code class="code">GLIBCXX_PROFILE_TRACE_PATH_ROOT</code>: set an alternative root
105    path for the output files.
106    </p></li><li class="listitem"><p>GLIBCXX_PROFILE_MAX_WARN_COUNT: set it to the maximum
107    number of warnings desired.  The default value is 10.</p></li><li class="listitem"><p>
108    <code class="code">GLIBCXX_PROFILE_MAX_STACK_DEPTH</code>: if set to 0, 
109    the advice will
110    be collected and reported for the program as a whole, and not for each
111    call context.
112    This could also be used in continuous regression tests, where you
113    just need to know whether there is a regression or not.
114    The default value is 32.
115    </p></li><li class="listitem"><p>
116    <code class="code">GLIBCXX_PROFILE_MEM_PER_DIAGNOSTIC</code>:
117    set a limit on how much memory to use for the accounting tables for each
118    diagnostic type.  When this limit is reached, new events are ignored
119    until the memory usage decreases under the limit.  Generally, this means
120    that newly created containers will not be instrumented until some
121    live containers are deleted.  The default is 128 MB.
122    </p></li><li class="listitem"><p>
123    <code class="code">GLIBCXX_PROFILE_NOTHREADS</code>:
124    Make the library not use threads.  Otherwise, pthread mutexes are used
125    to protect access to internal data structures.  This should be useful
126    only if the program is single threaded and you want to avoid the overhead
127    of aquiring/releasing locks unnecessarily.
128    (Environment variable not supported.)
129    </p></li><li class="listitem"><p>
130    <code class="code">HAVE_EXECINFO_H</code>:
131    This name should be defined at library configuration time.
132    If your library was configured without <code class="code">execinfo.h</code>, but
133    you have it in your include path, you can define it explicitly.  Without
134    it, advice is collected for the program as a whole, and not for each
135    call context.
136    (Environment variable not supported.)
137    </p></li></ul></div><p>
138   </p></div></div><div class="bibliography" title="Bibliography"><div class="titlepage"><div><div><h2 class="title"><a id="profile_mode.biblio"></a>Bibliography</h2></div></div></div><div class="biblioentry" title="Perflint: A Context Sensitive Performance Advisor for C++ Programs"><a id="id447328"></a><p><span class="title"><i>
139       Perflint: A Context Sensitive Performance Advisor for C++ Programs
140     </i>. </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">
141         Proceedings of the 2009 International Symposium on Code Generation
142         and Optimization
143       . </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="bk01pt12ch31s05.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="bk01pt12ch32s02.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Testing </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Design</td></tr></table></div></body></html>