From ba0a995a0ccaa2225e181c4ea502930fe2c6df47 Mon Sep 17 00:00:00 2001 From: bnu Date: Wed, 27 Aug 2014 11:01:09 +0900 Subject: [PATCH] =?UTF-8?q?writeSlowlog()=20=ED=95=A8=EC=88=98=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20query,=20trigger=20=EC=88=98=ED=96=89=20?= =?UTF-8?q?=EC=8B=9C=20slowlog=EB=A5=BC=20=EA=B8=B0=EB=A1=9D=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=97=AD=ED=95=A0=20=EC=88=98=ED=96=89=20-=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=EC=97=90=20=EA=B8=B0=EB=A1=9D=20=EB=98=90?= =?UTF-8?q?=EB=8A=94=20`XE.writeSlowlog`=20trigger=EB=A5=BC=20=EB=8F=99?= =?UTF-8?q?=EC=9E=91=EC=8B=9C=ED=82=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/func.inc.php | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/config/func.inc.php b/config/func.inc.php index f2fbaa3d9..b5456a184 100644 --- a/config/func.inc.php +++ b/config/func.inc.php @@ -872,6 +872,60 @@ function debugPrint($debug_output = NULL, $display_option = TRUE, $file = '_debu } } +/** + * @param string $type query, trigger + * @param float $elapsed_time + * @param object $obj + */ +function writeSlowlog($type, $elapsed_time, $obj) +{ + static $log_filename = array( + 'query' => 'files/_slowlog_query.php', + 'trigger' => 'files/_slowlog_trigger.php', + 'addon' => 'files/_slowlog_addon.php' + ); + $write_file = true; + + $log_file = _XE_PATH_ . $log_filename[$type]; + + $buff = array(); + $buff[] = ''; + $buff[] = date('c'); + + if($type == 'trigger' && __LOG_SLOW_TRIGGER__ > 0 && $elapsed_time > __LOG_SLOW_TRIGGER__) + { + $buff[] = "\tCaller : " . $obj->caller; + $buff[] = "\tCalled : " . $obj->called; + } + else if($type == 'query' && __LOG_SLOW_QUERY__ > 0 && $elapsed_time > __LOG_SLOW_QUERY__) + { + + $buff[] = $obj->query; + $buff[] = "\tQuery ID : " . $obj->query_id; + $buff[] = "\tCaller : " . $obj->caller; + $buff[] = "\tConnection : " . $obj->connection; + } + else + { + $write_file = false; + } + + if($write_file) + { + $buff[] = sprintf("\t%0.6f sec", $elapsed_time); + $buff[] = PHP_EOL . PHP_EOL; + file_put_contents($log_file, implode(PHP_EOL, $buff), FILE_APPEND); + } + + $trigger_args = $obj; + $trigger_args->_log_type = $type; + $trigger_args->_elapsed_time = $elapsed_time; + if($type != 'query') + { + ModuleHandler::triggerCall('XE.writeSlowlog', 'after', $trigger_args); + } +} + /** * microtime() return *