From 2624211f7d4c26cad433ca174f45e713ee228e2d Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 13:12:55 +0300 Subject: [PATCH 1/6] log built-in call --- runtime-light/stdlib/diagnostics/logs.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime-light/stdlib/diagnostics/logs.h b/runtime-light/stdlib/diagnostics/logs.h index c3c5a9725a..ff9e5b7348 100644 --- a/runtime-light/stdlib/diagnostics/logs.h +++ b/runtime-light/stdlib/diagnostics/logs.h @@ -107,3 +107,6 @@ struct std::formatter> { return std::format_to(ctx.out(), "{:.4f}", wrapper.value); } }; + +#define SAVE_BUILTIN_CALL_STATS(builtin_name, builtin_call) \ + (k2::log(std::to_underlying(kphp::log::level::debug), "built-in called: " builtin_name, {}), builtin_call) From 4bdcb7fb9b8c8b4534124c3460ccc96dd9ffdf7a Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 13:52:18 +0300 Subject: [PATCH 2/6] log in tests --- tests/kphp_tester.py | 1 + tests/python/lib/kphp_run_once.py | 461 +++++++++++++++++++++++++++++- tests/python/lib/testcase.py | 3 +- 3 files changed, 463 insertions(+), 2 deletions(-) diff --git a/tests/kphp_tester.py b/tests/kphp_tester.py index 810ce4d209..fe653525d7 100755 --- a/tests/kphp_tester.py +++ b/tests/kphp_tester.py @@ -75,6 +75,7 @@ def set_up_env_for_k2(self): self.env_vars["KPHP_ENABLE_GLOBAL_VARS_MEMORY_STATS"] = "0" self.env_vars["KPHP_PROFILER"] = "0" self.env_vars["KPHP_FORCE_LINK_RUNTIME"] = "1" + self.env_vars["KPHP_TRACKED_BUILTINS_LIST"] = KphpRunOnce.K2_KPHP_TRACKED_BUILTINS_LIST def make_test_file(file_path, test_tmp_dir, test_tags): diff --git a/tests/python/lib/kphp_run_once.py b/tests/python/lib/kphp_run_once.py index 1f8596717e..e0b79ab41f 100644 --- a/tests/python/lib/kphp_run_once.py +++ b/tests/python/lib/kphp_run_once.py @@ -8,6 +8,465 @@ class KphpRunOnce(KphpBuilder): + K2_KPHP_TRACKED_BUILTINS_LIST = " ".join([ + "_exception_set_location", + "_explode_tuple2", + "_explode_tuple3", + "_explode_tuple4", + "_tmp_substr", + "_tmp_trim", + "abs", + "acos", + "addcslashes", + "addslashes", + "array_chunk", + "array_column", + "array_combine", + "array_count_values", + "array_diff", + "array_diff_assoc", + "array_diff_key", + "array_fill", + "array_fill_keys", + "array_filter", + "array_filter_by_key", + "array_find", + "array_first_key", + "array_first_value", + "array_flip", + "array_intersect", + "array_intersect_assoc", + "array_intersect_key", + "array_is_vector", + "array_key_exists", + "array_key_first", + "array_key_last", + "array_keys", + "array_keys_as_ints", + "array_keys_as_strings", + "array_last_key", + "array_last_value", + "array_map", + "array_merge", + "array_merge_into", + "array_merge_recursive", + "array_merge_spread", + "array_pad", + "array_pop", + "array_push", + "array_rand", + "array_reduce", + "array_replace", + "array_reserve", + "array_reserve_from", + "array_reserve_map_int_keys", + "array_reserve_map_string_keys", + "array_reserve_vector", + "array_reverse", + "array_search", + "array_shift", + "array_slice", + "array_splice", + "array_sum", + "array_swap_int_keys", + "array_unique", + "array_unset", + "array_unshift", + "array_values", + "arsort", + "asort", + "atan", + "atan2", + "base_convert", + "base64_decode", + "base64_encode", + "basename", + "bcadd", + "bccomp", + "bcdiv", + "bcmod", + "bcmul", + "bcpow", + "bcscale", + "bcsqrt", + "bcsub", + "bin2hex", + "bindec", + "ceil", + "checkdate", + "chr", + "CompileTimeLocation$$__construct", + "CompileTimeLocation$$calculate", + "confdata_get_value", + "confdata_get_values_by_predefined_wildcard", + "cos", + "count", + "count_chars", + "crc32", + "create_vector", + "critical_error", + "ctype_alnum", + "ctype_digit", + "ctype_xdigit", + "curl_close", + "curl_errno", + "curl_error", + "curl_exec", + "curl_exec_concurrently", + "curl_getinfo", + "curl_init", + "curl_multi_add_handle", + "curl_multi_close", + "curl_multi_errno", + "curl_multi_exec", + "curl_multi_getcontent", + "curl_multi_info_read", + "curl_multi_init", + "curl_multi_remove_handle", + "curl_multi_select", + "curl_multi_setopt", + "curl_multi_strerror", + "curl_setopt", + "curl_setopt_array", + "date", + "date_default_timezone_get", + "date_default_timezone_set", + "DateInterval$$__construct", + "DateInterval$$createFromDateString", + "DateInterval$$format", + "DateTime$$__construct", + "DateTime$$add", + "DateTime$$createFromFormat", + "DateTime$$diff", + "DateTime$$format", + "DateTime$$getTimestamp", + "DateTime$$modify", + "DateTime$$setDate", + "DateTime$$setTime", + "DateTime$$setTimestamp", + "DateTimeImmutable$$__construct", + "DateTimeImmutable$$add", + "DateTimeImmutable$$createFromFormat", + "DateTimeImmutable$$diff", + "DateTimeImmutable$$format", + "DateTimeImmutable$$getTimestamp", + "DateTimeImmutable$$modify", + "DateTimeImmutable$$setTime", + "DateTimeImmutable$$setTimestamp", + "DateTimeZone$$__construct", + "debug_backtrace", + "decbin", + "dechex", + "deflate_add", + "deflate_init", + "deg2rad", + "die", + "echo", + "empty", + "err", + "error_get_last", + "error_reporting", + "Error$$getCode", + "Error$$getFile", + "Error$$getLine", + "Error$$getMessage", + "Error$$getTrace", + "Error$$getTraceAsString", + "estimate_memory_usage", + "Exception$$__construct", + "Exception$$getCode", + "Exception$$getFile", + "Exception$$getLine", + "Exception$$getMessage", + "Exception$$getTrace", + "Exception$$getTraceAsString", + "exit", + "exp", + "explode", + "extract_kphp_rpc_response_extra_info", + "fclose", + "fetch_double", + "fetch_int", + "fetch_long", + "fetch_string", + "fflush", + "file", + "file_get_contents", + "filesize", + "floor", + "fmod", + "fopen", + "fprintf", + "fread", + "function_exists", + "fwrite", + "get_class", + "get_engine_version", + "get_hash_of_class", + "get_job_workers_number", + "get_kphp_cluster_name", + "get_running_fork_id", + "getdate", + "getKeyByPos", + "gettype", + "getValueByPos", + "gmdate", + "gmmktime", + "gzcompress", + "gzdecode", + "gzencode", + "gzinflate", + "gzuncompress", + "hash", + "hash_equals", + "hash_hmac", + "header", + "headers_list", + "hex2bin", + "hexdec", + "hrtime", + "html_entity_decode", + "htmlentities", + "htmlspecialchars", + "htmlspecialchars_decode", + "http_build_query", + "iconv", + "implode", + "in_array", + "inet_pton", + "ini_get", + "instance_cache_delete", + "instance_cache_fetch", + "instance_cache_store", + "instance_cache_update_ttl", + "instance_cast", + "instance_deserialize", + "instance_deserialize_safe", + "instance_serialize", + "instance_to_array", + "ip2long", + "ip2ulong", + "is_array", + "is_bool", + "is_confdata_loaded", + "is_double", + "is_file", + "is_finite", + "is_float", + "is_infinite", + "is_int", + "is_integer", + "is_kphp_job_workers_enabled", + "is_nan", + "is_null", + "is_numeric", + "is_object", + "is_scalar", + "is_string", + "json_decode", + "json_encode", + "JsonEncoder$$from_json_impl", + "JsonEncoder$$getLastError", + "JsonEncoder$$to_json_impl", + "kml_get_custom_property", + "kml_xgboost_predict_matrix", + "kphp_get_runtime_config", + "kphp_set_context_on_error", + "KphpJobWorkerResponseError$$getError", + "KphpJobWorkerResponseError$$getErrorCode", + "KphpRpcRequestsExtraInfo$$get", + "krsort", + "ksort", + "lcfirst", + "lcg_value", + "levenshtein", + "likely", + "log", + "long2ip", + "ltrim", + "make_clone", + "max", + "mb_check_encoding", + "mb_stripos", + "mb_strlen", + "mb_strpos", + "mb_strtolower", + "mb_strtoupper", + "mb_substr", + "md5", + "memory_get_detailed_stats", + "memory_get_peak_usage", + "memory_get_total_usage", + "memory_get_usage", + "microtime", + "min", + "mktime", + "msgpack_deserialize", + "msgpack_serialize", + "mt_getrandmax", + "mt_rand", + "mt_srand", + "natsort", + "nl2br", + "numa_get_bound_node", + "number_format", + "ob_clean", + "ob_end_clean", + "ob_end_flush", + "ob_get_clean", + "ob_get_contents", + "ob_get_length", + "ob_get_level", + "ob_start", + "openssl_cipher_iv_length", + "openssl_decrypt", + "openssl_encrypt", + "openssl_get_cipher_methods", + "openssl_pkey_get_private", + "openssl_pkey_get_public", + "openssl_private_decrypt", + "openssl_public_encrypt", + "openssl_random_pseudo_bytes", + "openssl_sign", + "openssl_verify", + "openssl_x509_parse", + "ord", + "pack", + "parse_str", + "parse_url", + "php_sapi_name", + "php_uname", + "posix_getpid", + "posix_getpwuid", + "posix_getuid", + "preg_match", + "preg_match_all", + "preg_quote", + "preg_replace", + "preg_replace_callback", + "print", + "print_r", + "printf", + "rand", + "range", + "rawurldecode", + "rawurlencode", + "realpath", + "register_kphp_on_oom_callback", + "register_kphp_on_warning_callback", + "register_shutdown_function", + "round", + "rpc_clean", + "rpc_parse", + "rpc_queue_create", + "rpc_queue_empty", + "rpc_queue_next", + "rpc_server_fetch_request", + "rpc_server_store_response", + "rpc_tl_pending_queries_count", + "rpc_tl_query", + "rpc_tl_query_result", + "rpc_tl_query_result_synchronously", + "rsort", + "rtrim", + "sched_yield", + "sched_yield_sleep", + "serialize", + "set_detect_incorrect_encoding_names_warning", + "set_fail_rpc_on_int32_overflow", + "set_json_log_on_timeout_mode", + "set_migration_php8_warning", + "setlocale", + "sha1", + "shuffle", + "similar_text", + "sin", + "sizeof", + "sleep", + "sort", + "sprintf", + "sqrt", + "store_error", + "store_int", + "store_long", + "store_string", + "str_ends_with", + "str_ireplace", + "str_pad", + "str_repeat", + "str_replace", + "str_split", + "str_starts_with", + "strcasecmp", + "strcmp", + "stream_socket_client", + "strip_tags", + "stripos", + "stripslashes", + "stristr", + "strlen", + "strnatcmp", + "strncmp", + "strpos", + "strrev", + "strripos", + "strrpos", + "strstr", + "strtolower", + "strtotime", + "strtoupper", + "strtr", + "substr", + "substr_compare", + "substr_count", + "substr_replace", + "tan", + "time", + "to_array_debug", + "trim", + "typed_rpc_tl_query", + "typed_rpc_tl_query_result", + "typed_rpc_tl_query_result_synchronously", + "uasort", + "UberH3$$geoToH3", + "UberH3$$h3ToParent", + "ucfirst", + "ucwords", + "uksort", + "uniqid", + "unlink", + "unpack", + "unserialize", + "urldecode", + "urlencode", + "usleep", + "usort", + "var_dump", + "var_export", + "vk_json_encode", + "vk_json_encode_safe", + "vk_sp_deunicode", + "vk_sp_simplify", + "vk_sp_to_lower", + "vk_sp_to_upper", + "vk_stats_hll_count", + "vk_stats_hll_merge", + "vk_utf8_to_win", + "vk_win_to_utf8", + "vsprintf", + "wait", + "wait_concurrently", + "wait_multi", + "wait_queue_create", + "wait_queue_empty", + "wait_queue_next", + "wait_queue_push", + "warning", + "wordwrap", + "zstd_compress", + "zstd_uncompress", + ]) + def __init__(self, php_script_path, artifacts_dir, working_dir, php_bin, extra_include_dirs=None, vkext_dir=None, use_nocc=False, cxx_name="g++", k2_bin=None): super(KphpRunOnce, self).__init__( @@ -141,7 +600,7 @@ def run_with_kphp_and_k2(self, runs_cnt=1, args=[]): env = os.environ.copy() if "RUST_LOG" not in env: - env["RUST_LOG"] = "Warn" + env["RUST_LOG"] = "Debug" k2_runtime_proc = subprocess.Popen(cmd, cwd=self._kphp_runtime_tmp_dir, diff --git a/tests/python/lib/testcase.py b/tests/python/lib/testcase.py index bf7940e49f..fda3e6939f 100644 --- a/tests/python/lib/testcase.py +++ b/tests/python/lib/testcase.py @@ -298,7 +298,8 @@ def should_use_k2(cls): @classmethod def kphp_env_for_k2_server_component(cls): env = {"KPHP_MODE": "k2-server", "KPHP_ENABLE_FULL_PERFORMANCE_ANALYZE": "0", - "KPHP_PROFILER": "0", "KPHP_USER_BINARY_PATH": "component.so", "KPHP_FORCE_LINK_RUNTIME": "1"} + "KPHP_PROFILER": "0", "KPHP_USER_BINARY_PATH": "component.so", "KPHP_FORCE_LINK_RUNTIME": "1", + "KPHP_TRACKED_BUILTINS_LIST": KphpRunOnce.K2_KPHP_TRACKED_BUILTINS_LIST} return env def assertKphpNoTerminatedRequests(self): From 7852979466b08a9a7b46b53d4befed01cfc99e3b Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 14:42:27 +0300 Subject: [PATCH 3/6] ingnore debug and indo logs --- tests/python/lib/kphp_run_once.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/lib/kphp_run_once.py b/tests/python/lib/kphp_run_once.py index e0b79ab41f..00f6639759 100644 --- a/tests/python/lib/kphp_run_once.py +++ b/tests/python/lib/kphp_run_once.py @@ -611,7 +611,7 @@ def run_with_kphp_and_k2(self, runs_cnt=1, args=[]): self._kphp_server_stdout, _kphp_server_stderr = self._wait_proc(k2_runtime_proc) ignore_stderr = error_can_be_ignored( - ignore_patterns=[], + ignore_patterns=[".*DEBUG.*", ".*INFO.*"], binary_error_text=_kphp_server_stderr) if not ignore_stderr: From fdf5a5053c4bd80f6575a3dbc6437ea69a301c42 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 17:14:46 +0300 Subject: [PATCH 4/6] aggregate call logs in each test --- .../stdlib/diagnostics/functions-call-stats.h | 9 + runtime-light/stdlib/diagnostics/logs.h | 3 - .../lib/k2_kphp_tracked_builtins_list.txt | 456 +++++++++++++++++ tests/python/lib/kphp_run_once.py | 469 +----------------- 4 files changed, 476 insertions(+), 461 deletions(-) create mode 100644 runtime-light/stdlib/diagnostics/functions-call-stats.h create mode 100644 tests/python/lib/k2_kphp_tracked_builtins_list.txt diff --git a/runtime-light/stdlib/diagnostics/functions-call-stats.h b/runtime-light/stdlib/diagnostics/functions-call-stats.h new file mode 100644 index 0000000000..7a647ad203 --- /dev/null +++ b/runtime-light/stdlib/diagnostics/functions-call-stats.h @@ -0,0 +1,9 @@ +// Compiler for PHP (aka KPHP) +// Copyright (c) 2026 LLC «V Kontakte» +// Distributed under the GPL v3 License, see LICENSE.notice.txt + +#pragma once + +#include "runtime-light/stdlib/diagnostics/logs.h" + +#define SAVE_BUILTIN_CALL_STATS(builtin_name, builtin_call) (kphp::log::debug("built-in called: " builtin_name), builtin_call) diff --git a/runtime-light/stdlib/diagnostics/logs.h b/runtime-light/stdlib/diagnostics/logs.h index ff9e5b7348..c3c5a9725a 100644 --- a/runtime-light/stdlib/diagnostics/logs.h +++ b/runtime-light/stdlib/diagnostics/logs.h @@ -107,6 +107,3 @@ struct std::formatter> { return std::format_to(ctx.out(), "{:.4f}", wrapper.value); } }; - -#define SAVE_BUILTIN_CALL_STATS(builtin_name, builtin_call) \ - (k2::log(std::to_underlying(kphp::log::level::debug), "built-in called: " builtin_name, {}), builtin_call) diff --git a/tests/python/lib/k2_kphp_tracked_builtins_list.txt b/tests/python/lib/k2_kphp_tracked_builtins_list.txt new file mode 100644 index 0000000000..fe86adc4e4 --- /dev/null +++ b/tests/python/lib/k2_kphp_tracked_builtins_list.txt @@ -0,0 +1,456 @@ +_exception_set_location +_explode_tuple2 +_explode_tuple3 +_explode_tuple4 +_tmp_substr +_tmp_trim +abs +acos +addcslashes +addslashes +array_chunk +array_column +array_combine +array_count_values +array_diff +array_diff_assoc +array_diff_key +array_fill +array_fill_keys +array_filter +array_filter_by_key +array_find +array_first_key +array_first_value +array_flip +array_intersect +array_intersect_assoc +array_intersect_key +array_is_vector +array_key_exists +array_key_first +array_key_last +array_keys +array_keys_as_ints +array_keys_as_strings +array_last_key +array_last_value +array_map +array_merge +array_merge_into +array_merge_recursive +array_merge_spread +array_pad +array_pop +array_push +array_rand +array_reduce +array_replace +array_reserve +array_reserve_from +array_reserve_map_int_keys +array_reserve_map_string_keys +array_reserve_vector +array_reverse +array_search +array_shift +array_slice +array_splice +array_sum +array_swap_int_keys +array_unique +array_unset +array_unshift +array_values +arsort +asort +atan +atan2 +base_convert +base64_decode +base64_encode +basename +bcadd +bccomp +bcdiv +bcmod +bcmul +bcpow +bcscale +bcsqrt +bcsub +bin2hex +bindec +ceil +checkdate +chr +CompileTimeLocation$$__construct +CompileTimeLocation$$calculate +confdata_get_value +confdata_get_values_by_predefined_wildcard +cos +count +count_chars +crc32 +create_vector +critical_error +ctype_alnum +ctype_digit +ctype_xdigit +curl_close +curl_errno +curl_error +curl_exec +curl_exec_concurrently +curl_getinfo +curl_init +curl_multi_add_handle +curl_multi_close +curl_multi_errno +curl_multi_exec +curl_multi_getcontent +curl_multi_info_read +curl_multi_init +curl_multi_remove_handle +curl_multi_select +curl_multi_setopt +curl_multi_strerror +curl_setopt +curl_setopt_array +date +date_default_timezone_get +date_default_timezone_set +DateInterval$$__construct +DateInterval$$createFromDateString +DateInterval$$format +DateTime$$__construct +DateTime$$add +DateTime$$createFromFormat +DateTime$$diff +DateTime$$format +DateTime$$getTimestamp +DateTime$$modify +DateTime$$setDate +DateTime$$setTime +DateTime$$setTimestamp +DateTimeImmutable$$__construct +DateTimeImmutable$$add +DateTimeImmutable$$createFromFormat +DateTimeImmutable$$diff +DateTimeImmutable$$format +DateTimeImmutable$$getTimestamp +DateTimeImmutable$$modify +DateTimeImmutable$$setTime +DateTimeImmutable$$setTimestamp +DateTimeZone$$__construct +debug_backtrace +decbin +dechex +deflate_add +deflate_init +deg2rad +die +echo +empty +err +error_get_last +error_reporting +Error$$getCode +Error$$getFile +Error$$getLine +Error$$getMessage +Error$$getTrace +Error$$getTraceAsString +estimate_memory_usage +Exception$$__construct +Exception$$getCode +Exception$$getFile +Exception$$getLine +Exception$$getMessage +Exception$$getTrace +Exception$$getTraceAsString +exit +exp +explode +extract_kphp_rpc_response_extra_info +fclose +fetch_double +fetch_int +fetch_long +fetch_string +fflush +file +file_get_contents +filesize +floor +fmod +fopen +fprintf +fread +function_exists +fwrite +get_class +get_engine_version +get_hash_of_class +get_job_workers_number +get_kphp_cluster_name +get_running_fork_id +getdate +getKeyByPos +gettype +getValueByPos +gmdate +gmmktime +gzcompress +gzdecode +gzencode +gzinflate +gzuncompress +hash +hash_equals +hash_hmac +header +headers_list +hex2bin +hexdec +hrtime +html_entity_decode +htmlentities +htmlspecialchars +htmlspecialchars_decode +http_build_query +iconv +implode +in_array +inet_pton +ini_get +instance_cache_delete +instance_cache_fetch +instance_cache_store +instance_cache_update_ttl +instance_cast +instance_deserialize +instance_deserialize_safe +instance_serialize +instance_to_array +ip2long +ip2ulong +is_array +is_bool +is_confdata_loaded +is_double +is_file +is_finite +is_float +is_infinite +is_int +is_integer +is_kphp_job_workers_enabled +is_nan +is_null +is_numeric +is_object +is_scalar +is_string +json_decode +json_encode +JsonEncoder$$from_json_impl +JsonEncoder$$getLastError +JsonEncoder$$to_json_impl +kml_get_custom_property +kml_xgboost_predict_matrix +kphp_get_runtime_config +kphp_set_context_on_error +KphpJobWorkerResponseError$$getError +KphpJobWorkerResponseError$$getErrorCode +KphpRpcRequestsExtraInfo$$get +krsort +ksort +lcfirst +lcg_value +levenshtein +likely +log +long2ip +ltrim +make_clone +max +mb_check_encoding +mb_stripos +mb_strlen +mb_strpos +mb_strtolower +mb_strtoupper +mb_substr +md5 +memory_get_detailed_stats +memory_get_peak_usage +memory_get_total_usage +memory_get_usage +microtime +min +mktime +msgpack_deserialize +msgpack_serialize +mt_getrandmax +mt_rand +mt_srand +natsort +nl2br +numa_get_bound_node +number_format +ob_clean +ob_end_clean +ob_end_flush +ob_get_clean +ob_get_contents +ob_get_length +ob_get_level +ob_start +openssl_cipher_iv_length +openssl_decrypt +openssl_encrypt +openssl_get_cipher_methods +openssl_pkey_get_private +openssl_pkey_get_public +openssl_private_decrypt +openssl_public_encrypt +openssl_random_pseudo_bytes +openssl_sign +openssl_verify +openssl_x509_parse +ord +pack +parse_str +parse_url +php_sapi_name +php_uname +posix_getpid +posix_getpwuid +posix_getuid +preg_match +preg_match_all +preg_quote +preg_replace +preg_replace_callback +print +print_r +printf +rand +range +rawurldecode +rawurlencode +realpath +register_kphp_on_oom_callback +register_kphp_on_warning_callback +register_shutdown_function +round +rpc_clean +rpc_parse +rpc_queue_create +rpc_queue_empty +rpc_queue_next +rpc_server_fetch_request +rpc_server_store_response +rpc_tl_pending_queries_count +rpc_tl_query +rpc_tl_query_result +rpc_tl_query_result_synchronously +rsort +rtrim +sched_yield +sched_yield_sleep +serialize +set_detect_incorrect_encoding_names_warning +set_fail_rpc_on_int32_overflow +set_json_log_on_timeout_mode +set_migration_php8_warning +setlocale +sha1 +shuffle +similar_text +sin +sizeof +sleep +sort +sprintf +sqrt +store_error +store_int +store_long +store_string +str_ends_with +str_ireplace +str_pad +str_repeat +str_replace +str_split +str_starts_with +strcasecmp +strcmp +stream_socket_client +strip_tags +stripos +stripslashes +stristr +strlen +strnatcmp +strncmp +strpos +strrev +strripos +strrpos +strstr +strtolower +strtotime +strtoupper +strtr +substr +substr_compare +substr_count +substr_replace +tan +time +to_array_debug +trim +typed_rpc_tl_query +typed_rpc_tl_query_result +typed_rpc_tl_query_result_synchronously +uasort +UberH3$$geoToH3 +UberH3$$h3ToParent +ucfirst +ucwords +uksort +uniqid +unlink +unpack +unserialize +urldecode +urlencode +usleep +usort +var_dump +var_export +vk_json_encode +vk_json_encode_safe +vk_sp_deunicode +vk_sp_simplify +vk_sp_to_lower +vk_sp_to_upper +vk_stats_hll_count +vk_stats_hll_merge +vk_utf8_to_win +vk_win_to_utf8 +vsprintf +wait +wait_concurrently +wait_multi +wait_queue_create +wait_queue_empty +wait_queue_next +wait_queue_push +warning +wordwrap +zstd_compress +zstd_uncompress \ No newline at end of file diff --git a/tests/python/lib/kphp_run_once.py b/tests/python/lib/kphp_run_once.py index 00f6639759..e3c4fda6ef 100644 --- a/tests/python/lib/kphp_run_once.py +++ b/tests/python/lib/kphp_run_once.py @@ -1,4 +1,7 @@ +import collections import os +import pathlib +import re import shutil import subprocess import sys @@ -8,464 +11,9 @@ class KphpRunOnce(KphpBuilder): - K2_KPHP_TRACKED_BUILTINS_LIST = " ".join([ - "_exception_set_location", - "_explode_tuple2", - "_explode_tuple3", - "_explode_tuple4", - "_tmp_substr", - "_tmp_trim", - "abs", - "acos", - "addcslashes", - "addslashes", - "array_chunk", - "array_column", - "array_combine", - "array_count_values", - "array_diff", - "array_diff_assoc", - "array_diff_key", - "array_fill", - "array_fill_keys", - "array_filter", - "array_filter_by_key", - "array_find", - "array_first_key", - "array_first_value", - "array_flip", - "array_intersect", - "array_intersect_assoc", - "array_intersect_key", - "array_is_vector", - "array_key_exists", - "array_key_first", - "array_key_last", - "array_keys", - "array_keys_as_ints", - "array_keys_as_strings", - "array_last_key", - "array_last_value", - "array_map", - "array_merge", - "array_merge_into", - "array_merge_recursive", - "array_merge_spread", - "array_pad", - "array_pop", - "array_push", - "array_rand", - "array_reduce", - "array_replace", - "array_reserve", - "array_reserve_from", - "array_reserve_map_int_keys", - "array_reserve_map_string_keys", - "array_reserve_vector", - "array_reverse", - "array_search", - "array_shift", - "array_slice", - "array_splice", - "array_sum", - "array_swap_int_keys", - "array_unique", - "array_unset", - "array_unshift", - "array_values", - "arsort", - "asort", - "atan", - "atan2", - "base_convert", - "base64_decode", - "base64_encode", - "basename", - "bcadd", - "bccomp", - "bcdiv", - "bcmod", - "bcmul", - "bcpow", - "bcscale", - "bcsqrt", - "bcsub", - "bin2hex", - "bindec", - "ceil", - "checkdate", - "chr", - "CompileTimeLocation$$__construct", - "CompileTimeLocation$$calculate", - "confdata_get_value", - "confdata_get_values_by_predefined_wildcard", - "cos", - "count", - "count_chars", - "crc32", - "create_vector", - "critical_error", - "ctype_alnum", - "ctype_digit", - "ctype_xdigit", - "curl_close", - "curl_errno", - "curl_error", - "curl_exec", - "curl_exec_concurrently", - "curl_getinfo", - "curl_init", - "curl_multi_add_handle", - "curl_multi_close", - "curl_multi_errno", - "curl_multi_exec", - "curl_multi_getcontent", - "curl_multi_info_read", - "curl_multi_init", - "curl_multi_remove_handle", - "curl_multi_select", - "curl_multi_setopt", - "curl_multi_strerror", - "curl_setopt", - "curl_setopt_array", - "date", - "date_default_timezone_get", - "date_default_timezone_set", - "DateInterval$$__construct", - "DateInterval$$createFromDateString", - "DateInterval$$format", - "DateTime$$__construct", - "DateTime$$add", - "DateTime$$createFromFormat", - "DateTime$$diff", - "DateTime$$format", - "DateTime$$getTimestamp", - "DateTime$$modify", - "DateTime$$setDate", - "DateTime$$setTime", - "DateTime$$setTimestamp", - "DateTimeImmutable$$__construct", - "DateTimeImmutable$$add", - "DateTimeImmutable$$createFromFormat", - "DateTimeImmutable$$diff", - "DateTimeImmutable$$format", - "DateTimeImmutable$$getTimestamp", - "DateTimeImmutable$$modify", - "DateTimeImmutable$$setTime", - "DateTimeImmutable$$setTimestamp", - "DateTimeZone$$__construct", - "debug_backtrace", - "decbin", - "dechex", - "deflate_add", - "deflate_init", - "deg2rad", - "die", - "echo", - "empty", - "err", - "error_get_last", - "error_reporting", - "Error$$getCode", - "Error$$getFile", - "Error$$getLine", - "Error$$getMessage", - "Error$$getTrace", - "Error$$getTraceAsString", - "estimate_memory_usage", - "Exception$$__construct", - "Exception$$getCode", - "Exception$$getFile", - "Exception$$getLine", - "Exception$$getMessage", - "Exception$$getTrace", - "Exception$$getTraceAsString", - "exit", - "exp", - "explode", - "extract_kphp_rpc_response_extra_info", - "fclose", - "fetch_double", - "fetch_int", - "fetch_long", - "fetch_string", - "fflush", - "file", - "file_get_contents", - "filesize", - "floor", - "fmod", - "fopen", - "fprintf", - "fread", - "function_exists", - "fwrite", - "get_class", - "get_engine_version", - "get_hash_of_class", - "get_job_workers_number", - "get_kphp_cluster_name", - "get_running_fork_id", - "getdate", - "getKeyByPos", - "gettype", - "getValueByPos", - "gmdate", - "gmmktime", - "gzcompress", - "gzdecode", - "gzencode", - "gzinflate", - "gzuncompress", - "hash", - "hash_equals", - "hash_hmac", - "header", - "headers_list", - "hex2bin", - "hexdec", - "hrtime", - "html_entity_decode", - "htmlentities", - "htmlspecialchars", - "htmlspecialchars_decode", - "http_build_query", - "iconv", - "implode", - "in_array", - "inet_pton", - "ini_get", - "instance_cache_delete", - "instance_cache_fetch", - "instance_cache_store", - "instance_cache_update_ttl", - "instance_cast", - "instance_deserialize", - "instance_deserialize_safe", - "instance_serialize", - "instance_to_array", - "ip2long", - "ip2ulong", - "is_array", - "is_bool", - "is_confdata_loaded", - "is_double", - "is_file", - "is_finite", - "is_float", - "is_infinite", - "is_int", - "is_integer", - "is_kphp_job_workers_enabled", - "is_nan", - "is_null", - "is_numeric", - "is_object", - "is_scalar", - "is_string", - "json_decode", - "json_encode", - "JsonEncoder$$from_json_impl", - "JsonEncoder$$getLastError", - "JsonEncoder$$to_json_impl", - "kml_get_custom_property", - "kml_xgboost_predict_matrix", - "kphp_get_runtime_config", - "kphp_set_context_on_error", - "KphpJobWorkerResponseError$$getError", - "KphpJobWorkerResponseError$$getErrorCode", - "KphpRpcRequestsExtraInfo$$get", - "krsort", - "ksort", - "lcfirst", - "lcg_value", - "levenshtein", - "likely", - "log", - "long2ip", - "ltrim", - "make_clone", - "max", - "mb_check_encoding", - "mb_stripos", - "mb_strlen", - "mb_strpos", - "mb_strtolower", - "mb_strtoupper", - "mb_substr", - "md5", - "memory_get_detailed_stats", - "memory_get_peak_usage", - "memory_get_total_usage", - "memory_get_usage", - "microtime", - "min", - "mktime", - "msgpack_deserialize", - "msgpack_serialize", - "mt_getrandmax", - "mt_rand", - "mt_srand", - "natsort", - "nl2br", - "numa_get_bound_node", - "number_format", - "ob_clean", - "ob_end_clean", - "ob_end_flush", - "ob_get_clean", - "ob_get_contents", - "ob_get_length", - "ob_get_level", - "ob_start", - "openssl_cipher_iv_length", - "openssl_decrypt", - "openssl_encrypt", - "openssl_get_cipher_methods", - "openssl_pkey_get_private", - "openssl_pkey_get_public", - "openssl_private_decrypt", - "openssl_public_encrypt", - "openssl_random_pseudo_bytes", - "openssl_sign", - "openssl_verify", - "openssl_x509_parse", - "ord", - "pack", - "parse_str", - "parse_url", - "php_sapi_name", - "php_uname", - "posix_getpid", - "posix_getpwuid", - "posix_getuid", - "preg_match", - "preg_match_all", - "preg_quote", - "preg_replace", - "preg_replace_callback", - "print", - "print_r", - "printf", - "rand", - "range", - "rawurldecode", - "rawurlencode", - "realpath", - "register_kphp_on_oom_callback", - "register_kphp_on_warning_callback", - "register_shutdown_function", - "round", - "rpc_clean", - "rpc_parse", - "rpc_queue_create", - "rpc_queue_empty", - "rpc_queue_next", - "rpc_server_fetch_request", - "rpc_server_store_response", - "rpc_tl_pending_queries_count", - "rpc_tl_query", - "rpc_tl_query_result", - "rpc_tl_query_result_synchronously", - "rsort", - "rtrim", - "sched_yield", - "sched_yield_sleep", - "serialize", - "set_detect_incorrect_encoding_names_warning", - "set_fail_rpc_on_int32_overflow", - "set_json_log_on_timeout_mode", - "set_migration_php8_warning", - "setlocale", - "sha1", - "shuffle", - "similar_text", - "sin", - "sizeof", - "sleep", - "sort", - "sprintf", - "sqrt", - "store_error", - "store_int", - "store_long", - "store_string", - "str_ends_with", - "str_ireplace", - "str_pad", - "str_repeat", - "str_replace", - "str_split", - "str_starts_with", - "strcasecmp", - "strcmp", - "stream_socket_client", - "strip_tags", - "stripos", - "stripslashes", - "stristr", - "strlen", - "strnatcmp", - "strncmp", - "strpos", - "strrev", - "strripos", - "strrpos", - "strstr", - "strtolower", - "strtotime", - "strtoupper", - "strtr", - "substr", - "substr_compare", - "substr_count", - "substr_replace", - "tan", - "time", - "to_array_debug", - "trim", - "typed_rpc_tl_query", - "typed_rpc_tl_query_result", - "typed_rpc_tl_query_result_synchronously", - "uasort", - "UberH3$$geoToH3", - "UberH3$$h3ToParent", - "ucfirst", - "ucwords", - "uksort", - "uniqid", - "unlink", - "unpack", - "unserialize", - "urldecode", - "urlencode", - "usleep", - "usort", - "var_dump", - "var_export", - "vk_json_encode", - "vk_json_encode_safe", - "vk_sp_deunicode", - "vk_sp_simplify", - "vk_sp_to_lower", - "vk_sp_to_upper", - "vk_stats_hll_count", - "vk_stats_hll_merge", - "vk_utf8_to_win", - "vk_win_to_utf8", - "vsprintf", - "wait", - "wait_concurrently", - "wait_multi", - "wait_queue_create", - "wait_queue_empty", - "wait_queue_next", - "wait_queue_push", - "warning", - "wordwrap", - "zstd_compress", - "zstd_uncompress", - ]) + K2_KPHP_TRACKED_BUILTINS_LIST_PATH = pathlib.Path(__file__).parent / "k2_kphp_tracked_builtins_list.txt" + K2_KPHP_TRACKED_BUILTINS_LIST = K2_KPHP_TRACKED_BUILTINS_LIST_PATH.read_text() + K2_BUILTIN_CALLED_MSG_RE = re.compile(b"built-in called: ([\w$]+)") def __init__(self, php_script_path, artifacts_dir, working_dir, php_bin, extra_include_dirs=None, vkext_dir=None, use_nocc=False, cxx_name="g++", k2_bin=None): @@ -486,6 +34,7 @@ def __init__(self, php_script_path, artifacts_dir, working_dir, php_bin, self._vkext_dir = vkext_dir self._php_bin = php_bin self.k2_bin = k2_bin + self.builtin_calls = collections.defaultdict(int) def _get_extensions(self): if sys.platform == "darwin": @@ -619,6 +168,10 @@ def run_with_kphp_and_k2(self, runs_cnt=1, args=[]): "k2_runtime_stderr", k2_runtime_proc.returncode, content=_kphp_server_stderr) + + for match in self.K2_BUILTIN_CALLED_MSG_RE.finditer(_kphp_server_stderr): + self.builtin_calls[match[1]] += 1 + return k2_runtime_proc.returncode == 0 def compare_php_and_kphp_stdout(self): From a51b7f7fc48dec61beca8b5fb1adfca39ef67e19 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 18:05:00 +0300 Subject: [PATCH 5/6] fix RUST_LOG --- tests/python/lib/kphp_run_once.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/lib/kphp_run_once.py b/tests/python/lib/kphp_run_once.py index e3c4fda6ef..49db1d4885 100644 --- a/tests/python/lib/kphp_run_once.py +++ b/tests/python/lib/kphp_run_once.py @@ -149,7 +149,7 @@ def run_with_kphp_and_k2(self, runs_cnt=1, args=[]): env = os.environ.copy() if "RUST_LOG" not in env: - env["RUST_LOG"] = "Debug" + env["RUST_LOG"] = "Warn,component-log=Debug" k2_runtime_proc = subprocess.Popen(cmd, cwd=self._kphp_runtime_tmp_dir, From 820bc74890ac4fa19037099c45a339cfef6d968d Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 11 Mar 2026 19:13:59 +0300 Subject: [PATCH 6/6] SAVE_BUILTIN_CALL_STATS -> DUMP_BUILTIN_CALL_STATS --- compiler/code-gen/vertex-compiler.cpp | 2 +- runtime-light/stdlib/diagnostics/functions-call-stats.h | 2 +- runtime/runtime-builtin-stats.h | 2 +- tests/python/lib/k2_kphp_tracked_builtins_list.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/code-gen/vertex-compiler.cpp b/compiler/code-gen/vertex-compiler.cpp index a48574eeda..0ca596f4c0 100644 --- a/compiler/code-gen/vertex-compiler.cpp +++ b/compiler/code-gen/vertex-compiler.cpp @@ -917,7 +917,7 @@ void compile_func_call(VertexAdaptor root, CodeGenerator &W, func_ } if (is_function_call_should_be_tracked(func)) { - W << "SAVE_BUILTIN_CALL_STATS(\"" << func->name << "\", ("; + W << "DUMP_BUILTIN_CALL_STATS(\"" << func->name << "\", ("; } if (mode == func_call_mode::fork_call) { diff --git a/runtime-light/stdlib/diagnostics/functions-call-stats.h b/runtime-light/stdlib/diagnostics/functions-call-stats.h index 7a647ad203..c1914f1495 100644 --- a/runtime-light/stdlib/diagnostics/functions-call-stats.h +++ b/runtime-light/stdlib/diagnostics/functions-call-stats.h @@ -6,4 +6,4 @@ #include "runtime-light/stdlib/diagnostics/logs.h" -#define SAVE_BUILTIN_CALL_STATS(builtin_name, builtin_call) (kphp::log::debug("built-in called: " builtin_name), builtin_call) +#define DUMP_BUILTIN_CALL_STATS(builtin_name, builtin_call) (kphp::log::debug("built-in called: " builtin_name), builtin_call) diff --git a/runtime/runtime-builtin-stats.h b/runtime/runtime-builtin-stats.h index 1964b4d1a0..e8a0306a38 100644 --- a/runtime/runtime-builtin-stats.h +++ b/runtime/runtime-builtin-stats.h @@ -49,6 +49,6 @@ inline void save_virtual_builtin_call_stats(const kphp::stl::string