Closed Bug 720595 Opened 14 years ago Closed 14 years ago

Report how many JS GC bytes were allocated while generating about:memory

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

Attachments

(3 files, 1 obsolete file)

about:memory is generated with some JS code. The generation allocates some memory, which perturbs what is being measured. It'd be really nice to know how many bytes of memory are allocated when generating about:memory, i.e. how big the perturbation is. We could use this facility to reduce the perturbation. This wouldn't count how many bytes have been freed -- the point is that if a GC happens in the middle of the generation, that shouldn't affect the result. Some kind of counter that can be read before and after would be good. If it can cover both GC heap memory and malloc memory, that'd be even great. billm volunteered to do the JS side of this, I'll do the XPCOM plumbing.
Depends on: 531396
Attached patch patch to track collected bytes (obsolete) — — Splinter Review
I think this does what you want. Currently, we track the number of allocated bytes in rt->gcBytes. This patch adds a new fields, rt->gcCollectedBytes, that tracks the total number of bytes collected since startup. If you add rt->gcBytes + rt->gcCollectedBytes, you will get the total bytes ever allocated. A few caveats: First, gcCollectedBytes can overflow. But since you're probably going to be subtracting before and after values of (gcBytes + gcCollectedBytes), the overflow shouldn't matter as long as it doesn't happen during about:memory. And, in fact, you could detect the overflow if you were really careful, by checking if the before value is greater than the after value (that is, assuming you won't be allocated 2^64 bytes while collecting about:memory stats). Also, these numbers are collected in arena-sized increments. You could do better by iterating over the entire heap before and after about:memory runs, but I'm guessing you already knew that and decided against it.
Attachment #594261 - Flags: review?(n.nethercote)
Comment on attachment 594261 [details] [diff] [review] patch to track collected bytes Review of attachment 594261 [details] [diff] [review]: ----------------------------------------------------------------- Looks fine. I'll give f+ since I need to add the XPCOM plumbing before this lands.
Attachment #594261 - Flags: review?(n.nethercote) → feedback+
This is an updated version of Bill's original patch. It adds the JSAPI function JS::CumulativeGCBytes().
Assignee: wmccloskey → n.nethercote
Attachment #594261 - Attachment is obsolete: true
Attachment #624299 - Flags: review?(wmccloskey)
This patch adds nsIMemoryReporterManager::cumulativeGCBytes. It was khuey's suggestion to use nsIJSRuntimeService for getting hold of the JSRuntime.
Attachment #624300 - Flags: review?(bobbyholley+bmo)
This shows at the bottom of about:memory the number of GC bytes allocated while generating about:memory. This is only part of the memory allocated, but it has several important qualities: (a) it's cheap to get, (b) it's very stable. It'll be really useful to help reduce the perturbation caused by about:memory. I also added a count of the number of values shown, just because it seems useful.
Attachment #624301 - Flags: review?(justin.lebar+bug)
Summary: Need to know how many bytes of memory the JS engine has allocated → Report how many JS GC bytes were allocated while generating about:memory
Blocks: 755583
Comment on attachment 624300 [details] [diff] [review] Patch 2: Add nsIMemoryReporter::cumulativeGCBytes I don't think I'm the appropriate reviewer here. Bouncing to khuey, since this is apparently his idea.
Attachment #624300 - Flags: review?(bobbyholley+bmo) → review?(khuey)
Comment on attachment 624301 [details] [diff] [review] Patch 3: show cumulative GC bytes in about:memory r=me, but maybe make this copy-pasteable? The amount of memory allocated would be interesting to get from reporters, don't you think?
Attachment #624301 - Flags: review?(justin.lebar+bug) → review+
Comment on attachment 624299 [details] [diff] [review] Patch 1: add JS::CumulativeGCBytes() Review of attachment 624299 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/public/MemoryMetrics.h @@ +183,5 @@ > > extern JS_PUBLIC_API(size_t) > UserCompartmentCount(const JSRuntime *rt); > > +// This returns the number of bytes ever allocated on the GC heap. It's One space after the period. ::: js/src/jscompartment.h @@ +195,5 @@ > gcPreserveCode = preserving; > } > > size_t gcBytes; > + size_t gcCollectedBytes; Could you take out this field and the update to it in jsgc.cpp? It looks like you're not using it, and it costs us an op to maintain it. Also, I forgot to initialize it to 0.
Attachment #624299 - Flags: review?(wmccloskey) → review+
> Could you take out this field and the update to it in jsgc.cpp? In part 1: > --- a/js/src/MemoryMetrics.cpp > +++ b/js/src/MemoryMetrics.cpp > +JS_PUBLIC_API(int64_t) > +CumulativeGCBytes(const JSRuntime *rt) > +{ > + return rt->gcBytes + rt->gcCollectedBytes; > +}
(In reply to Justin Lebar [:jlebar] from comment #9) > > --- a/js/src/MemoryMetrics.cpp > > +++ b/js/src/MemoryMetrics.cpp > > +JS_PUBLIC_API(int64_t) > > +CumulativeGCBytes(const JSRuntime *rt) > > +{ > > + return rt->gcBytes + rt->gcCollectedBytes; > > +} That's a field of the runtime. I want the field on the compartment (with the same name) to be removed.
> That's a field of the runtime. I want the field on the compartment (with the same name) to be > removed. Ah, I totally missed "jscompartment.h". Thanks!
Comment on attachment 624300 [details] [diff] [review] Patch 2: Add nsIMemoryReporter::cumulativeGCBytes Review of attachment 624300 [details] [diff] [review]: ----------------------------------------------------------------- ::: xpcom/base/nsIMemoryReporter.idl @@ +345,1 @@ > }; You need to change the IID of the interface.
Attachment #624300 - Flags: review?(khuey) → review+
I won't land these patches. I ended up not using them that much :(
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: