After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 780106 - Add a way to dump the heap
Add a way to dump the heap
Status: RESOLVED FIXED
Product: gjs
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Juan Pablo Ugarte
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2017-03-15 19:22 UTC by Juan Pablo Ugarte
Modified: 2017-05-22 04:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add System.dumpHeapComplete() method (2.29 KB, patch)
2017-03-15 19:22 UTC, Juan Pablo Ugarte
none Details | Review
jsapi-util-args: Functions with only optional args (3.43 KB, patch)
2017-03-15 21:36 UTC, Philip Chimento
committed Details | Review
Add System.dumpHeapComplete() method (2.25 KB, patch)
2017-03-16 18:56 UTC, Juan Pablo Ugarte
committed Details | Review

Description Juan Pablo Ugarte 2017-03-15 19:22:44 UTC
Created attachment 348033 [details] [review]
Add System.dumpHeapComplete() method

It would be nice to have a way to dump JS heap for debugging purposes.
Comment 1 Philip Chimento 2017-03-15 21:36:04 UTC
Created attachment 348040 [details] [review]
jsapi-util-args: Functions with only optional args

An oversight in the original implementation: arguments were not
considered optional if all the arguments were optional.
Comment 2 Philip Chimento 2017-03-15 21:36:38 UTC
The System.dumpHeapComplete() patch requires this fix to gjs_parse_call_args(), as well.
Comment 3 Philip Chimento 2017-03-15 21:44:12 UTC
Review of attachment 348033 [details] [review]:

Thanks! A few small comments.

::: modules/system.cpp
@@ +109,3 @@
+        return false;
+
+    FILE *file;

What is the use case for the mode argument? Why not always "w"?

@@ +113,3 @@
+        fclose(file);
+    }
+    if (!gjs_parse_call_args(context, "dumpHeapComplete", argv, "|ss",

style: braces around the else clause and 4-space indent

@@ +175,3 @@
     JS_FS("refcount", gjs_refcount, 1, GJS_MODULE_PROP_FLAGS),
     JS_FS("breakpoint", gjs_breakpoint, 0, GJS_MODULE_PROP_FLAGS),
+    JS_FS("dumpHeapComplete", gjs_dump_heap_complete, 0, GJS_MODULE_PROP_FLAGS),

Thinking about the name some more, "Complete" doesn't actually refer to anything outside of the SpiderMonkey API, so we should probably just call it "dumpHeap".
Comment 4 Cosimo Cecchi 2017-03-15 23:24:54 UTC
Review of attachment 348040 [details] [review]:

This one looks good.
Comment 5 Juan Pablo Ugarte 2017-03-16 18:01:17 UTC
(In reply to Philip Chimento from comment #3)
> +    FILE *file;
> 
> What is the use case for the mode argument? Why not always "w"?

Appending instead of truncating the file


> +    JS_FS("dumpHeapComplete", gjs_dump_heap_complete, 0,
> GJS_MODULE_PROP_FLAGS),
> 
> Thinking about the name some more, "Complete" doesn't actually refer to
> anything outside of the SpiderMonkey API, so we should probably just call it
> "dumpHeap".

Sure no problem
Comment 6 Juan Pablo Ugarte 2017-03-16 18:56:58 UTC
Created attachment 348114 [details] [review]
Add System.dumpHeapComplete() method
Comment 7 Philip Chimento 2017-03-19 05:45:37 UTC
Review of attachment 348114 [details] [review]:

::: gjs/jsapi-wrapper.h
@@ +36,3 @@
 #endif
 #include <jsapi.h>
+#include <jsfriendapi.h>

I forgot to mention the first time, this will need a rebase on master, it looks like this is applied to a mozjs31 point in the tree.

::: modules/system.cpp
@@ +104,3 @@
+    FILE *file;
+
+{

I missed this last time, but the signature has to be "|fs" so that the filename string is converted to filename encoding.

@@ +106,3 @@
+    if (!gjs_parse_call_args(context, "dumpHeap", argv, "|ss",
+                             "filename", &filename,
+    JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);

I'm still not convinced of the usefulness of being able to append / overwrite. At least, not enough to balance the low-level C fopen() API leaking into JS here. Could we not just always append except if the file doesn't exist?
Comment 8 Philip Chimento 2017-03-29 04:23:30 UTC
Comment on attachment 348040 [details] [review]
jsapi-util-args: Functions with only optional args

Attachment 348040 [details] pushed as cf0ac43 - jsapi-util-args: Functions with only optional args
Comment 9 Philip Chimento 2017-05-22 04:13:56 UTC
I rebased it and amended it to always append, so we can commit it for now. If you feel like allowing an extra parameter for overwriting, that can certainly be added in the future.