@@ -108,48 +108,82 @@ CallResult<HermesValue>
108108hermesInternalGetInstrumentedStats (void *, Runtime &runtime, NativeArgs args) {
109109 GCScope gcScope (runtime);
110110 auto resultHandle = runtime.makeHandle (JSObject::create (runtime));
111+ MutableHandle<> valHandle{runtime};
111112
112113 // / Adds \p key with \p val to the resultHandle object.
113- auto addToResultHandle = [&](llvh::StringRef key, double v) {
114- GCScopeMarkerRAII marker{ gcScope};
115- HermesValue val = HermesValue::encodeUntrustedNumberValue (v);
116- Handle<> valHandle = runtime. makeHandle (val) ;
117- auto keySym = symbolForCStr (runtime, key.data ());
118- if (LLVM_UNLIKELY (keySym == ExecutionStatus::EXCEPTION)) {
119- return ExecutionStatus::EXCEPTION;
120- }
121-
122- return JSObject::defineNewOwnProperty (
123- resultHandle ,
124- runtime,
125- **keySym,
126- PropertyFlags::defaultNewNamedPropertyFlags (),
127- valHandle );
128- };
114+ auto addToResultHandle =
115+ [& gcScope, &runtime](
116+ Handle<JSObject> obj, llvh::StringRef key, Handle<> val) {
117+ GCScopeMarkerRAII marker{gcScope} ;
118+ auto keySym = symbolForCStr (runtime, key.data ());
119+ if (LLVM_UNLIKELY (keySym == ExecutionStatus::EXCEPTION)) {
120+ return ExecutionStatus::EXCEPTION;
121+ }
122+
123+ return JSObject::defineNewOwnProperty (
124+ obj ,
125+ runtime,
126+ **keySym,
127+ PropertyFlags::defaultNewNamedPropertyFlags (),
128+ val );
129+ };
129130
130131 // / Adds a property to resultHandle. \p key provides its name, and \p val,
131132 // / its value.
132- #define ADD_PROP (name, value ) \
133- if (LLVM_UNLIKELY ( \
134- addToResultHandle (name, value) == ExecutionStatus::EXCEPTION)) { \
135- return ExecutionStatus::EXCEPTION; \
133+ #define ADD_PROP (obj, name, value ) \
134+ valHandle = HermesValue::encodeUntrustedNumberValue (value); \
135+ if (LLVM_UNLIKELY ( \
136+ addToResultHandle (obj, name, valHandle) == \
137+ ExecutionStatus::EXCEPTION)) { \
138+ return ExecutionStatus::EXCEPTION; \
136139 }
137140
138141 auto &heap = runtime.getHeap ();
139142 GCBase::HeapInfo info;
140143 heap.getHeapInfo (info);
141144
142- ADD_PROP (" js_VMExperiments" , runtime.getVMExperimentFlags ());
143- ADD_PROP (" js_numGCs" , heap.getNumGCs ());
144- ADD_PROP (" js_gcCPUTime" , heap.getGCCPUTime ());
145- ADD_PROP (" js_gcTime" , heap.getGCTime ());
146- ADD_PROP (" js_totalAllocatedBytes" , info.totalAllocatedBytes );
147- ADD_PROP (" js_allocatedBytes" , info.allocatedBytes );
148- ADD_PROP (" js_heapSize" , info.heapSize );
149- ADD_PROP (" js_mallocSizeEstimate" , info.mallocSizeEstimate );
150- ADD_PROP (" js_vaSize" , info.va );
151- ADD_PROP (" js_externalBytes" , info.externalBytes );
152- ADD_PROP (" js_markStackOverflows" , info.numMarkStackOverflows );
145+ ADD_PROP (resultHandle, " js_VMExperiments" , runtime.getVMExperimentFlags ());
146+ ADD_PROP (resultHandle, " js_numGCs" , heap.getNumGCs ());
147+ ADD_PROP (resultHandle, " js_gcCPUTime" , heap.getGCCPUTime ());
148+ ADD_PROP (
149+ resultHandle, " js_avgGCCPUTime" , info.generalStats .gcCPUTime .average ());
150+ ADD_PROP (resultHandle, " js_maxGCCPUTime" , info.generalStats .gcCPUTime .max ());
151+ ADD_PROP (resultHandle, " js_gcTime" , heap.getGCTime ());
152+ ADD_PROP (
153+ resultHandle, " js_avgGCTime" , info.generalStats .gcWallTime .average ());
154+ ADD_PROP (resultHandle, " js_maxGCTime" , info.generalStats .gcWallTime .max ());
155+ ADD_PROP (resultHandle, " js_totalAllocatedBytes" , info.totalAllocatedBytes );
156+ ADD_PROP (resultHandle, " js_allocatedBytes" , info.allocatedBytes );
157+ ADD_PROP (resultHandle, " js_heapSize" , info.heapSize );
158+ ADD_PROP (resultHandle, " js_mallocSizeEstimate" , info.mallocSizeEstimate );
159+ ADD_PROP (resultHandle, " js_vaSize" , info.va );
160+ ADD_PROP (resultHandle, " js_externalBytes" , info.externalBytes );
161+ ADD_PROP (
162+ resultHandle,
163+ " js_peakAllocatedBytes" ,
164+ info.generalStats .usedBefore .max ());
165+ ADD_PROP (
166+ resultHandle, " js_peakLiveAfterGC" , info.generalStats .usedAfter .max ());
167+
168+ #ifdef HERMESVM_GC_HADES
169+ Handle<JSObject> specificStatsHandle =
170+ runtime.makeHandle (JSObject::create (runtime));
171+ auto res =
172+ addToResultHandle (resultHandle, " js_gcSpecific" , specificStatsHandle);
173+ if (LLVM_UNLIKELY (res == ExecutionStatus::EXCEPTION)) {
174+ return ExecutionStatus::EXCEPTION;
175+ }
176+
177+ ADD_PROP (
178+ specificStatsHandle,
179+ " js_numYGCollections" ,
180+ info.youngGenStats .numCollections );
181+ ADD_PROP (
182+ specificStatsHandle,
183+ " js_numOGCollections" ,
184+ info.fullStats .numCollections );
185+ ADD_PROP (specificStatsHandle, " js_numCompactions" , info.numCompactions );
186+ #endif
153187#undef ADD_PROP
154188
155189 return resultHandle.getHermesValue ();
0 commit comments