summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/libraries/Benchmark.php35
-rw-r--r--system/libraries/Output.php131
-rw-r--r--system/libraries/Router.php5
-rw-r--r--user_guide/libraries/benchmark.html72
-rw-r--r--user_guide/libraries/output.html15
-rw-r--r--user_guide/libraries/profiler.html95
-rw-r--r--user_guide/nav/nav.js3
-rw-r--r--user_guide/toc.html3
8 files changed, 122 insertions, 237 deletions
diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php
index feedbf570..d29e91798 100644
--- a/system/libraries/Benchmark.php
+++ b/system/libraries/Benchmark.php
@@ -48,7 +48,6 @@ class CI_Benchmark {
{
$this->marker[$name] = microtime();
}
- // END mark()
// --------------------------------------------------------------------
@@ -81,39 +80,6 @@ class CI_Benchmark {
return number_format(($em + $es) - ($sm + $ss), $decimals);
}
- // END elapsed_time()
-
- // --------------------------------------------------------------------
-
- /**
- * Auto Profiler
- *
- * This function cycles through the entire array of mark points and
- * matches any two points that are named identially (ending in "_start"
- * and "_end" respectively). It then compiles the execution times for
- * all points and returns it as an array
- *
- * @access public
- * @return array
- */
- function auto_profiler()
- {
- $marker_keys = array_reverse(array_keys($this->marker));
-
- $times = array();
- foreach ($marker_keys as $val)
- {
- if (preg_match("/(.+?)_start/i", $val, $match))
- {
- if (isset($this->marker[$match[1].'_end']))
- {
- $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end');
- }
- }
- }
-
- return $times;
- }
// --------------------------------------------------------------------
@@ -132,7 +98,6 @@ class CI_Benchmark {
{
return '{memory_usage}';
}
- // END memory_usage()
}
diff --git a/system/libraries/Output.php b/system/libraries/Output.php
index b5b7c9e97..4ab5dd23c 100644
--- a/system/libraries/Output.php
+++ b/system/libraries/Output.php
@@ -29,9 +29,10 @@
class CI_Output {
var $final_output;
- var $cache_expiration = 0;
- var $headers = array();
- var $enable_profiler = FALSE;
+ var $cache_expiration = 0;
+ var $headers = array();
+ var $enable_profiler = FALSE;
+
function CI_Output()
{
@@ -121,46 +122,52 @@ class CI_Output {
/**
* Display Output
*
- * All "view" data is automatically put into this variable
- * by the controller class:
+ * All "view" data is automatically put into this variable by the controller class:
*
* $this->final_output
*
- * This function simply echos the variable out. It also does the following:
- *
- * Stops the benchmark timer so the page rendering speed can be shown.
- *
- * Determines if the "memory_get_usage' function is available so that
- * the memory usage can be shown.
+ * This function sends the finalized output data to the browser along
+ * with any server headers and profile data. It also stops the
+ * benchmark timer so the page rendering speed and memory usage can be shown.
*
* @access public
- * @return void
+ * @return mixed
*/
function _display($output = '')
{
- // Note: We can't use $obj =& get_instance() since this function
- // is sometimes called by the caching mechanism, which happens before
- // it's available. Instead we'll use globals...
+ // Note: We use globals because we can't use $obj =& get_instance()
+ // since this function is sometimes called by the caching mechanism,
+ // which happens before the CI super object is available.
global $BM, $CFG;
-
+
+ // --------------------------------------------------------------------
+
+ // Set the output data
if ($output == '')
{
$output =& $this->final_output;
}
+ // --------------------------------------------------------------------
+
// Do we need to write a cache file?
if ($this->cache_expiration > 0)
{
$this->_write_cache($output);
}
+
+ // --------------------------------------------------------------------
- // Parse out the elapsed time and memory usage, and
- // swap the pseudo-variables with the data
+ // Parse out the elapsed time and memory usage,
+ // then swap the pseudo-variables with the data
+
$elapsed = $BM->elapsed_time('total_execution_time_start', 'total_execution_time_end');
+ $output = str_replace('{elapsed_time}', $elapsed, $output);
+
$memory = ( ! function_exists('memory_get_usage')) ? '0' : round(memory_get_usage()/1024/1024, 2).'MB';
-
$output = str_replace('{memory_usage}', $memory, $output);
- $output = str_replace('{elapsed_time}', $elapsed, $output);
+
+ // --------------------------------------------------------------------
// Is compression requested?
if ($CFG->item('compress_output') === TRUE)
@@ -173,6 +180,8 @@ class CI_Output {
}
}
}
+
+ // --------------------------------------------------------------------
// Are there any server headers to send?
if (count($this->headers) > 0)
@@ -182,30 +191,54 @@ class CI_Output {
@header($header);
}
}
+
+ // --------------------------------------------------------------------
- // Send the finalized output either directly
- // to the browser or to the user's _output()
- // function if it exists
- if (function_exists('get_instance'))
+ // Does the get_instance() function exist?
+ // If not we know we are dealing with a cache file so we'll
+ // simply echo out the data and exit.
+ if ( ! function_exists('get_instance'))
{
- $obj =& get_instance();
-
- if ($this->enable_profiler == TRUE)
- {
- $output .= $this->_run_profiler();
- }
+ echo $output;
+ log_message('debug', "Final output sent to browser");
+ log_message('debug', "Total execution time: ".$elapsed);
+ }
+
+ // --------------------------------------------------------------------
+
+ // Grab the super object. We'll need it in a moment...
+ $obj =& get_instance();
- if (method_exists($obj, '_output'))
+ // Do we need to generate profile data?
+ // If so, load the Profile class and run it.
+ if ($this->enable_profiler == TRUE)
+ {
+ $obj->load->library('profiler');
+
+ // If the output data contains closing </body> and </html> tags
+ // we will remove them and add them back after we insert the profile data
+ if (preg_match("|</body>.*?</html>|is", $output))
{
- $obj->_output($output);
+ $output = preg_replace("|</body>.*?</html>|is", '', $output);
+ $output .= $obj->profiler->run();
+ $output .= '</body></html>';
}
else
{
- echo $output; // Send it to the browser!
+ $output .= $obj->profiler->run();
}
}
+
+ // --------------------------------------------------------------------
+
+ // Does the controller contain a function named _output()?
+ // If so send the output there. Otherwise, echo it.
+ if (method_exists($obj, '_output'))
+ {
+ $obj->_output($output);
+ }
else
- {
+ {
echo $output; // Send it to the browser!
}
@@ -324,36 +357,6 @@ class CI_Output {
return TRUE;
}
- // --------------------------------------------------------------------
-
- /**
- * Run the Auto-profiler
- *
- * @access private
- * @return string
- */
- function _run_profiler()
- {
- $obj =& get_instance();
-
- $profile = $obj->benchmark->auto_profiler();
-
- $output = '';
- if (count($profile) > 0)
- {
- $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0'>\n";
-
- foreach ($profile as $key => $val)
- {
- $key = ucwords(str_replace(array('_', '-'), ' ', $key));
- $output .= "<tr><td><strong>".$key."</strong></td><td>".$val."</td></tr>\n";
- }
-
- $output .= "</table>\n";
- }
-
- return $output;
- }
}
// END Output Class
diff --git a/system/libraries/Router.php b/system/libraries/Router.php
index d62cf5090..7a4fd3899 100644
--- a/system/libraries/Router.php
+++ b/system/libraries/Router.php
@@ -530,6 +530,11 @@ class CI_Router {
*/
function fetch_method()
{
+ if ($this->method == $this->fetch_class())
+ {
+ return 'index';
+ }
+
return $this->method;
}
diff --git a/user_guide/libraries/benchmark.html b/user_guide/libraries/benchmark.html
index b8b0bfd32..8c1dc2c44 100644
--- a/user_guide/libraries/benchmark.html
+++ b/user_guide/libraries/benchmark.html
@@ -78,9 +78,9 @@ timing of the entire system execution to be shown.</p>
<ul>
<li><a href="#using">Using the Benchmark Class</a></li>
+<li><a href="#profiler">Profiling Your Benchmark Points</a></li>
<li><a href="#execution">Displaying Total Execution Time</a></li>
<li><a href="#memory">Displaying Memory Consumption</a></li>
-<li><a href="#profiler">Auto Profiler</a></li>
</ul>
@@ -98,15 +98,15 @@ timing of the entire system execution to be shown.</p>
<p>Here's an example using real code:</p>
-<code>$this->benchmark->mark('start');<br />
+<code>$this->benchmark->mark('code_start');<br />
<br />
// Some code happens here<br />
<br />
-$this->benchmark->mark('end');<br />
+$this->benchmark->mark('code_end');<br />
<br />
-echo $this->benchmark->elapsed_time('start', 'end');</code>
+echo $this->benchmark->elapsed_time('code_start', 'code_end');</code>
-<p><strong>Note:</strong> The words "start" and "end" are arbitrary. They are simply words used to set two markers. You can
+<p><strong>Note:</strong> The words "code_start" and "code_end" are arbitrary. They are simply words used to set two markers. You can
use any words you want, and you can set multiple sets of markers. Consider this example:</p>
<code>$this->benchmark->mark('dog');<br />
@@ -124,6 +124,32 @@ echo $this->benchmark->elapsed_time('cat', 'bird');<br />
echo $this->benchmark->elapsed_time('dog', 'bird');</code>
+<a name="profiler"></a>
+<h2>Profiling Your Benchmark Points</h2>
+
+<p>If you want your benchmark data to be available to the
+<a href="../general/profiling.html">Profiler</a> all of your marked points must be set up in pairs, and
+each mark point name must end with <kbd>_start</kbd> and <kbd>_end</kbd>.
+Each pair of points must otherwise be named identically. Example:</p>
+
+<code>
+$this->benchmark->mark('my_mark<kbd>_start</kbd>');<br />
+<br />
+// Some code happens here...<br />
+<br />
+$this->benchmark->mark('my_mark<kbd>_end</kbd>');
+<br /><br />
+
+$this->benchmark->mark('another_mark<kbd>_start</kbd>');<br />
+<br />
+// Some more code happens here...<br />
+<br />
+$this->benchmark->mark('another_mark<kbd>_end</kbd>');
+
+<p>Please read the <a href="../general/profiling.html">Profiler page</a> for more information.</p>
+
+
+
<a name="execution"></a>
<h2>Displaying Total Execution Time</h2>
@@ -155,42 +181,6 @@ system using the following code in one of your view file:</p>
<code>{memory_usage}</code>
-<a name="profiler"></a>
-<h2>Auto Profiler</h2>
-
-<p>When the "auto profiler" is enabled, you'll see a report printed at the bottom of your pages containing a list of
-execution times for all benchmarks you have set throughout your application. This information can help you optimize your program.</p>
-
-<p class="important"><strong>Note:</strong> Even though this is a feature of the Benchmark class you will enable it from the Output class as indicated below.</p>
-
-<p>To enable the profiler place the the following function anywhere within your Controllers:</p>
-<code>$this->output->enable_profiler(TRUE);</code>
-
-<p>When enabled you'll see a table of execution times at the bottom of your pages.</p>
-
-<p>To disable the profiler you will use:</p>
-<code>$this->output->enable_profiler(FALSE);</code>
-
-<p>Important: In order to use this feature all of your marked points must end with <kbd>_start</kbd> and <kbd>_end</kbd>, and
-each pair of points must otherwise be named identically. Example:</p>
-
-<code>
-$this->benchmark->mark('my_mark<kbd>_start</kbd>');<br />
-<br />
-// Some code happens here...<br />
-<br />
-$this->benchmark->mark('my_mark<kbd>_end</kbd>');
-<br /><br />
-
-$this->benchmark->mark('another_mark<kbd>_start</kbd>');<br />
-<br />
-// Some more code happens here...<br />
-<br />
-$this->benchmark->mark('another_mark<kbd>_end</kbd>');
-
-</code>
-
-
</div>
diff --git a/user_guide/libraries/output.html b/user_guide/libraries/output.html
index adc8fb58e..ad6a53d8f 100644
--- a/user_guide/libraries/output.html
+++ b/user_guide/libraries/output.html
@@ -105,6 +105,21 @@ $this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);<br
$this->output->set_header("Pragma: no-cache"); </code>
+<h2>$this->output->enable_profiler();</h2>
+
+<p>Permits you to enable/disable the <a href="../general/profiling.html">Profiler</a>, which will display benchmark and other data
+at the bottom of your pages for debugging and optimization purposes.</p>
+
+<p>To enable the profiler place the the following function anywhere within your <a href="controllers.html">Controller</a> functions:</p>
+<code>$this->output->enable_profiler(TRUE);</code>
+
+<p>When enabled a report will be generated and inserted at the bottom of your pages.</p>
+
+<p>To disable the profiler you will use:</p>
+<code>$this->output->enable_profiler(FALSE);</code>
+
+
+
</div>
<!-- END CONTENT -->
diff --git a/user_guide/libraries/profiler.html b/user_guide/libraries/profiler.html
deleted file mode 100644
index 2b162be0b..000000000
--- a/user_guide/libraries/profiler.html
+++ /dev/null
@@ -1,95 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html>
-<head>
-
-<title>Code Igniter User Guide</title>
-
-<style type='text/css' media='all'>@import url('../userguide.css');</style>
-<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
-
-<script type="text/javascript" src="../nav/nav.js"></script>
-<script type="text/javascript" src="../nav/prototype.lite.js"></script>
-<script type="text/javascript" src="../nav/moo.fx.js"></script>
-<script type="text/javascript">
-window.onload = function() {
- myHeight = new fx.Height('nav', {duration: 400});
- myHeight.hide();
-}
-</script>
-
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<meta http-equiv='expires' content='-1' />
-<meta http-equiv= 'pragma' content='no-cache' />
-<meta name='robots' content='all' />
-<meta name='author' content='Rick Ellis' />
-<meta name='description' content='Code Igniter User Guide' />
-
-</head>
-<body>
-
-<!-- START NAVIGATION -->
-<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
-<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
-<div id="masthead">
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td><h1>Code Igniter User Guide Version 1.5.0</h1></td>
-<td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
-</tr>
-</table>
-</div>
-<!-- END NAVIGATION -->
-
-
-<!-- START BREADCRUMB -->
-<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
-<tr>
-<td id="breadcrumb">
-<a href="http://www.codeigniter.com/">Code Igniter Home</a> &nbsp;&#8250;&nbsp;
-<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
-Profiler Class
-</td>
-<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
-</tr>
-</table>
-<!-- END BREADCRUMB -->
-
-<br clear="all" />
-
-
-<!-- START CONTENT -->
-<div id="content">
-
-
-
-
-<h1>Profiler Class</h1>
-
-<p>The Profiler Class enables you to display benchmark, query, POST data at the bottom of your pages during
-development in order to help with debugging and optimization.</p>
-
-
-<h2>Initializing the Class</h2>
-
-<p><strong>Important:</strong> This class does NOT need to be initialized. It is loaded automatically by the Output class if
-profiling is enabled as shown below.</p>
-
-
-
-</div>
-<!-- END CONTENT -->
-
-
-<div id="footer">
-<p>
-Previous Topic:&nbsp;&nbsp;<a href="parser.html">Parser Class</a>
-&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
-<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
-<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
-Next Topic:&nbsp;&nbsp;<a href="sessions.html">Session Class</a>
-<p>
-<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
-</div>
-
-</body>
-</html> \ No newline at end of file
diff --git a/user_guide/nav/nav.js b/user_guide/nav/nav.js
index fc2d609a1..5afa28742 100644
--- a/user_guide/nav/nav.js
+++ b/user_guide/nav/nav.js
@@ -52,7 +52,8 @@ function create_menu(basepath)
'<li><a href="'+base+'general/scaffolding.html">Scaffolding</a></li>' +
'<li><a href="'+base+'general/routing.html">URI Routing</a></li>' +
'<li><a href="'+base+'general/errors.html">Error Handling</a></li>' +
- '<li><a href="'+base+'general/caching.html">Web Page Caching</a></li>' +
+ '<li><a href="'+base+'general/caching.html">Caching</a></li>' +
+ '<li><a href="'+base+'general/profiling.html">Profiling Your Application</a></li>' +
'<li><a href="'+base+'general/multiple_apps.html">Running Multiple Applications</a></li>' +
'<li><a href="'+base+'general/alternative_php.html">Alternative PHP Syntax</a></li>' +
'<li><a href="'+base+'general/security.html">Security</a></li>' +
diff --git a/user_guide/toc.html b/user_guide/toc.html
index f4675b9b5..d479aa19a 100644
--- a/user_guide/toc.html
+++ b/user_guide/toc.html
@@ -107,7 +107,8 @@ Table of Contents
<li><a href="./general/scaffolding.html">Scaffolding</a></li>
<li><a href="./general/routing.html">URI Routing</a></li>
<li><a href="./general/errors.html">Error Handling</a></li>
- <li><a href="./general/caching.html">Web Page Caching</a></li>
+ <li><a href="./general/caching.html">Caching</a></li>
+ <li><a href="./general/profiling.html">Profiling Your Application</a></li>
<li><a href="./general/multiple_apps.html">Running Multiple Applications</a></li>
<li><a href="./general/alternative_php.html">Alternative PHP Syntax</a></li>
<li><a href="./general/security.html">Security</a></li>