Bug 230957 - [JSC] Add objectTypeCounts to JSGetMemoryUsageStatistics
Summary: [JSC] Add objectTypeCounts to JSGetMemoryUsageStatistics
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Basuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-09-29 08:54 PDT by Basuke Suzuki
Modified: 2021-09-29 17:20 PDT (History)
10 users (show)

See Also:


Attachments
PATCH (4.85 KB, patch)
2021-09-29 12:11 PDT, Basuke Suzuki
ysuzuki: review+
Details | Formatted Diff | Diff
PATCH (4.84 KB, patch)
2021-09-29 15:39 PDT, Basuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Basuke Suzuki 2021-09-29 08:54:35 PDT
It is very useful to have the numbers of each object types in the JS statistics.
Comment 1 Basuke Suzuki 2021-09-29 12:11:35 PDT
Created attachment 439639 [details]
PATCH
Comment 2 Basuke Suzuki 2021-09-29 12:14:26 PDT
Added memoryUsageStatistics() to jsc.

Input:

function dump(values, indent = '') {
    for (const key in values) {
        const value = values[key];
        if (typeof value === 'object') {
            print(`${indent}${key}:`);
            dump(value, indent + '  ');
        } else
            print(`${indent}${key}: ${value}`);
    }
}
dump(memoryUsageStatistics());

Output:

heapSize: 0
heapCapacity: 344064
extraMemorySize: 0
objectCount: 0
protectedObjectCount: 44
protectedGlobalObjectCount: 0
objectTypeCounts:
  JSProxy: 1
  Promise: 1
  Callee: 2
  Atomics: 1
...
Comment 3 Yusuke Suzuki 2021-09-29 14:48:47 PDT
Comment on attachment 439639 [details]
PATCH

I think this is fine. r=me
Comment 4 Ross Kirsling 2021-09-29 14:56:53 PDT
Comment on attachment 439639 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=439639&action=review

> Source/JavaScriptCore/API/JSBase.cpp:208
> +    JSObject* objectTypeCounts = constructEmptyObject(globalObject);

I think you could do `constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure())` since this object is just holding key-value pairs and doesn't need access to the Object prototype.

> Source/JavaScriptCore/API/JSBasePrivate.h:74
> + objectTypeCounts: object which has kind as key and its number as value for each GC objects 

I think something like "object with HeapCell kinds as keys and their current counts as values" would be clearer.
Comment 5 Basuke Suzuki 2021-09-29 15:39:41 PDT
Created attachment 439672 [details]
PATCH
Comment 6 Basuke Suzuki 2021-09-29 15:41:01 PDT
Thanks Ross.
Comment 7 EWS 2021-09-29 17:19:15 PDT
Committed r283286 (242313@main): <https://commits.webkit.org/242313@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 439672 [details].
Comment 8 Radar WebKit Bug Importer 2021-09-29 17:20:27 PDT
<rdar://problem/83696026>