blob: 63a261cc6573b00ecc2ce7ca2b310afa40500889 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001##########################
2Profiling Your Application
3##########################
4
5The Profiler Class will display benchmark results, queries you have run,
Andrey Andreev16a704c2012-11-09 17:25:00 +02006and ``$_POST`` data at the bottom of your pages. This information can be
Derek Jones8ede1a22011-10-05 13:34:52 -05007useful during development in order to help with debugging and
8optimization.
9
10Initializing the Class
11======================
12
13.. important:: This class does NOT need to be initialized. It is loaded
Andrey Andreev16a704c2012-11-09 17:25:00 +020014 automatically by the :doc:`Output Library <../libraries/output>`
15 if profiling is enabled as shown below.
Derek Jones8ede1a22011-10-05 13:34:52 -050016
17Enabling the Profiler
18=====================
19
Andrey Andreev16a704c2012-11-09 17:25:00 +020020To enable the profiler place the following line anywhere within your
21:doc:`Controller <controllers>` methods::
Derek Jones8ede1a22011-10-05 13:34:52 -050022
23 $this->output->enable_profiler(TRUE);
24
25When enabled a report will be generated and inserted at the bottom of
26your pages.
27
28To disable the profiler you will use::
29
30 $this->output->enable_profiler(FALSE);
31
32Setting Benchmark Points
33========================
34
35In order for the Profiler to compile and display your benchmark data you
36must name your mark points using specific syntax.
37
Andrey Andreev16a704c2012-11-09 17:25:00 +020038Please read the information on setting Benchmark points in the
39:doc:`Benchmark Library <../libraries/benchmark>` page.
Derek Jones8ede1a22011-10-05 13:34:52 -050040
41Enabling and Disabling Profiler Sections
42========================================
43
44Each section of Profiler data can be enabled or disabled by setting a
45corresponding config variable to TRUE or FALSE. This can be done one of
46two ways. First, you can set application wide defaults with the
Andrey Andreev16a704c2012-11-09 17:25:00 +020047*application/config/profiler.php* config file.
Derek Jones8ede1a22011-10-05 13:34:52 -050048
Andrey Andreev16a704c2012-11-09 17:25:00 +020049Example::
Derek Jones8ede1a22011-10-05 13:34:52 -050050
Derek Jonesa1360ef2011-10-05 17:22:53 -050051 $config['config'] = FALSE;
52 $config['queries'] = FALSE;
Derek Jones8ede1a22011-10-05 13:34:52 -050053
54In your controllers, you can override the defaults and config file
Andrey Andreev16a704c2012-11-09 17:25:00 +020055values by calling the ``set_profiler_sections()`` method of the
56:doc:`Output Library <../libraries/output>`::
Derek Jones8ede1a22011-10-05 13:34:52 -050057
Derek Jonesa1360ef2011-10-05 17:22:53 -050058 $sections = array(
Andrey Andreev16a704c2012-11-09 17:25:00 +020059 'config' => TRUE,
60 'queries' => TRUE
61 );
Derek Jonesa1360ef2011-10-05 17:22:53 -050062
63 $this->output->set_profiler_sections($sections);
Derek Jones8ede1a22011-10-05 13:34:52 -050064
65Available sections and the array key used to access them are described
66in the table below.
67
Joseph Wensley5b3ea1a2011-10-06 20:54:32 -040068======================= =================================================================== ========
69Key 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.
Andrey Andreev1c8245a2014-01-20 10:28:20 +020083======================= =================================================================== ========
84
Manu Ganji0d7344e2014-05-22 16:30:09 +053085.. note:: Disabling the (save_queries)[http://ellislab.com/codeigniter/user-guide/database/configuration.html] setting in your database configuration
Andrey Andreev1c8245a2014-01-20 10:28:20 +020086 will also effectively disable profiling for database queries and render
Manu Ganji37c1f432014-05-22 16:25:23 +053087 the 'queries' setting above useless. You can optionally override this
88 setting with `$this->db->save_queries = TRUE;`. Without this setting you
Manu Ganji0d7344e2014-05-22 16:30:09 +053089 won't be able to view the queries or the (last_query)[http://ellislab.com/codeigniter/user-guide/database/helpers.html].