CodeIgniter 使用手冊版本 2.2.0

Application 效能分析

這個效能分析類別(Profiler Class)會顯示出 benchmark 的查詢結果、然後將 $_POST 的資料置於頁面的尾端。這些資訊在進行開發時,用來協助除錯或是最佳化相當有用。


非常重要:  這各類別 不需要 額外步驟將它初始化。他可由 Output 類別 自動載入,效能分析功能就會啟動並顯示結果在頁面尾端。


控制器(Controller) 函數中,啟動效能分析器:





設定 Benchmark 點

In order for the Profiler to compile and display your benchmark data you must name your mark points using specific syntax.

Please read the information on setting Benchmark points in Benchmark Class page.

Enabling and Disabling Profiler Sections

Each section of Profiler data can be enabled or disabled by setting a corresponding config variable to TRUE or FALSE. This can be done one of two ways. First, you can set application wide defaults with the application/config/profiler.php config file.

$config['config']          = FALSE;
$config['queries']         = FALSE;

In your controllers, you can override the defaults and config file values by calling the set_profiler_sections() method of the Output class:

$sections = array(
    'config'  => TRUE,
    'queries' => TRUE


Available sections and the array key used to access them are described in the table below.

Key Description Default
benchmarks Elapsed time of Benchmark points and total execution time TRUE
config CodeIgniter Config variables TRUE
controller_info The Controller class and method requested TRUE
get Any GET data passed in the request TRUE
http_headers The HTTP headers for the current request TRUE
memory_usage Amount of memory consumed by the current request, in bytes TRUE
post Any POST data passed in the request TRUE
queries Listing of all database queries executed, including execution time TRUE
uri_string The URI of the current request TRUE
query_toggle_count The number of queries after which the query block will default to hidden. 25