Codeigniter-application-profiling

提供:Dev Guides
移動先:案内検索

CodeIgniter-アプリケーションプロファイリング

Webアプリケーションを構築するとき、コントローラーの実行にかかる時間と使用されるメモリの量の観点から、Webサイトのパフォーマンスを非常に懸念しています。 パフォーマンスだけでなく、POSTデータ、データベースクエリのデータ、セッションデータなどのデータの洞察も確認する必要があります。 一部のアプリケーションの開発中にデバッグ目的で使用します。 CodeIgniterは、アプリケーションをプロファイリングすることにより、この作業を簡単にしました。

プロファイリングを有効にする

アプリケーションのプロファイリングを有効にするには、コントローラーのいずれかのメソッドで次のコマンドを実行するだけです。

$this->output->enable_profiler(TRUE);

プロファイリングのレポートは、有効にするとページの下部に表示されます。

プロファイリングを無効にする

アプリケーションのプロファイリングを無効にするには、コントローラーのいずれかのメソッドで次のコマンドを実行します。

$this->output->enable_profiler(FALSE);

プロファイラーセクションの有効化/無効化

プロファイリングはセクション単位で実行できます。 ブール値TRUEまたはFALSEを設定することにより、セクションのプロファイリングを有効または無効にできます。 アプリケーションでプロファイリングを設定する場合は、 application/config/profiler.php にあるファイルで実行できます

たとえば、次のコマンドは、アプリケーション全体のプロファイリングクエリを有効にします。

$config['queries'] = TRUE;

次の表のキーはパラメーターであり、特定のプロファイルを有効または無効にするために構成配列で設定できます。

Key Description Default
benchmarks Elapsed time of Benchmark points and total execution time TRUE
config CodeIgniterConfig 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
session_data Data stored in the current session TRUE
query_toggle_count The number of queries after which the query block will default to hidden. 25
*application/config/profiler.php* のファイルに設定されているプロファイラーは、以下に示すようにコントローラーで* set_profiler_sections()*関数を使用することでオーバーライドできます。
$sections = array(
   'config'  => TRUE,
   'queries' => TRUE
);

$this->output->set_profiler_sections($sections);