Skip to content

Commit

Permalink
writeSlowlog() 함수 추가
Browse files Browse the repository at this point in the history
- query, trigger 수행 시 slowlog를 기록하는 역할 수행
- 파일에 기록 또는 `XE.writeSlowlog` trigger를 동작시킴
  • Loading branch information
bnu committed Oct 11, 2014
1 parent b395884 commit ba0a995
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions config/func.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '<?php exit(); ?>';
$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
*
Expand Down

0 comments on commit ba0a995

Please sign in to comment.