Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting accurate readings of Memory #206

Open
jsProj opened this issue Sep 12, 2024 · 1 comment · May be fixed by #207
Open

Getting accurate readings of Memory #206

jsProj opened this issue Sep 12, 2024 · 1 comment · May be fixed by #207

Comments

@jsProj
Copy link

jsProj commented Sep 12, 2024

How would I go about getting memory accurate readings?
When doing

(async () => {
    let QJS = await QuickJS.getQuickJS();
    let rt = QJS.newRuntime();
    let memoryLimit = 1024 * 32; // 32 KiB
    rt.setMemoryLimit(memoryLimit);
    rt.setMaxStackSize(2048);
    console.log(rt.computeMemoryUsage().consume(rt.getSystemContext().dump));
})().catch(console.error);

I get the result of

{
  malloc_limit: 32768, // bytes limit provided
  memory_used_size: 43402, // past bytes limit
  malloc_count: 835,
  memory_used_count: 835,
  atom_count: 486,
  atom_size: 16490,
  str_count: 0,
  str_size: 0,
  obj_count: 145,
  obj_size: 6960,
  prop_count: 806,
  prop_size: 6968,
  shape_count: 52,
  shape_size: 10896,
  js_func_count: 0,
  js_func_size: 0,
  js_func_code_size: 0,
  js_func_pc2line_count: 0,
  js_func_pc2line_size: 0,
  c_func_count: 91,
  array_count: 1,
  fast_array_count: 1,
  fast_array_elements: 0,
  binary_object_count: 0,
  binary_object_size: 0
}

Not to mention the memory_used_size, before any contexts other than the system context, scales with the allowed malloc_limit.

@jsProj jsProj changed the title Getting accurate readings of Memory for a single context Getting accurate readings of Memor Sep 12, 2024
@jsProj jsProj changed the title Getting accurate readings of Memor Getting accurate readings of Memory Sep 12, 2024
@justjake justjake linked a pull request Sep 15, 2024 that will close this issue
@justjake
Copy link
Owner

I looked into enabling better memory accounting, but there's a bug in Emscripten which prevents us from using Emscripten's malloc_usable_size function; quickjs hard-codes this to 0 in Emscripten environments, and Emscripten STRICT=1 mode appears to disable injectable memory.

Work-in-progress PR here: #207

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants