forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
145 lines
18 KiB
HTML
145 lines
18 KiB
HTML
<a name="EN-US_TOPIC_0000001233430143"></a><a name="EN-US_TOPIC_0000001233430143"></a>
|
|
|
|
<h1 class="topictitle1">Call Stack Recording Functions</h1>
|
|
<div id="body1599459477562"><p id="EN-US_TOPIC_0000001233430143__p848217410256">The <strong id="EN-US_TOPIC_0000001233430143__b18529131316311">pv_memory_profiling(type int)</strong> and environment variable <strong id="EN-US_TOPIC_0000001233430143__b1492121711319">MALLOC_CONF</strong> are used by <span id="EN-US_TOPIC_0000001233430143__text443568464">GaussDB(DWS)</span> to control the enabling and disabling of the memory allocation call stack recording module and the output of the memory call stack. The following figure illustrates the process.</p>
|
|
<p id="EN-US_TOPIC_0000001233430143__p2293185820247"><span><img id="EN-US_TOPIC_0000001233430143__image04663369277" src="figure/en-us_image_0000001188110590.png"></span></p>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430143__section6347191611619"><h4 class="sectiontitle">MALLOC_CONF</h4><p id="EN-US_TOPIC_0000001233430143__p18174334192016">The environment variable <strong id="EN-US_TOPIC_0000001233430143__b122482023193114">MALLOC_CONF</strong> is used to enable the monitoring module. It is in the <strong id="EN-US_TOPIC_0000001233430143__b1262431017329">${BIGDATA_HOME}/mppdb/.mppdbgs_profile</strong> file and is enabled by default. Note the following points: </p>
|
|
<ul id="EN-US_TOPIC_0000001233430143__ul1750118496207"><li id="EN-US_TOPIC_0000001233430143__li135027499201">Restart the database after modifying this environment variable.</li><li id="EN-US_TOPIC_0000001233430143__li81581746302">If <strong id="EN-US_TOPIC_0000001233430143__b34099917347">om_monitor</strong> is enabled in the cluster, restart the <strong id="EN-US_TOPIC_0000001233430143__b8538422193415">om_monitor</strong> process and then the database after setting this environment variable, so that the setting can take effect. </li><li id="EN-US_TOPIC_0000001233430143__li142761071325">This environment variable can be set on all servers in the cluster or on some servers where the module needs to be enabled. For the GaussDB process, each process determines whether to enable the module based on the <strong id="EN-US_TOPIC_0000001233430143__b185811426386">MALLOC_CONF</strong> environment variable.</li></ul>
|
|
<p id="EN-US_TOPIC_0000001233430143__p3634177153413">Commands for enabling and disabling <strong id="EN-US_TOPIC_0000001233430143__b26077133912">MALLOC_CONF</strong>:</p>
|
|
<ul id="EN-US_TOPIC_0000001233430143__ul184481517144111"><li id="EN-US_TOPIC_0000001233430143__li10448131712414">Enabling the monitoring module:<pre class="screen" id="EN-US_TOPIC_0000001233430143__screen18168175015189">export MALLOC_CONF=prof:true</pre>
|
|
</li><li id="EN-US_TOPIC_0000001233430143__li1151772519413">Disabling the monitoring module:<pre class="screen" id="EN-US_TOPIC_0000001233430143__screen64439230347">export MALLOC_CONF=prof:false</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430143__section130612653215"><h4 class="sectiontitle">pv_memory_profiling (type int)</h4><p id="EN-US_TOPIC_0000001233430143__p171911547153615">Parameter description: Controls the backtrace recording and output of memory allocation functions such as <strong id="EN-US_TOPIC_0000001233430143__b01508106401">malloc</strong> in the kernel.</p>
|
|
<p id="EN-US_TOPIC_0000001233430143__p686116306476">Value range: a positive integer from 0 to 3.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233430143__table15845932133314" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Values and descriptions of <strong id="EN-US_TOPIC_0000001233430143__b2527102254117">pv_memory_profile</strong></caption><thead align="left"><tr id="EN-US_TOPIC_0000001233430143__row19846183253313"><th align="left" class="cellrowborder" valign="top" width="26.179999999999996%" id="mcps1.3.4.4.2.3.1.1"><p id="EN-US_TOPIC_0000001233430143__p984615327338">pv_memory_profiling</p>
|
|
<p id="EN-US_TOPIC_0000001233430143__p48461732163315">Value</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="73.82%" id="mcps1.3.4.4.2.3.1.2"><p id="EN-US_TOPIC_0000001233430143__p284743263318">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001233430143__row1484711324334"><td class="cellrowborder" valign="top" width="26.179999999999996%" headers="mcps1.3.4.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001233430143__p20847163273316">0</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="73.82%" headers="mcps1.3.4.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001233430143__p15847133223313">Disables the memory trace function and does not record information of call stacks such as <strong id="EN-US_TOPIC_0000001233430143__b83181269428">malloc</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430143__row1084711320334"><td class="cellrowborder" valign="top" width="26.179999999999996%" headers="mcps1.3.4.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001233430143__p19847153219339">1</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="73.82%" headers="mcps1.3.4.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001233430143__p15848332143313">Enables the memory trace function to record information of call stacks such as <strong id="EN-US_TOPIC_0000001233430143__b63284408429">malloc</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430143__row1584893212331"><td class="cellrowborder" valign="top" width="26.179999999999996%" headers="mcps1.3.4.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001233430143__p684820324339">2</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="73.82%" headers="mcps1.3.4.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001233430143__p184817324331">Outputs trace logs of call stacks such as <strong id="EN-US_TOPIC_0000001233430143__b1687192414432">malloc</strong>.</p>
|
|
<ul id="EN-US_TOPIC_0000001233430143__ul154871619344"><li id="EN-US_TOPIC_0000001233430143__li16488169342">Output path: <strong id="EN-US_TOPIC_0000001233430143__b0136131994411">/proc/</strong><em id="EN-US_TOPIC_0000001233430143__i73839211449">pid</em><strong id="EN-US_TOPIC_0000001233430143__b71902248441">/cwd</strong> directory. <em id="EN-US_TOPIC_0000001233430143__i06381229174416">pid</em> indicates the ID of the GaussDB process.</li><li id="EN-US_TOPIC_0000001233430143__li4879141919346">Output log name format: <strong id="EN-US_TOPIC_0000001233430143__b1819134664717">jeprof.<</strong><em id="EN-US_TOPIC_0000001233430143__i20192246104713">pid</em><strong id="EN-US_TOPIC_0000001233430143__b0192146104715">>.</strong><em id="EN-US_TOPIC_0000001233430143__i20192144616477">*</em><strong id="EN-US_TOPIC_0000001233430143__b1619314466472">.heap</strong>, where <em id="EN-US_TOPIC_0000001233430143__i12193134613474">pid</em> indicates the ID of the GaussDB process and <em id="EN-US_TOPIC_0000001233430143__i18193946174712">*</em> indicates the unique sequence number of the output trace log, for example, <strong id="EN-US_TOPIC_0000001233430143__b15749256114712">jeprof.195473.0.u0.heap</strong>.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430143__row2084843218336"><td class="cellrowborder" valign="top" width="26.179999999999996%" headers="mcps1.3.4.4.2.3.1.1 "><p id="EN-US_TOPIC_0000001233430143__p184843253310">3</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="73.82%" headers="mcps1.3.4.4.2.3.1.2 "><p id="EN-US_TOPIC_0000001233430143__p17849183214334">Outputs memory statistics.</p>
|
|
<ul id="EN-US_TOPIC_0000001233430143__ul050684816357"><li id="EN-US_TOPIC_0000001233430143__li45061948193511">Output path: <strong id="EN-US_TOPIC_0000001233430143__b173794551466">/proc/</strong><em id="EN-US_TOPIC_0000001233430143__i53791055144612">pid</em><strong id="EN-US_TOPIC_0000001233430143__b1938075534617">/cwd</strong> directory. <em id="EN-US_TOPIC_0000001233430143__i13380955104619">pid</em> indicates the ID of the GaussDB process.</li><li id="EN-US_TOPIC_0000001233430143__li1585381133617">Log name format: <em id="EN-US_TOPIC_0000001233430143__i132391540184710">Node name</em> + <em id="EN-US_TOPIC_0000001233430143__i340813453478">Process ID</em> + <em id="EN-US_TOPIC_0000001233430143__i104871648194719">Time</em> + <strong id="EN-US_TOPIC_0000001233430143__b192075715478">heap_stats</strong> + <strong id="EN-US_TOPIC_0000001233430143__b20690180114816">.out</strong>. You can use vim to open the file.</li></ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001233430143__p11353182719379">Return type: Boolean</p>
|
|
<p id="EN-US_TOPIC_0000001233430143__p373863612383">Note:</p>
|
|
<ul id="EN-US_TOPIC_0000001233430143__ul1659894217366"><li id="EN-US_TOPIC_0000001233430143__li1748654133910">If the function is called successfully, <strong id="EN-US_TOPIC_0000001233430143__b17768183154917">true</strong> is returned. Otherwise, <strong id="EN-US_TOPIC_0000001233430143__b344163616498">false</strong> is returned.</li><li id="EN-US_TOPIC_0000001233430143__li14773131653918">If <strong id="EN-US_TOPIC_0000001233430143__b133683535497">Memory profiling failed, check if $MALLOC_CONF contain 'prof:true'.</strong> is displayed, it indicates that the module is used when <strong id="EN-US_TOPIC_0000001233430143__b076961617500">MALLOC_CONF=prof:true</strong> is not set. In this case, you need to set the environment variable.</li><li id="EN-US_TOPIC_0000001233430143__li1877391616397">If <strong id="EN-US_TOPIC_0000001233430143__b13897735165015">Type %d is not supported. The valid range is 0-3.</strong> is displayed, the parameter value is incorrect. The correct values are <strong id="EN-US_TOPIC_0000001233430143__b13532103145117">0</strong>, <strong id="EN-US_TOPIC_0000001233430143__b10538133395118">1</strong>, <strong id="EN-US_TOPIC_0000001233430143__b234510359518">2</strong>, and <strong id="EN-US_TOPIC_0000001233430143__b945803818519">3</strong>.</li><li id="EN-US_TOPIC_0000001233430143__li1598174283619">If <strong id="EN-US_TOPIC_0000001233430143__b7946175325119">Memory profiling failed, inputed type is %d, failed number is %d.</strong> is displayed, contact technical support for assistance.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430143__section21664123158"><h4 class="sectiontitle">Outputting Memory Call Stack Information</h4><p id="EN-US_TOPIC_0000001233430143__p11915135151714">Procedure:</p>
|
|
<ol id="EN-US_TOPIC_0000001233430143__ol12919410131712"><li id="EN-US_TOPIC_0000001233430143__li119191910111712"><span>Execute the following statement to output the memory call stack information and output the <strong id="EN-US_TOPIC_0000001233430143__b1749043211538">trace</strong> file in the directory where the GaussDB process is located:</span><p><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430143__screen92911826191710"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">pv_memory_profiling</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</p></li><li id="EN-US_TOPIC_0000001233430143__li156101819171717"><span>Use the jeprof tool provided by jemalloc to parse log information.</span><p><div class="p" id="EN-US_TOPIC_0000001233430143__p996193361911">Method 1: Output in text format.<pre class="screen" id="EN-US_TOPIC_0000001233430143__screen198728512198">jeprof --text --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 >prof.txt</pre>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001233430143__p7888184912193">Method 2: Export the report in PDF format.</p>
|
|
<pre class="screen" id="EN-US_TOPIC_0000001233430143__screen19901710122012">jeprof --pdf --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 > prof.pdf</pre>
|
|
<div class="note" id="EN-US_TOPIC_0000001233430143__note20310240154214"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001233430143__ul15311940134219"><li id="EN-US_TOPIC_0000001233430143__li197891737122311">To parse the memory call stack information, you need to use the GaussDB source code for analysis. You need to send the <strong id="EN-US_TOPIC_0000001233430143__b158506491194">trace</strong> file to R&D engineers for analysis.</li><li id="EN-US_TOPIC_0000001233430143__li14311144004217">To analyze the <strong id="EN-US_TOPIC_0000001233430143__b1173220225510">trace</strong> file, you need to use the jeprof tool, which is generated by jemalloc. The Perl environment is required for using the tool. To generate PDF calling diagrams, you need to install the GraphViz tool that matches the OS.</li></ul>
|
|
</div></div>
|
|
</p></li></ol>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430143__section316154111598"><h4 class="sectiontitle">Example</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430143__screen910012521244"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
|
<span class="normal"> 2</span>
|
|
<span class="normal"> 3</span>
|
|
<span class="normal"> 4</span>
|
|
<span class="normal"> 5</span>
|
|
<span class="normal"> 6</span>
|
|
<span class="normal"> 7</span>
|
|
<span class="normal"> 8</span>
|
|
<span class="normal"> 9</span>
|
|
<span class="normal">10</span>
|
|
<span class="normal">11</span>
|
|
<span class="normal">12</span>
|
|
<span class="normal">13</span>
|
|
<span class="normal">14</span>
|
|
<span class="normal">15</span>
|
|
<span class="normal">16</span>
|
|
<span class="normal">17</span>
|
|
<span class="normal">18</span>
|
|
<span class="normal">19</span>
|
|
<span class="normal">20</span>
|
|
<span class="normal">21</span>
|
|
<span class="normal">22</span>
|
|
<span class="normal">23</span>
|
|
<span class="normal">24</span>
|
|
<span class="normal">25</span>
|
|
<span class="normal">26</span>
|
|
<span class="normal">27</span>
|
|
<span class="normal">28</span>
|
|
<span class="normal">29</span>
|
|
<span class="normal">30</span>
|
|
<span class="normal">31</span>
|
|
<span class="normal">32</span>
|
|
<span class="normal">33</span>
|
|
<span class="normal">34</span>
|
|
<span class="normal">35</span></pre></div></td><td class="code"><div><pre><span></span><span class="c1">-- Log in as the system administrator, set environment variables, and start the database.</span>
|
|
<span class="n">export</span><span class="w"> </span><span class="n">MALLOC_CONF</span><span class="o">=</span><span class="n">prof</span><span class="p">:</span><span class="k">true</span>
|
|
|
|
<span class="c1">-- Disable the memory trace recording function when the database is running.</span>
|
|
<span class="k">SELECT</span><span class="w"> </span><span class="n">pv_memory_profiling</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
|
|
<span class="n">pv_memory_profiling</span>
|
|
<span class="c1">----------------------------</span>
|
|
<span class="n">t</span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span>
|
|
|
|
<span class="c1">-- Enable the memory trace recording function when the database is running.</span>
|
|
<span class="k">SELECT</span><span class="w"> </span><span class="n">pv_memory_profiling</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
|
<span class="n">pv_memory_profiling</span>
|
|
<span class="c1">----------------------------</span>
|
|
<span class="n">t</span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span>
|
|
|
|
<span class="c1">-- Output memory trace records.</span>
|
|
<span class="k">SELECT</span><span class="w"> </span><span class="n">pv_memory_profiling</span><span class="p">(</span><span class="mi">2</span><span class="p">);</span>
|
|
<span class="n">pv_memory_profiling</span>
|
|
<span class="c1">----------------------------</span>
|
|
<span class="n">t</span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span>
|
|
|
|
<span class="c1">-- Generate the trace file in text or PDF format in the directory where the GaussDB process is located.</span>
|
|
<span class="n">jeprof</span><span class="w"> </span><span class="c1">--text --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 >prof.txt</span>
|
|
<span class="n">jeprof</span><span class="w"> </span><span class="c1">--pdf --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 > prof.pdf</span>
|
|
|
|
<span class="c1">-- Output memory statistics.</span>
|
|
<span class="k">Execute</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">following</span><span class="w"> </span><span class="k">statement</span><span class="w"> </span><span class="k">to</span><span class="w"> </span><span class="n">generate</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">memory</span><span class="w"> </span><span class="k">statistics</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">directory</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">GaussDB</span><span class="w"> </span><span class="n">process</span><span class="w"> </span><span class="k">is</span><span class="w"> </span><span class="n">located</span><span class="p">.</span><span class="w"> </span><span class="n">The</span><span class="w"> </span><span class="n">file</span><span class="w"> </span><span class="n">can</span><span class="w"> </span><span class="n">be</span><span class="w"> </span><span class="n">directly</span><span class="w"> </span><span class="k">read</span><span class="p">.</span>
|
|
<span class="k">SELECT</span><span class="w"> </span><span class="n">pv_memory_profiling</span><span class="p">(</span><span class="mi">3</span><span class="p">);</span>
|
|
<span class="n">pv_memory_profiling</span>
|
|
<span class="c1">----------------------------</span>
|
|
<span class="n">t</span>
|
|
<span class="p">(</span><span class="mi">1</span><span class="w"> </span><span class="k">row</span><span class="p">)</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0027.html">Functions and Operators</a></div>
|
|
</div>
|
|
</div>
|
|
|