Skip to content

Commit bbebefe

Browse files
lavenzgmeta-codesync[bot]
authored andcommitted
Update hermesInternalGetInstrumentedStats()
Summary: Add more stats to `hermesInternalGetInstrumentedStats()`. Hades specific stats are put into a sub-object keyed by `js_gcSpecificx`. Reviewed By: avp Differential Revision: D84768956 fbshipit-source-id: 0d8355ed24bcef1a88ec5adc22e604c0608c3606
1 parent b43a049 commit bbebefe

File tree

4 files changed

+73
-31
lines changed

4 files changed

+73
-31
lines changed

include/hermes/VM/GCBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ class GCBase {
365365
struct HeapInfo {
366366
/// Number of garbage collections (of any kind) since creation.
367367
unsigned numCollections{0};
368+
/// Number of compaction since creation (zero if non-generational GC).
369+
unsigned numCompactions{0};
368370
/// Total (cumulative) bytes allocated within the JS heap since creation.
369371
uint64_t totalAllocatedBytes{0};
370372
/// Number of currently allocated bytes within the JS heap. Some may be
@@ -386,6 +388,8 @@ class GCBase {
386388
/// Cumulative number of mark stack overflows in full collections
387389
/// (zero if non-generational GC).
388390
unsigned numMarkStackOverflows{0};
391+
/// Stats for general collection (including both YG and OG).
392+
CumulativeHeapStats generalStats;
389393
/// Stats for full collections (zeroes if non-generational GC).
390394
CumulativeHeapStats fullStats;
391395
/// Stats for collections in the young generation (zeroes if

lib/VM/GCBase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ void GCBase::printAllCollectedStats(llvh::raw_ostream &os) {
745745

746746
void GCBase::getHeapInfo(HeapInfo &info) {
747747
info.numCollections = cumStats_.numCollections;
748+
info.generalStats = cumStats_;
748749
}
749750

750751
void GCBase::getHeapInfoWithMallocSize(HeapInfo &info) {

lib/VM/JSLib/HermesInternal.cpp

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,48 +108,82 @@ CallResult<HermesValue>
108108
hermesInternalGetInstrumentedStats(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();

lib/VM/gcs/HadesGC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,9 @@ void HadesGC::getHeapInfo(HeapInfo &info) {
13231323
info.totalAllocatedBytes = totalAllocatedBytes_ + youngGen().used();
13241324
info.va = info.heapSize;
13251325
info.externalBytes = oldGen_.externalBytes() + getYoungGenExternalBytes();
1326+
info.youngGenStats = ygCumulativeStats_;
1327+
info.fullStats = ogCumulativeStats_;
1328+
info.numCompactions = numCompactions_;
13261329
}
13271330

13281331
void HadesGC::getHeapInfoWithMallocSize(HeapInfo &info) {

0 commit comments

Comments
 (0)