Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#785 slow trigger log 추가 #788

Merged
6 commits merged into from
Aug 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions classes/module/ModuleHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,12 +1145,25 @@ function triggerCall($trigger_name, $called_position, &$obj)
{
return new Object();
}

//store before trigger call time
$before_trigger_time = NULL;
if(__LOG_SLOW_TRIGGER__> 0)
{
$before_trigger_time = microtime(true);
}

foreach($triggers as $item)
{
$module = $item->module;
$type = $item->type;
$called_method = $item->called_method;

$before_each_trigger_time = NULL;
if(__LOG_SLOW_TRIGGER__> 0)
{
$before_each_trigger_time = microtime(true);
}

// todo why don't we call a normal class object ?
$oModule = getModule($module, $type);
Expand All @@ -1165,6 +1178,57 @@ function triggerCall($trigger_name, $called_position, &$obj)
return $output;
}
unset($oModule);

//store after trigger call time
$after_each_trigger_time = NULL;
//init value to 0
$elapsed_time_trigger = 0;

if(__LOG_SLOW_TRIGGER__> 0)
{
$after_each_trigger_time = microtime(true);
$elapsed_time_trigger = ($after_each_trigger_time - $before_each_trigger_time) * 1000;
}

// if __LOG_SLOW_TRIGGER__ is defined, check elapsed time and leave trigger time log
if(__LOG_SLOW_TRIGGER__> 0 && $elapsed_time_trigger > __LOG_SLOW_TRIGGER__)
{
$buff = '';
$log_file = _XE_PATH_ . 'files/_db_slow_trigger.php';
if(!file_exists($log_file))
{
$buff = '<?php exit(); ?' . '>' . "\n";
}

$buff .= sprintf("%s\t%s.%s.%s.%s(%s)\n\t%0.6f msec\n\n", date("Y-m-d H:i"), $item->trigger_name,$item->module,$item->called_method,$item->called_position,$item->type, $elapsed_time_trigger);

@file_put_contents($log_file, $buff, FILE_APPEND|LOCK_EX);
}
}

//store after trigger call time
$after_trigger_time = NULL;
//init value to 0
$elapsed_time = 0;
if(__LOG_SLOW_TRIGGER__> 0)
{
$after_trigger_time = microtime(true);
$elapsed_time = ($after_trigger_time - $before_trigger_time) * 1000;
}

// if __LOG_SLOW_TRIGGER__ is defined, check elapsed time and leave trigger time log
if(__LOG_SLOW_TRIGGER__> 0 && $elapsed_time > __LOG_SLOW_TRIGGER__)
{
$buff = '';
$log_file = _XE_PATH_ . 'files/_slow_trigger.php';
if(!file_exists($log_file))
{
$buff = '<?php exit(); ?' . '>' . "\n";
}

$buff .= sprintf("%s\t%s.totaltime\n\t%0.6f msec\n\n", date("Y-m-d H:i"), $trigger_name,$elapsed_time);

@file_put_contents($log_file, $buff, FILE_APPEND|LOCK_EX);
}

return new Object();
Expand Down
14 changes: 14 additions & 0 deletions config/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@
define('__LOG_SLOW_QUERY__', 0);
}

if(!defined('__LOG_SLOW_TRIGGER__'))
{
/**
* Trigger excute time log
*
* <pre>
* 0: Do not leave a log
* > 0: leave a log when the trigger takes over specified milliseconds
* Log file is saved as ./files/_db_slow_trigger.php file
* </pre>
*/
define('__LOG_SLOW_TRIGGER__', 0);
}

if(!defined('__DEBUG_QUERY__'))
{
/**
Expand Down