Attempting to learn about a slow memory leak.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3887 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-06-04 03:01:12 +00:00
parent 5622db92a7
commit 2992b7e955
5 changed files with 114 additions and 0 deletions

View File

@ -93,6 +93,7 @@ typedef struct _tf_task_t
promiseid_t _nextPromise;
uv_loop_t _loop;
uv_timer_t gc_timer;
uv_timer_t trace_timer;
uint64_t last_hrtime;
uint64_t last_idle_time;
@ -732,6 +733,14 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int
}
JS_SetPropertyStr(context, result, "sqlite3_memory_percent", JS_NewFloat64(context, 100.0f * sqlite3_memory_used() / total_memory));
JSMemoryUsage js = { 0 };
JSRuntime* runtime = JS_GetRuntime(context);
JS_ComputeMemoryUsage(runtime, &js);
JS_SetPropertyStr(context, result, "js_malloc_percent", JS_NewFloat64(context, 100.0f * js.malloc_size / total_memory));
JS_SetPropertyStr(context, result, "uv_malloc_percent", JS_NewFloat64(context, 100.0f * tf_util_uv_get_malloc_size() / total_memory));
JS_SetPropertyStr(context, result, "socket_count", JS_NewInt32(context, tf_socket_get_count()));
JS_SetPropertyStr(context, result, "socket_open_count", JS_NewInt32(context, tf_socket_get_open_count()));
@ -1309,6 +1318,12 @@ static void _tf_task_promise_rejection_tracker(JSContext* context, JSValueConst
}
}
static void _tf_task_gc_timer(uv_timer_t* timer)
{
tf_task_t* task = timer->data;
JS_RunGC(task->_runtime);
}
static void _tf_task_trace_timer(uv_timer_t* timer)
{
tf_task_t* task = timer->data;
@ -1446,6 +1461,10 @@ tf_task_t* tf_task_create()
uv_timer_init(&task->_loop, &task->trace_timer);
uv_timer_start(&task->trace_timer, _tf_task_trace_timer, 100, 100);
uv_unref((uv_handle_t*)&task->trace_timer);
task->gc_timer.data = task;
uv_timer_init(&task->_loop, &task->gc_timer);
uv_timer_start(&task->gc_timer, _tf_task_gc_timer, 10000, 10000);
uv_unref((uv_handle_t*)&task->gc_timer);
task->idle.data = task;
uv_idle_init(&task->_loop, &task->idle);
uv_unref((uv_handle_t*)&task->idle);
@ -1645,10 +1664,15 @@ void tf_task_destroy(tf_task_t* task)
{
uv_close((uv_handle_t*)&task->trace_timer, _tf_task_on_handle_close);
}
if (task->gc_timer.data && !uv_is_closing((uv_handle_t*)&task->gc_timer))
{
uv_close((uv_handle_t*)&task->gc_timer, _tf_task_on_handle_close);
}
uv_close((uv_handle_t*)&task->idle, _tf_task_on_handle_close);
uv_close((uv_handle_t*)&task->prepare, _tf_task_on_handle_close);
while (task->trace_timer.data ||
task->gc_timer.data ||
task->idle.data ||
task->prepare.data)
{