Skip to content

Commit 6362473

Browse files
Danil42RussiaDrDet
andauthored
changed some of the runtime logs to server logs (#1285)
Co-authored-by: Denis Vaksman <dr.denisv2016@yandex.ru>
1 parent 0c58fba commit 6362473

9 files changed

Lines changed: 55 additions & 27 deletions

File tree

runtime-common/core/memory-resource/resource_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class resource_allocator {
3737
static_assert(sizeof(value_type) <= max_value_type_size(), "memory limit");
3838
auto result = static_cast<value_type*>(memory_resource_.allocate(sizeof(value_type) * size));
3939
if (unlikely(!result)) {
40-
php_critical_error("not enough memory to continue");
40+
runtime_critical_error("not enough memory to continue");
4141
}
4242
return result;
4343
}

runtime-common/core/utils/kphp-assert-core.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44

55
#include "common/wrappers/likely.h"
66

7+
// For reporting php logic related errors happened during script execution
78
void php_debug(char const* message, ...) __attribute__((format(printf, 1, 2)));
89
void php_notice(char const* message, ...) __attribute__((format(printf, 1, 2)));
910
void php_warning(char const* message, ...) __attribute__((format(printf, 1, 2)));
1011
void php_error(char const* message, ...) __attribute__((format(printf, 1, 2)));
1112

13+
// For reporting internal runtime errors happened during script execution
14+
// void runtime_debug(char const* message, ...) __attribute__((format(printf, 1, 2)));
15+
// void runtime_notice(char const* message, ...) __attribute__((format(printf, 1, 2)));
16+
// void runtime_warning(char const* message, ...) __attribute__((format(printf, 1, 2)));
17+
void runtime_error(char const* message, ...) __attribute__((format(printf, 1, 2)));
18+
1219
[[noreturn]] void php_assert__(const char* msg, const char* file, int line);
1320
[[noreturn]] void critical_error_handler();
1421

@@ -24,3 +31,9 @@ void php_error(char const* message, ...) __attribute__((format(printf, 1, 2)));
2431
php_error("Critical error \"" format "\" in file %s on line %d", ##__VA_ARGS__, __FILE__, __LINE__); \
2532
critical_error_handler(); \
2633
} while (0)
34+
35+
#define runtime_critical_error(format, ...) \
36+
do { \
37+
runtime_error("Critical error \"" format "\" in file %s on line %d", ##__VA_ARGS__, __FILE__, __LINE__); \
38+
critical_error_handler(); \
39+
} while (0)

runtime-light/utils/php_assert.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ void php_error(char const* message, ...) {
6262
va_end(args);
6363
}
6464

65+
void runtime_error(char const* message, ...) {
66+
va_list args;
67+
va_start(args, message);
68+
php_warning_impl(false, std::to_underlying(LogLevel::Error), message, args); // TODO: fix error code and think about internal / user errors separation in K2
69+
va_end(args);
70+
}
71+
6572
void php_assert__(const char* msg, const char* file, int line) {
6673
php_error("Assertion \"%s\" failed in file %s on line %d", msg, file, line);
6774
critical_error_handler();

runtime/allocator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void* allocate(size_t size) noexcept {
104104
return heap_replacer->allocate(size);
105105
}
106106
if (unlikely(!script_allocator_enabled)) {
107-
php_critical_error("Trying to call allocate for non runned script, n = %zu", size);
107+
runtime_critical_error("Trying to call allocate for non runned script, n = %zu", size);
108108
return nullptr;
109109
}
110110

@@ -118,7 +118,7 @@ void* allocate0(size_t size) noexcept {
118118
return heap_replacer->allocate0(size);
119119
}
120120
if (unlikely(!script_allocator_enabled)) {
121-
php_critical_error("Trying to call allocate0 for non runned script, n = %zu", size);
121+
runtime_critical_error("Trying to call allocate0 for non runned script, n = %zu", size);
122122
return nullptr;
123123
}
124124

@@ -132,7 +132,7 @@ void* reallocate(void* mem, size_t new_size, size_t old_size) noexcept {
132132
return heap_replacer->reallocate(mem, new_size, old_size);
133133
}
134134
if (unlikely(!script_allocator_enabled)) {
135-
php_critical_error("Trying to call reallocate for non runned script, p = %p, new_size = %zu, old_size = %zu", mem, new_size, old_size);
135+
runtime_critical_error("Trying to call reallocate for non runned script, p = %p, new_size = %zu, old_size = %zu", mem, new_size, old_size);
136136
return mem;
137137
}
138138

@@ -277,7 +277,7 @@ void* memalign(size_t alignment, size_t size) {
277277
void* operator new(size_t size) {
278278
auto* res = std::malloc(size);
279279
if (!res) {
280-
php_critical_error("nullptr from malloc");
280+
runtime_critical_error("nullptr from malloc");
281281
}
282282
return res;
283283
}

runtime/inter-process-mutex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void handle_lock_error(pid_t* lock, const char* what) noexcept {
4343
}
4444
}
4545
} else if (errno != EAGAIN) {
46-
php_critical_error("Got unexpected error from futex %s: %s", what, std::strerror(errno));
46+
runtime_critical_error("Got unexpected error from futex %s: %s", what, std::strerror(errno));
4747
}
4848
}
4949

@@ -95,7 +95,7 @@ void inter_process_mutex::unlock() noexcept {
9595
const pid_t tid = get_main_thread_id();
9696
if (!__sync_bool_compare_and_swap(&lock_, tid, 0)) {
9797
if (futex(&lock_, FUTEX_UNLOCK_PI)) {
98-
php_critical_error("Got unexpected error from futex unlock: %s", std::strerror(errno));
98+
runtime_critical_error("Got unexpected error from futex unlock: %s", std::strerror(errno));
9999
}
100100
}
101101
dl::leave_critical_section();

runtime/memory_resource_impl/monotonic_runtime_buffer_resource.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ void monotonic_buffer_resource::critical_dump(void* mem, size_t size) const noex
1919
dl::write_last_malloc_replacement_stacktrace(malloc_replacement_stacktrace_buf.data() + strlen(descr),
2020
malloc_replacement_stacktrace_buf.size() - strlen(descr));
2121
}
22-
php_critical_error("Found unexpected memory piece:\n"
23-
"ptr: %p\n"
24-
"size: %zu\n"
25-
"memory_begin: %p\n"
26-
"memory_current: %p\n"
27-
"memory_end: %p\n"
28-
"memory_limit: %zu\n"
29-
"memory_used: %zu\n"
30-
"max_memory_used: %zu\n"
31-
"real_memory_used: %zu\n"
32-
"max_real_memory_used: %zu\n"
33-
"is_malloc_replaced: %d\n"
34-
"%s",
35-
mem, size, memory_begin_, memory_current_, memory_end_, stats_.memory_limit, stats_.memory_used, stats_.max_memory_used,
36-
stats_.real_memory_used, stats_.max_real_memory_used, dl::is_malloc_replaced(), malloc_replacement_stacktrace_buf.data());
22+
runtime_critical_error("Found unexpected memory piece:\n"
23+
"ptr: %p\n"
24+
"size: %zu\n"
25+
"memory_begin: %p\n"
26+
"memory_current: %p\n"
27+
"memory_end: %p\n"
28+
"memory_limit: %zu\n"
29+
"memory_used: %zu\n"
30+
"max_memory_used: %zu\n"
31+
"real_memory_used: %zu\n"
32+
"max_real_memory_used: %zu\n"
33+
"is_malloc_replaced: %d\n"
34+
"%s",
35+
mem, size, memory_begin_, memory_current_, memory_end_, stats_.memory_limit, stats_.memory_used, stats_.max_memory_used,
36+
stats_.real_memory_used, stats_.max_real_memory_used, dl::is_malloc_replaced(), malloc_replacement_stacktrace_buf.data());
3737
}
3838

3939
void monotonic_buffer_resource::raise_oom(size_t size) const noexcept {

runtime/net_events.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ kphp_event_timer* allocate_event_timer(double wakeup_time, int wakeup_callback_i
129129
dl::reallocate(event_timers_heap, sizeof(kphp_event_timer*) * 2 * event_timers_max_heap_size, sizeof(kphp_event_timer*) * event_timers_max_heap_size));
130130
event_timers_max_heap_size *= 2;
131131
if (event_timers_max_heap_size > EVENT_TIMERS_HEAP_INDEX_MASK) {
132-
php_critical_error("maximum number of event timers exceeded");
132+
runtime_critical_error("maximum number of event timers exceeded");
133133
}
134134
}
135135
i = event_timer_heap_move_up(et->wakeup_time, i);

runtime/php_assert.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "server/json-logger.h"
3333
#include "server/php-engine-vars.h"
34+
#include "server/server-log.h"
3435

3536
const char* engine_tag = "[";
3637
long long engine_tag_number = 0;
@@ -164,10 +165,11 @@ static void php_warning_impl(bool out_of_memory, int error_type, char const* mes
164165
}
165166

166167
if (is_demangled_stacktrace_logs_enabled) {
167-
vk::singleton<JsonLogger>::get().write_log_with_demangled_backtrace(buf, error_type, cur_time, buffer, nptrs,
168-
out_of_memory || die_on_fail || error_type == E_ERROR);
168+
vk::singleton<JsonLogger>::get().write_log_with_demangled_backtrace(
169+
buf, error_type, cur_time, buffer, nptrs, out_of_memory || die_on_fail || error_type == E_ERROR || error_type == static_cast<int>(ServerLog::Critical));
169170
} else {
170-
vk::singleton<JsonLogger>::get().write_log(buf, error_type, cur_time, buffer, nptrs, out_of_memory || die_on_fail || error_type == E_ERROR);
171+
vk::singleton<JsonLogger>::get().write_log(buf, error_type, cur_time, buffer, nptrs,
172+
out_of_memory || die_on_fail || error_type == E_ERROR || error_type == static_cast<int>(ServerLog::Critical));
171173
}
172174

173175
if (die_on_fail) {
@@ -205,6 +207,13 @@ void php_out_of_memory_warning(char const* message, ...) {
205207
va_end(args);
206208
}
207209

210+
void runtime_error(char const* message, ...) {
211+
va_list args;
212+
va_start(args, message);
213+
php_warning_impl(false, static_cast<int>(ServerLog::Critical), message, args);
214+
va_end(args);
215+
}
216+
208217
const char* php_uncaught_exception_error(const class_instance<C$Throwable>& ex) noexcept {
209218
const int64_t current_time = time(nullptr);
210219
const char* message = ex->$message.empty() ? "(empty)" : ex->$message.c_str();

server/php-engine.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,6 @@ int rpcx_execute(connection *c, int op, raw_message *raw) {
10311031
assert(result_len >= 0);
10321032

10331033
if (result_len == 0) {
1034-
log_server_warning("Got empty RPC result from %s, op = 0x%08x", pid_to_print(&remote_pid), static_cast<unsigned>(op));
10351034
return 0;
10361035
}
10371036

0 commit comments

Comments
 (0)