This commit is contained in:
Roman Kelesidis 2023-10-23 08:52:46 +07:00
parent 1dcfa83a4f
commit 67e625e992
4 changed files with 26 additions and 38 deletions

View File

@ -123,7 +123,7 @@ class sql_db
*/
function connect ()
{
$this->cur_query = 'connect';
$this->cur_query = "connect to: '{$this->cfg['dbhost']}'";
$this->debug('start');
$connect_type = ($this->cfg['persist']) ? 'mysql_pconnect' : 'mysql_connect';
@ -402,30 +402,24 @@ class sql_db
if ($mode == 'start')
{
if (SQL_CALC_QUERY_TIME || DBG_LOG_TRACKER || SQL_LOG_SLOW_QUERIES)
{
$this->sql_starttime = utime();
$this->sql_last_time = 0;
}
$this->sql_starttime = utime();
$this->sql_last_time = 0;
}
elseif ($mode == 'end')
{
if (SQL_CALC_QUERY_TIME || DBG_LOG_TRACKER || SQL_LOG_SLOW_QUERIES)
{
$this->sql_last_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->sql_last_time;
$this->DBS['sql_timetotal'] += $this->sql_last_time;
$this->sql_last_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->sql_last_time;
$this->DBS['sql_timetotal'] += $this->sql_last_time;
if (SQL_LOG_SLOW_QUERIES && $this->sql_last_time > $this->slow_time)
{
$msg = date('m-d H:i:s') . LOG_SEPR;
$msg .= sprintf('%03d', round($this->sql_last_time));
$msg .= LOG_SEPR . sprintf('%.1f', sys('la'));
$msg .= LOG_SEPR . str_compact($this->cur_query);
$msg .= LOG_SEPR .' # '. $this->query_info();
$msg .= LOG_SEPR . $this->debug_find_source();
bb_log($msg . LOG_LF, 'sql_slow_tr');
}
if (SQL_LOG_SLOW_QUERIES && $this->sql_last_time > $this->slow_time)
{
$msg = date('m-d H:i:s') . LOG_SEPR;
$msg .= sprintf('%03d', round($this->sql_last_time));
$msg .= LOG_SEPR . sprintf('%.1f', sys('la'));
$msg .= LOG_SEPR . str_compact($this->cur_query);
$msg .= LOG_SEPR .' # '. $this->query_info();
$msg .= LOG_SEPR . $this->debug_find_source();
bb_log($msg . LOG_LF, 'sql_slow_tr');
}
}
}

View File

@ -93,7 +93,7 @@ class sql_db
*/
function connect ()
{
$this->cur_query = ($this->dbg_enabled) ? ($this->cfg['persist'] ? 'p' : '') . "connect to: {$this->cfg['dbhost']}" : 'connect';
$this->cur_query = ($this->dbg_enabled) ? ($this->cfg['persist'] ? 'p' : '') . "connect to: '{$this->cfg['dbhost']}'" : 'connect';
$this->debug('start');
$connect_type = ($this->cfg['persist']) ? 'mysql_pconnect' : 'mysql_connect';
@ -748,10 +748,7 @@ class sql_db
if ($mode == 'start')
{
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
{
$this->sql_starttime = utime();
}
$this->sql_starttime = utime();
if ($this->dbg_enabled)
{
$dbg['sql'] = preg_replace('#^(\s*)(/\*)(.*)(\*/)(\s*)#', '', $this->cur_query);
@ -769,16 +766,13 @@ class sql_db
}
else if ($mode == 'stop')
{
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
{
$this->cur_query_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->cur_query_time;
$this->DBS['sql_timetotal'] += $this->cur_query_time;
$this->cur_query_time = utime() - $this->sql_starttime;
$this->sql_timetotal += $this->cur_query_time;
$this->DBS['sql_timetotal'] += $this->cur_query_time;
if (SQL_LOG_SLOW_QUERIES && $this->cur_query_time > $this->slow_time)
{
$this->log_slow_query();
}
if (SQL_LOG_SLOW_QUERIES && $this->cur_query_time > $this->slow_time)
{
$this->log_slow_query();
}
if ($this->dbg_enabled)
{

View File

@ -47,8 +47,8 @@ function get_sql_log_html ($db_obj, $log_name)
{
$id = "sql_{$i}_". mt_rand();
$sql = short_query($dbg['sql'], true);
$time = sprintf('%.4f', $dbg['time']);
$perc = @sprintf('[%d%%]', round($dbg['time']*100/$db_obj->sql_timetotal));
$time = SQL_CALC_QUERY_TIME ? sprintf('%.4f', $dbg['time']) : '';
$perc = SQL_CALC_QUERY_TIME ? @sprintf('[%d%%]', round($dbg['time']*100/$db_obj->sql_timetotal)) : '';
$info = !empty($dbg['info']) ? $dbg['info'] .' ['. $dbg['src'] .']' : $dbg['src'];
$log .= ''

View File

@ -38,7 +38,7 @@ if ($show_dbg_info)
if (!empty($DBS))
{
$sql_t = $DBS->sql_timetotal;
$sql_time_txt = ($sql_t) ? sprintf('%.3f '.$lang['SEC'].' (%d%%) · ', $sql_t, round($sql_t*100/$gen_time)) : '';
$sql_time_txt = ($sql_t && SQL_CALC_QUERY_TIME) ? sprintf('%.3f '.$lang['SEC'].' (%d%%) · ', $sql_t, round($sql_t*100/$gen_time)) : '';
$num_q = $DBS->num_queries;
$stat .= "  |  {$DBS->get_db_obj()->engine}: {$sql_time_txt}{$num_q} " . $lang['QUERIES'];
}