From 67e625e992bb20ce3700340cd566646e359cd827 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Mon, 23 Oct 2023 08:52:46 +0700 Subject: [PATCH] Updated --- bt/includes/init_tr.php | 36 +++++++++++++----------------- library/includes/core/mysql.php | 22 +++++++----------- library/includes/functions_dev.php | 4 ++-- library/includes/page_footer.php | 2 +- 4 files changed, 26 insertions(+), 38 deletions(-) diff --git a/bt/includes/init_tr.php b/bt/includes/init_tr.php index e50927cf..6e3851bd 100644 --- a/bt/includes/init_tr.php +++ b/bt/includes/init_tr.php @@ -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'); } } } diff --git a/library/includes/core/mysql.php b/library/includes/core/mysql.php index 2c766806..f27c3827 100644 --- a/library/includes/core/mysql.php +++ b/library/includes/core/mysql.php @@ -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) { diff --git a/library/includes/functions_dev.php b/library/includes/functions_dev.php index febcd752..c173696d 100644 --- a/library/includes/functions_dev.php +++ b/library/includes/functions_dev.php @@ -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 .= '' diff --git a/library/includes/page_footer.php b/library/includes/page_footer.php index e58f807c..6dd1bac3 100644 --- a/library/includes/page_footer.php +++ b/library/includes/page_footer.php @@ -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']; }