OSDN Git Service

Benchmarkコンポーネント導入
authorCake <cake_67@users.sourceforge.jp>
Wed, 7 Jul 2010 04:36:51 +0000 (13:36 +0900)
committerCake <cake_67@users.sourceforge.jp>
Wed, 7 Jul 2010 04:36:51 +0000 (13:36 +0900)
app/config/init.php
app/controllers/app_controller.php
app/controllers/components/benchmark.php [new file with mode: 0644]

index a851d47..9c7b8b8 100644 (file)
@@ -39,13 +39,17 @@ Configure::write('Qdmailer', array(
        'errorlogFilename' => 'qdmailer_error.log',
 ));
 
-/* 携帯ビューの停止(暫定) */
-Configure::write('Mode.Mobile', false);
+/* Benchmarkコンポーネント使用 */
+// guest UserIDでの操作制限
+define('BENCHMARK_MODE', true);
 
 /* デモモード */
 // guest UserIDでの操作制限
 Configure::write('Mode.Demo', false);
 
+/* 携帯ビューの停止(暫定) */
+Configure::write('Mode.Mobile', false);
+
 /* php.ini設定の上書き */
 // mb_string関連
 mb_language('Japanese');
index 158633c..270fbc7 100644 (file)
@@ -30,10 +30,11 @@ class AppController extends Controller
        var $components = array(
                'AuthPlus',
                'Acl',
-               'DebugKit.Toolbar',
                'Cakeplus.HtmlEscape',
                'Token',
                'Crypt',
+               'DebugKit.Toolbar',
+               'Benchmark'
        );
 
        var $helpers = array(
@@ -100,6 +101,8 @@ class AppController extends Controller
 
        function beforeFilter()
        {
+               $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' .' beforeFilterStart');
+
                parent::beforeFilter();
 
                $this->user['User']['name'] = __('Guest', true);
@@ -159,9 +162,16 @@ class AppController extends Controller
 
        function beforeRender()
        {
+               $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' . ' beforeRenderStart');
                parent::beforeRender();
        }
 
+       function afterFilter()
+       {
+               $this->Benchmark->report($this->params['controller']. '/'. $this->action . ':' . ' afterFilterStart');
+               parent::afterFilter();
+       }
+
        /* 共通関数 */
        /* public_flag設定をview用にセット */
        function set_public_flag4view()
diff --git a/app/controllers/components/benchmark.php b/app/controllers/components/benchmark.php
new file mode 100644 (file)
index 0000000..460442a
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+/* 
+ * ベンチマークコンポーネント
+ * Reffer: http://blog.aidream.jp/cakephp/cakephp-benchmark-component-1366.html
+ */
+
+class BenchmarkComponent extends Object {
+       var $id = null;
+       var $start_time = 0;
+
+       //---------------------------------------------------------------------------
+       // コンストラクタ
+       //---------------------------------------------------------------------------
+       function __construct() {
+               $this->id = substr( md5(uniqid(rand(),true)) , 0, 8);
+               $this->report('<==construct', true);
+       }
+
+       //---------------------------------------------------------------------------
+       // デストラクタ
+       //---------------------------------------------------------------------------
+       function __destruct() {
+               $this->report('<==destruct');
+       }
+
+       //---------------------------------------------------------------------------
+       // 計測してログファイルに出力
+       //---------------------------------------------------------------------------
+       function report($message = null, $reset = false) {
+               if (defined('BENCHMARK_MODE') === false || BENCHMARK_MODE === false) {
+                       return;
+               }
+               if ($reset === true) {
+                       $this->start_time = $this->_getMicroTime();
+               }
+
+               $now = $this->_getMicroTime() - $this->start_time;
+
+               $str = sprintf("[%s] %01.5f : %s :", $this->id, $now, $message);
+               $this->log($str, LOG_DEBUG);
+       }
+
+       //---------------------------------------------------------------------------
+       // マイクロタイムを取得
+       //---------------------------------------------------------------------------
+       function _getMicrotime() {
+               if (phpversion() < 5) {
+                       list($usec, $sec) = explode(" ", microtime());
+                       return ((float)$usec + (float)$sec);
+               } else {
+                       return microtime(true);
+               }
+       }
+}