Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 1 | ########################## |
| 2 | Profiling Your Application |
| 3 | ########################## |
| 4 | |
| 5 | The Profiler Class will display benchmark results, queries you have run, |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 6 | and ``$_POST`` data at the bottom of your pages. This information can be |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 7 | useful during development in order to help with debugging and |
| 8 | optimization. |
| 9 | |
| 10 | Initializing the Class |
| 11 | ====================== |
| 12 | |
| 13 | .. important:: This class does NOT need to be initialized. It is loaded |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 14 | automatically by the :doc:`Output Library <../libraries/output>` |
| 15 | if profiling is enabled as shown below. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 16 | |
| 17 | Enabling the Profiler |
| 18 | ===================== |
| 19 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 20 | To enable the profiler place the following line anywhere within your |
| 21 | :doc:`Controller <controllers>` methods:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 22 | |
| 23 | $this->output->enable_profiler(TRUE); |
| 24 | |
| 25 | When enabled a report will be generated and inserted at the bottom of |
| 26 | your pages. |
| 27 | |
| 28 | To disable the profiler you will use:: |
| 29 | |
| 30 | $this->output->enable_profiler(FALSE); |
| 31 | |
| 32 | Setting Benchmark Points |
| 33 | ======================== |
| 34 | |
| 35 | In order for the Profiler to compile and display your benchmark data you |
| 36 | must name your mark points using specific syntax. |
| 37 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 38 | Please read the information on setting Benchmark points in the |
| 39 | :doc:`Benchmark Library <../libraries/benchmark>` page. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 40 | |
| 41 | Enabling and Disabling Profiler Sections |
| 42 | ======================================== |
| 43 | |
| 44 | Each section of Profiler data can be enabled or disabled by setting a |
| 45 | corresponding config variable to TRUE or FALSE. This can be done one of |
| 46 | two ways. First, you can set application wide defaults with the |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 47 | *application/config/profiler.php* config file. |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 48 | |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 49 | Example:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 50 | |
Derek Jones | a1360ef | 2011-10-05 17:22:53 -0500 | [diff] [blame] | 51 | $config['config'] = FALSE; |
| 52 | $config['queries'] = FALSE; |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 53 | |
| 54 | In your controllers, you can override the defaults and config file |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 55 | values by calling the ``set_profiler_sections()`` method of the |
| 56 | :doc:`Output Library <../libraries/output>`:: |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 57 | |
Derek Jones | a1360ef | 2011-10-05 17:22:53 -0500 | [diff] [blame] | 58 | $sections = array( |
Andrey Andreev | 16a704c | 2012-11-09 17:25:00 +0200 | [diff] [blame] | 59 | 'config' => TRUE, |
| 60 | 'queries' => TRUE |
| 61 | ); |
Derek Jones | a1360ef | 2011-10-05 17:22:53 -0500 | [diff] [blame] | 62 | |
| 63 | $this->output->set_profiler_sections($sections); |
Derek Jones | 8ede1a2 | 2011-10-05 13:34:52 -0500 | [diff] [blame] | 64 | |
| 65 | Available sections and the array key used to access them are described |
| 66 | in the table below. |
| 67 | |
Joseph Wensley | 5b3ea1a | 2011-10-06 20:54:32 -0400 | [diff] [blame] | 68 | ======================= =================================================================== ======== |
| 69 | Key Description Default |
| 70 | ======================= =================================================================== ======== |
| 71 | **benchmarks** Elapsed time of Benchmark points and total execution time TRUE |
| 72 | **config** CodeIgniter Config variables TRUE |
| 73 | **controller_info** The Controller class and method requested TRUE |
| 74 | **get** Any GET data passed in the request TRUE |
| 75 | **http_headers** The HTTP headers for the current request TRUE |
| 76 | **memory_usage** Amount of memory consumed by the current request, in bytes TRUE |
| 77 | **post** Any POST data passed in the request TRUE |
| 78 | **queries** Listing of all database queries executed, including execution time TRUE |
| 79 | **uri_string** The URI of the current request TRUE |
| 80 | **session_data** Data stored in the current session TRUE |
| 81 | **query_toggle_count** The number of queries after which the query block will default to 25 |
| 82 | hidden. |
| 83 | ======================= =================================================================== ======== |