Track our own quickjs memory usage so that we can avoid expensive calls to JS_ComputeMemoryUsage.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3915 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-06-20 17:57:07 +00:00
parent f69e74ce53
commit c9e01f220d
5 changed files with 81 additions and 9 deletions

View File

@ -722,12 +722,7 @@ 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, "js_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_js_malloc_size() / total_memory));
JS_SetPropertyStr(context, result, "uv_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_uv_malloc_size() / total_memory));
JS_SetPropertyStr(context, result, "tls_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_tls_malloc_size() / total_memory));
JS_SetPropertyStr(context, result, "tf_malloc_percent", JS_NewFloat64(context, 100.0f * tf_mem_get_tf_malloc_size() / total_memory));
@ -1276,7 +1271,10 @@ tf_task_t* tf_task_create()
tf_task_t* task = tf_malloc(sizeof(tf_task_t));
*task = (tf_task_t) { 0 };
++_count;
task->_runtime = JS_NewRuntime();
JSMallocFunctions funcs = { 0 };
tf_get_js_malloc_functions(&funcs);
task->_runtime = JS_NewRuntime2(&funcs, NULL);
task->_context = JS_NewContext(task->_runtime);
JS_SetContextOpaque(task->_context, task);