diff --git a/cache.inc.php b/cache.inc.php index 8826d13..741b212 100644 --- a/cache.inc.php +++ b/cache.inc.php @@ -234,7 +234,7 @@ function config_cache_fetch(ConfigFetchParams $params) : ConfigFetchResult $result = _config_cache_fetch($params); if($params->verbose) - echo "[CFG] Fetch from cache: " . round(microtime(true) - $t,2) . " sec.\n"; + config_log("Fetch from cache: " . round(microtime(true) - $t,2) . " sec."); return $result; } @@ -261,7 +261,7 @@ function _config_cache_fetch(ConfigFetchParams $params) : ConfigFetchResult if(array_search(false, $results_by_job, true/*strict*/) !== false) { if($params->verbose) - echo "[CFG] Result error detected, trying serial processing...\n"; + config_log("Result error detected, trying serial processing..."); $results_by_job = _config_worker_run_procs($params, $jobs, true); } } @@ -269,10 +269,10 @@ function _config_cache_fetch(ConfigFetchParams $params) : ConfigFetchResult $t = microtime(true); $result = _config_merge_fetch_results($params, $results_by_job); if($params->verbose) - echo "[CFG] Merge results: " . round(microtime(true) - $t,2) . " sec.\n"; + config_log("Merge results: " . round(microtime(true) - $t,2) . " sec."); if($params->verbose) - echo "[CFG] Miss(Fast)/Total: {$result->stales}($result->fast_jsons)/" . sizeof($result->all) . "\n"; + config_log("Miss(Fast)/Total: {$result->stales}($result->fast_jsons)/" . sizeof($result->all)); return $result; } diff --git a/config.inc.php b/config.inc.php index 7f8c90b..c50fae5 100644 --- a/config.inc.php +++ b/config.inc.php @@ -40,6 +40,11 @@ class ConfigGlobals } } +function config_log($msg) +{ + echo "[CFG] $msg\n"; +} + function config_get_cache_path(ConfigGlobals $globals, string $file) : string { return config_get_tmp_build_path($globals, $file . '.cacheb'); @@ -109,9 +114,9 @@ function config_bench_load(ConfigGlobals $globals, string $file) $parse_res = config_parse($globals->base_dirs, $file); if($parse_res->error !== 0) throw new Exception("Error({$parse_res->error}) while loading JSON from {$file}:\n" . $parse_res->error_descr); - echo "[CFG] Parse: " . (microtime(true) - $t) . "\n"; + config_log("Parse: " . (microtime(true) - $t)); $t = microtime(true); $config = config_load_from_kv_array($globals, $base_dir, $file, $parse_res->parsed_arr, $conf_id); - echo "[CFG] Load: " . (microtime(true) - $t) . "\n"; + config_log("Load: " . (microtime(true) - $t)); } diff --git a/pack.inc.php b/pack.inc.php index f494abe..2c1045f 100644 --- a/pack.inc.php +++ b/pack.inc.php @@ -52,11 +52,11 @@ function config_pack_bundle(ConfigPackParams $params) : string throw new Exception("Unknown binary format: {$params->binary_format}"); if($params->debug) - echo "[CFG] Packed entries: " . sizeof($params->cache_entries) . ", total: " . + config_log("Packed entries: " . sizeof($params->cache_entries) . ", total: " . kb($packed_data) . ", format: {$params->binary_format}, lz4: " . var_export($params->use_lz4, true) . ", refs: " . var_export($params->use_config_refs, true) . ", CRC: " . crc32($packed_data) . - ", " . round(microtime(true) - $t,2) . " sec.\n"; + ", " . round(microtime(true) - $t,2) . " sec."); return $packed_data; } diff --git a/scan.inc.php b/scan.inc.php index 458da2e..97d2820 100644 --- a/scan.inc.php +++ b/scan.inc.php @@ -88,7 +88,7 @@ function config_scan_files( } if($verbose) - echo "[CFG] File scan: {$result->count()}, done " . round(microtime(true) - $t,2) . " sec.\n"; + config_log("File scan: {$result->count()}, done " . round(microtime(true) - $t,2) . " sec."); return $result; } diff --git a/task.inc.php b/task.inc.php index 0c5a176..c5889d5 100644 --- a/task.inc.php +++ b/task.inc.php @@ -54,7 +54,7 @@ function _config_worker_func(ConfigFetchParams $params, array $job) : array list($idx, $start_time, $chunk) = $job; if($params->verbose) - echo "[CFG] Worker $idx (" . sizeof($chunk) . ") started (".round(microtime(true)-$start_time, 2)." sec)\n"; + config_log("Worker $idx (" . sizeof($chunk) . ") started (".round(microtime(true)-$start_time, 2)." sec)"); $fast_parser_num = 0; $results = array(); @@ -65,7 +65,7 @@ function _config_worker_func(ConfigFetchParams $params, array $job) : array list($base_dir, $file) = $chunk_data; if($params->verbose && $file_idx > 0 && ($file_idx % 500) == 0) - echo "[CFG] Worker $idx progress: " . round($file_idx / sizeof($chunk) * 100) . "% ...\n"; + config_log("Worker $idx progress: " . round($file_idx / sizeof($chunk) * 100) . "% ..."); $cache_file = config_get_cache_path($params->globals, $file); @@ -87,7 +87,7 @@ function _config_worker_func(ConfigFetchParams $params, array $job) : array } if($params->verbose) - echo "[CFG] Worker $idx done (".round(microtime(true)-$start_time, 2)." sec)\n"; + config_log("Worker $idx done (".round(microtime(true)-$start_time, 2)." sec)"); return $results; }