From 4cadce1de006935b2a8a00f61ba6da93c66507ec Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 7 Jul 2019 13:51:19 +0100 Subject: [PATCH] merge slow-page-log into tracer, fixes #673 --- core/send_event.php | 4 ++-- core/sys_config.php | 4 ++-- core/util.php | 13 ------------- index.php | 7 ++++--- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/core/send_event.php b/core/send_event.php index 434068aa..6759bf0f 100644 --- a/core/send_event.php +++ b/core/send_event.php @@ -108,8 +108,8 @@ function send_event(Event $event): void $method_name = "on".str_replace("Event", "", get_class($event)); // send_event() is performance sensitive, and with the number - // of times context gets called the time starts to add up - $tracer_enabled = constant('EVENT_TRACE'); + // of times tracer gets called the time starts to add up + $tracer_enabled = constant('TRACE_FILE'); if ($tracer_enabled) $_tracer->begin(get_class($event)); // SHIT: http://bugs.php.net/bug.php?id=35106 diff --git a/core/sys_config.php b/core/sys_config.php index e2ce789b..32da08fb 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -33,7 +33,6 @@ _d("DEBUG", false); // boolean print various debugging details _d("DEBUG_SQL", false); // boolean dump SQL queries to data/sql.log _d("DEBUG_CACHE", false); // boolean dump cache queries to data/cache.log _d("COVERAGE", false); // boolean activate xdebug coverage monitor -_d("EVENT_TRACE", null); // string file to log performance data into _d("CACHE_HTTP", false); // boolean output explicit HTTP caching headers _d("COOKIE_PREFIX", 'shm'); // string if you run multiple galleries with non-shared logins, give them different prefixes _d("SPEED_HAX", false); // boolean do some questionable things in the name of performance @@ -47,7 +46,8 @@ _d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,set _d("EXTRA_EXTS", ""); // string optional extra extensions _d("BASE_URL", null); // string force a specific base URL (default is auto-detect) _d("MIN_PHP_VERSION", '7.1');// string minimum supported PHP version -_d("SLOW_PAGES", null); // float log pages which take more time than this +_d("TRACE_FILE", null); // string file to log performance data into +_d("TRACE_THRESHOLD", 0.0); // float log pages which take more time than this many seconds _d("ENABLED_MODS", "imageboard"); /* diff --git a/core/util.php b/core/util.php index 43f62dd1..007822d5 100644 --- a/core/util.php +++ b/core/util.php @@ -390,19 +390,6 @@ function get_debug_info(): string return $debug; } -function log_slow(): void -{ - global $_shm_load_start; - if (!is_null(SLOW_PAGES)) { - $_time = microtime(true) - $_shm_load_start; - if ($_time > SLOW_PAGES) { - $_query = _get_query(); - $_dbg = get_debug_info(); - file_put_contents("data/slow-pages.log", "$_time $_query $_dbg\n", FILE_APPEND | LOCK_EX); - } - } -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * Request initialisation stuff * diff --git a/index.php b/index.php index efad8c65..fdde0b16 100644 --- a/index.php +++ b/index.php @@ -113,8 +113,9 @@ try { _fatal_error($e); } -log_slow(); $_tracer->end(); -if (EVENT_TRACE) { - $_tracer->flush(EVENT_TRACE); +if (TRACE_FILE) { + if((microtime(true) - $_shm_load_start) > TRACE_THRESHOLD) { + $_tracer->flush(TRACE_FILE); + } }