MCPcopy Create free account
hub / github.com/buke/quickjs-go / dump_memory_usage

Function dump_memory_usage

deps/quickjs/api-test.c:709–739  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

707}
708
709static void dump_memory_usage(void)
710{
711 JSMemoryUsage stats;
712
713 JSRuntime *rt = NULL;
714 JSContext *ctx = NULL;
715
716 rt = new_runtime();
717 ctx = JS_NewContext(rt);
718
719 //JS_SetDumpFlags(rt, JS_DUMP_PROMISE);
720
721 static const char code[] =
722 "globalThis.count = 0;"
723 "globalThis.actual = undefined;" // set by promise_hook_cb
724 "globalThis.expected = new Promise(resolve => resolve());"
725 "expected.then(_ => count++)";
726
727 JSValue evalVal = JS_Eval(ctx, code, strlen(code), "<input>", 0);
728 JS_FreeValue(ctx, evalVal);
729
730 FILE *temp = tmpfile();
731 assert(temp != NULL);
732 JS_ComputeMemoryUsage(rt, &stats);
733 JS_DumpMemoryUsage(temp, &stats, rt);
734 // JS_DumpMemoryUsage(stdout, &stats, rt);
735 fclose(temp);
736
737 JS_FreeContext(ctx);
738 JS_FreeRuntime(rt);
739}
740
741static void new_errors(void)
742{

Callers 1

mainFunction · 0.85

Calls 2

new_runtimeFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected