Your SlideShare is downloading. ×
FuelPHPで3種のprofilerを使ってみた
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply
We'd love to hear what you think

By taking this short survey, you'll help us make SlideShare better. It shouldn't take more than a few minutes.

Start Survey

FuelPHPで3種のprofilerを使ってみた

6,292
views

Published on

PHPカンファレンス2013で発表したスライドです。

PHPカンファレンス2013で発表したスライドです。

Published in: Technology

0 Comments
14 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,292
On Slideshare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
20
Comments
0
Likes
14
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. FuelPHPで 3種のProfilerを使ってみた PHP カンファレンス 2013 2013/09/14 株式会社 サイバード 三浦 克浩 13年9月14日土曜日
  • 2. アジェンダ •自己紹介 •プロファイラとは •New Relicについて •xhprofについて •PHP Quick Profilerについて 13年9月14日土曜日
  • 3. 自己紹介 • 名前:三浦 克浩 • Twitter ID:@MiuraKatsu • 仕事:ソーシャルゲーム開発 • 好きなフレームワーク: CakePHP、Yacafi • 浦和レッズ: 13年9月14日土曜日
  • 4. プロファイラ使ってますか? 13年9月14日土曜日
  • 5. プロファイラとは プロファイラ(英: Profiler)は性能解析ツールであり、 プログラム実行時の各種情報を収集する。特に、関数 呼び出しの頻度やそれにかかる時間を計測する。出力 は記録したイベントの羅列(トレース)の場合と、観測 したイベント群の統計的要約(プロファイル)の場合が ある。 出典: http://ja.wikipedia.org/wiki/ %E6%80%A7%E8%83%BD%E8%A7%A3%E6%9E%90 13年9月14日土曜日
  • 6. 要はパフォーマンス・チューニングと ボトルネック調査の時に使うアレ 13年9月14日土曜日
  • 7. こんな時とか 13年9月14日土曜日
  • 8. こんな時とか こんな時に使うアレ 13年9月14日土曜日
  • 9. 諸般の事情により FuelPHPでパフォーマンス・チューニング 使わざるを得ない状況に 13年9月14日土曜日
  • 10. FuelPHPでパフォーマンス・チューニング 幾つかのプロファイラを使ってみた その時ゴニョゴニョしたことのまとめ 13年9月14日土曜日
  • 11. FuelPHPで∼を使うには New Recli編 https://newrelic.com/ 13年9月14日土曜日
  • 12. New Relicとは 13年9月14日土曜日
  • 13. New Relicとは SaaS型パフォーマンス 監視サービス 13年9月14日土曜日
  • 14. エージェントを インストールするだけで 13年9月14日土曜日
  • 15. こんな画面とか 13年9月14日土曜日
  • 16. こんな画面が 13年9月14日土曜日
  • 17. 超お手軽 自分、SaaSですから 13年9月14日土曜日
  • 18. さらに 13年9月14日土曜日
  • 19. Summary 13年9月14日土曜日
  • 20. Trace details 13年9月14日土曜日
  • 21. メソッド単位で 13年9月14日土曜日
  • 22. 超べんり ※ただしイケメン有料版に限る 13年9月14日土曜日
  • 23. 13年9月14日土曜日
  • 24. 必要な時だけ 13年9月14日土曜日
  • 25. 対応フレームワーク • CakePHP 1.2, 1.3, and 2.* • CodeIgniter 2 • Drupal 6 and 7 • Joomla 1.5 and 1.6 • Kohana 3.2 and 3.3 • Magento 1.5 and 1.6 • MediaWiki • QDrupal • Symfony 1 • WordPress • Yii • Zend Framework 1 13年9月14日土曜日
  • 26. _人人人人人人人人人人人人人人人_ > まさかの FuelPHP 非対応 ww <  ̄^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^ ̄ 13年9月14日土曜日
  • 27. 非対応だと 全部 index.php 13年9月14日土曜日
  • 28. 非対応だと 全部 index.phpアクセスした URLで分けたい 13年9月14日土曜日
  • 29. ゴニョゴニョします NewRelicの インストール方法は各自で 13年9月14日土曜日
  • 30. index.php try { $response = Request::forge()->execute()->response(); } 47行目位∼ 13年9月14日土曜日
  • 31. index.php try { //$response = Request::forge()->execute()->response(); $request = Request::forge(); $response = $request->execute()->response(); //New Relic対応 if (extension_loaded ('newrelic')) { $segments = $request->uri->get_segments(); $newrelic_controller = isset($segments[1]) ? $segments[1] : null; $newrelic_action = isset($segments[2]) ? $segments[2] : null; $newrelic_params = isset($segments[3]) ? $segments[3] : null; newrelic_name_transaction ( $newrelic_controller . '/' . $newrelic_action . '/' . $newrelic_params); } } 13年9月14日土曜日
  • 32. なんでそんな処理に? newrelic_name_transaction( ) に渡したstringはURLとして扱われる $request->uri->get_segments( ) でURLを配列として取得 ‘/’で結合してnewrelic_name_transaction( )に 13年9月14日土曜日
  • 33. 13年9月14日土曜日
  • 34. 注意点 Request::forge()->execute()->response() を抜けたあとで処理しているので、 途中でReturnせずにExitしたりRedirectしたりすると 全部 index.php 扱い 13年9月14日土曜日
  • 35. 問題点 NewRelicはパフォーマンス監視サービス しきい値を超えて遅いものしか 分析できない 13年9月14日土曜日
  • 36. 問題点 NewRelicはパフォーマンス監視サービス しきい値を超えて遅いものしか 分析できない 個々の処理についても詳しく調べたい! 13年9月14日土曜日
  • 37. FuelPHPで∼を使うには xhprof編 http://pecl.php.net/package/xhprof 13年9月14日土曜日
  • 38. xhprofとは facebook.comの中の人が 作ったプロファイラ 13年9月14日土曜日
  • 39. プロファイル情報がブラウザで見られる 13年9月14日土曜日
  • 40. プロファイリングの階層表示も 13年9月14日土曜日
  • 41. 13年9月14日土曜日
  • 42. 処理のフローをグラフ化 13年9月14日土曜日
  • 43. 13年9月14日土曜日
  • 44. 13年9月14日土曜日
  • 45. ボトルネックが一発で! 13年9月14日土曜日
  • 46. 超べんり 13年9月14日土曜日
  • 47. ゴニョゴニョします xhprofの インストール方法は各自で 13年9月14日土曜日
  • 48. index.php // Boot the app require APPPATH.'bootstrap.php'; 43行目位∼ 13年9月14日土曜日
  • 49. index.php // xhprofile if(function_exists('xhprof_enable')){ xhprof_enable(); } // Boot the app require APPPATH.'bootstrap.php'; bootstrap.phpの前で xhprof_enable() 13年9月14日土曜日
  • 50. index.php // Boot the app require APPPATH.'bootstrap.php'; if(function_exists('xhprof_disable')) { register_shutdown_function( function() { $xhprof_data = xhprof_disable(); $XHPROF_ROOT = '/var/www/xhprof/'; //xhprofをインストールしたディレクトリ $XHPROF_SOURCE_NAME = 'fuelphp'; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php"; include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php"; $xhprof_runs = new XHProfRuns_Default('/tmp'); $run_id = $xhprof_runs->save_run($xhprof_data, $XHPROF_SOURCE_NAME); echo "<a href="http://".$_SERVER["SERVER_ADDR"]."/xhprof_html/index.php?run= $run_id&source=$XHPROF_SOURCE_NAME">xhprof Result</a>n"; }); } bootstrap.phpの後で register_shutdown_function() 13年9月14日土曜日
  • 51. core/bootstrap.phpの中でも register_shutdown_function()が 呼ばれてる Event::shutdown()の実行 この処理の後に実行させたいので bootstrap.phpの後で register_shutdown_function() なんでそんな処理に? 13年9月14日土曜日
  • 52. 13年9月14日土曜日
  • 53. 13年9月14日土曜日
  • 54. ログになら Log::debug("[" . $_SERVER['REQUEST_URI'] . "] -> http://". $_SERVER["SERVER_ADDR"]."/xhprof_html/index.php?run=$run_id&source= $XHPROF_SOURCE_NAME"); echo "<a href="http://".$_SERVER["SERVER_ADDR"]."/xhprof_html/index.php? run=$run_id&source=$XHPROF_SOURCE_NAME">xhprof Result</a>n"; 13年9月14日土曜日
  • 55. 問題点 インストールがちょっと面倒くさい peclだとコケるし Graphvizとか必要だし 結果ファイルがダブつく /tmpを何度かパンパンにしました もっと詳細な情報がほしい! 13年9月14日土曜日
  • 56. FuelPHPで∼を使うには PHP Quick Profiler編 http://www.particletree.com/features/php-quick-profiler/ 13年9月14日土曜日
  • 57. PHP QuickProfilerとは particletree.comの中の人が 作った プロファイラ 13年9月14日土曜日
  • 58. 13年9月14日土曜日
  • 59. 13年9月14日土曜日
  • 60. カッコいいGUI 13年9月14日土曜日
  • 61. 13年9月14日土曜日
  • 62. 多機能 Log、SQL Query、 Memory、LoadFile、etc... 13年9月14日土曜日
  • 63. 超べんり 13年9月14日土曜日
  • 64. なにより 13年9月14日土曜日
  • 65. FuelPHP標準装備 13年9月14日土曜日
  • 66. FuelPHP標準装備 13年9月14日土曜日
  • 67. 超お手軽 てゆうか、これ絶対入ってるよね 13年9月14日土曜日
  • 68. 問題点 表示(echo)してるだけ 保存できない 非表示 ($config[‘profiling’] = false) 取れない 13年9月14日土曜日
  • 69. https://github.com/MiuraKatsu/fuelphp-profiler-log Packageを作った 13年9月14日土曜日
  • 70. プロファイル情報をDebug Logに出力 画面に表示/非表示にかかわらず取得可能 出力する情報種別も選択可 13年9月14日土曜日
  • 71. ゴニョゴニョしました ProfilerLogの インストール方法は・・・ 13年9月14日土曜日
  • 72. インストール方法 package配下に展開 core/classes/profiler.phpの差し替え patch -u core/classes/profiler.php < packages/profiler-log/patch/profiler.patch $config[‘profiler’]の設定 git clone -recursive git://github.com/MiuraKatsu/fuelphp-profiler-log.git 13年9月14日土曜日
  • 73. やっていること •core/classes/profiler.phpにメソッドの追加 •Event::shutdown()にProfileLog::shutdown登録 •ProfilerLog::shutdown()でプロファイルデータ取得 •ついでにSessionIdも追加 •Log::debug()に指定したデータをprint_r()で出力 13年9月14日土曜日
  • 74. こんな感じ INFO - 2013-09-08 18:28:19 --> FuelCoreRequest::__construct - Creating a new Request with URI = "welcome/index" INFO - 2013-09-08 18:28:19 --> FuelCoreRequest::execute - Called INFO - 2013-09-08 18:28:19 --> FuelCoreRequest::execute - Setting main Request DEBUG - 2013-09-08 18:28:19 --> Array ( [session_id] => ce1d264276ff7a28bf33883bf69d173a [output_data] => Array ( [logs] => Array ( [console] => Array ( [0] => Array ( [data] => 46.040 ms [type] => speed [name] => FuelCoreProfiler::init Start ) [1] => Array ( [data] => 67.952 ms [type] => speed [name] => FuelCoreFuel::init End ) [2] => Array 13年9月14日土曜日
  • 75. 展開 Driverを追加すれば、 DBとか fluentdとかにも 13年9月14日土曜日
  • 76. •New Relicで当たりをつける •xhprofでボトルネックを絞り込む •ProfilerLogで詳細情報を取得する まとめ 13年9月14日土曜日
  • 77. •New Relicで当たりをつける •xhprofでボトルネックを絞り込む •ProfilerLogで詳細情報を取得する まとめ みんなで幸せになろう 13年9月14日土曜日
  • 78. 幸せになりたい エンジニア募集中 13年9月14日土曜日
  • 79. ご清聴ありがとうございました。 13年9月14日土曜日