📄 profile.html
字号:
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>DBI::Profile - Performance profiling and benchmarking for the DBI</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>DBI::Profile - Performance profiling and benchmarking for the DBI</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#overview">OVERVIEW</a></li>
<li><a href="#enabling_a_profile">ENABLING A PROFILE</a></li>
<li><a href="#the_profile_object">THE PROFILE OBJECT</a></li>
<ul>
<li><a href="#data">Data</a></li>
<li><a href="#path">Path</a></li>
</ul>
<li><a href="#reporting">REPORTING</a></li>
<ul>
<li><a href="#report_format">Report Format</a></li>
<li><a href="#report_destination">Report Destination</a></li>
</ul>
<li><a href="#child_handles">CHILD HANDLES</a></li>
<li><a href="#custom_data_manipulation">CUSTOM DATA MANIPULATION</a></li>
<ul>
<li><a href="#dbi_profile_merge">dbi_profile_merge</a></li>
</ul>
<li><a href="#custom_data_collection">CUSTOM DATA COLLECTION</a></li>
<ul>
<li><a href="#using_the_path_attribute">Using The Path Attribute</a></li>
<li><a href="#adding_your_own_samples">Adding Your Own Samples</a></li>
</ul>
<li><a href="#subclassing">SUBCLASSING</a></li>
<li><a href="#caveats">CAVEATS</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>DBI::Profile - Performance profiling and benchmarking for the DBI</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<p>The easiest way to enable DBI profiling is to set the DBI_PROFILE
environment variable to 2 and then run your code as usual:</p>
<pre>
DBI_PROFILE=2 prog.pl</pre>
<p>This will profile your program and then output a textual summary
grouped by query when the program exits. You can also enable profiling by
setting the Profile attribute of any DBI handle:</p>
<pre>
<span class="variable">$dbh</span><span class="operator">-></span><span class="operator">{</span><span class="string">Profile</span><span class="operator">}</span> <span class="operator">=</span> <span class="number">2</span><span class="operator">;</span>
</pre>
<p>Then the summary will be printed when the handle is destroyed.</p>
<p>Many other values apart from are possible - see <a href="#enabling_a_profile">ENABLING A PROFILE</a> below.</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>The DBI::Profile module provides a simple interface to collect and
report performance and benchmarking data from the DBI.</p>
<p>For a more elaborate interface, suitable for larger programs, see
<a href="../../lib/DBI/ProfileDumper.html">DBI::ProfileDumper</a> and <a href="../../bin/dbiprof.html">dbiprof</a>.
For Apache/mod_perl applications see
<a href="../../lib/DBI/ProfileDumper/Apache.html">DBI::ProfileDumper::Apache</a>.</p>
<p>
</p>
<hr />
<h1><a name="overview">OVERVIEW</a></h1>
<p>Performance data collection for the DBI is built around several
concepts which are important to understand clearly.</p>
<dl>
<dt><strong><a name="item_method_dispatch">Method Dispatch</a></strong>
<dd>
<p>Every method call on a DBI handle passes through a single 'dispatch'
function which manages all the common aspects of DBI method calls,
such as handling the RaiseError attribute.</p>
</dd>
</li>
<dt><strong><a name="item_data_collection">Data Collection</a></strong>
<dd>
<p>If profiling is enabled for a handle then the dispatch code takes
a high-resolution timestamp soon after it is entered. Then, after
calling the appropriate method and just before returning, it takes
another high-resolution timestamp and calls a function to record
the information. That function is passed the two timestamps
plus the DBI handle and the name of the method that was called.
That data about a single DBI method call is called a <em>profile sample</em>.</p>
</dd>
</li>
<dt><strong><a name="item_data_filtering">Data Filtering</a></strong>
<dd>
<p>If the method call was invoked by the DBI or by a driver then the call is
ignored for profiling because the time spent will be accounted for by the
original 'outermost' call for your code.</p>
</dd>
<dd>
<p>For example, the calls that the <code>selectrow_arrayref()</code> method makes
to <code>prepare()</code> and <code>execute()</code> etc. are not counted individually
because the time spent in those methods is going to be allocated
to the <code>selectrow_arrayref()</code> method when it returns. If this was not
done then it would be very easy to double count time spent inside
the DBI.</p>
</dd>
</li>
<dt><strong><a name="item_data_storage_tree">Data Storage Tree</a></strong>
<dd>
<p>The profile data is accumulated as 'leaves on a tree'. The 'path' through the
branches of the tree to a particular leaf is determined dynamically for each sample.
This is a key feature of DBI profiliing.</p>
</dd>
<dd>
<p>For each profiled method call the DBI walks along the Path and uses each value
in the Path to step into and grow the Data tree.</p>
</dd>
<dd>
<p>For example, if the Path is</p>
</dd>
<dd>
<pre>
[ 'foo', 'bar', 'baz' ]</pre>
</dd>
<dd>
<p>then the new profile sample data will be <em>merged</em> into the tree at</p>
</dd>
<dd>
<pre>
<span class="variable">$h</span><span class="operator">-></span><span class="operator">{</span><span class="string">Profile</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">Data</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">foo</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">bar</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">baz</span><span class="operator">}</span>
</pre>
</dd>
<dd>
<p>But it's not very useful to merge all the call data into one leaf node (except
to get an overall 'time spent inside the DBI' total). It's more common to want
the Path to include dynamic values such as the current statement text and/or
the name of the method called to show what the time spent inside the DBI was for.</p>
</dd>
<dd>
<p>The Path can contain some 'magic cookie' values that are automatically replaced
by corresponding dynamic values when they're used. These magic cookies always
start with a punctuation character.</p>
</dd>
<dd>
<p>For example a value of '<code>!MethodName</code>' in the Path causes the corresponding
entry in the Data to be the name of the method that was called.
For example, if the Path was:</p>
</dd>
<dd>
<pre>
[ 'foo', '!MethodName', 'selectall_arrayref' ]</pre>
</dd>
<dd>
<p>and the <code>selectall_arrayref()</code> method was called, then the profile sample data
for that call will be merged into the tree at:</p>
</dd>
<dd>
<pre>
<span class="variable">$h</span><span class="operator">-></span><span class="operator">{</span><span class="string">Profile</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">Data</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">foo</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">selectall_arrayref</span><span class="operator">}</span><span class="operator">-></span><span class="operator">{</span><span class="string">bar</span><span class="operator">}</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_profile_data">Profile Data</a></strong>
<dd>
<p>Profile data is stored at the 'leaves' of the tree as references
to an array of numeric values. For example:</p>
</dd>
<dd>
<pre>
[
106, # 0: count of samples at this node
0.0312958955764771, # 1: total duration
0.000490069389343262, # 2: first duration
0.000176072120666504, # 3: shortest duration
0.00140702724456787, # 4: longest duration
1023115819.83019, # 5: time of first sample
1023115819.86576, # 6: time of last sample
]</pre>
</dd>
<dd>
<p>After the first sample, later samples always update elements 0, 1, and 6, and
may update 3 or 4 depending on the duration of the sampled call.</p>
</dd>
</li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -