Skip to content

Commit 5cd54e0

Browse files
author
Mike Kaufman
committed
Adding new trace event to emit just the heap size & usage ratio. This will be used to drive perf track & diag track integration
1 parent e782dc3 commit 5cd54e0

File tree

4 files changed

+46
-9
lines changed

4 files changed

+46
-9
lines changed

lib/Common/Memory/RecyclerTelemetryInfo.cpp

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Memory
2424

2525
RecyclerTelemetryInfo::RecyclerTelemetryInfo(Recycler * recycler, RecyclerTelemetryHostInterface* hostInterface) :
2626
passCount(0),
27+
perfTrackPassCount(0),
2728
hostInterface(hostInterface),
2829
gcPassStats(&HeapAllocator::Instance),
2930
recyclerStartTime(Js::Tick::Now()),
@@ -41,7 +42,7 @@ namespace Memory
4142
AssertOnValidThread(this, RecyclerTelemetryInfo::~RecyclerTelemetryInfo);
4243
if (this->gcPassStats.Empty() == false)
4344
{
44-
this->hostInterface->TransmitTelemetry(*this);
45+
this->hostInterface->TransmitGCTelemetryStats(*this);
4546
this->FreeGCPassStats();
4647
}
4748
}
@@ -147,6 +148,7 @@ namespace Memory
147148
{
148149
this->inPassActiveState = true;
149150
passCount++;
151+
perfTrackPassCount++;
150152
memset(stats, 0, sizeof(RecyclerTelemetryGCPassStats));
151153

152154
stats->startPassCollectionState = collectionState;
@@ -218,16 +220,30 @@ namespace Memory
218220

219221
lastPassStats->endPassProcessingElapsedTime = Js::Tick::Now() - start;
220222

221-
if (ShouldTransmit() && this->hostInterface != nullptr)
223+
// use separate events for perftrack specific data & general telemetry data
224+
if (this->ShouldTransmitPerfTrackEvents())
222225
{
223-
if (this->hostInterface->TransmitTelemetry(*this))
226+
if (this->hostInterface->TransmitHeapUsage(bucketReporter.GetTotalStats()->totalByteCount, bucketReporter.GetTotalStats()->objectByteCount, bucketReporter.GetTotalStats()->UsedRatio()))
227+
{
228+
this->ResetPerfTrackCounts();
229+
}
230+
}
231+
232+
if (this->ShouldTransmitGCStats() && this->hostInterface != nullptr)
233+
{
234+
if (this->hostInterface->TransmitGCTelemetryStats(*this))
224235
{
225236
this->lastTransmitTime = lastPassStats->passEndTimeTick;
226237
Reset();
227238
}
228239
}
229240
}
230241

242+
void RecyclerTelemetryInfo::ResetPerfTrackCounts()
243+
{
244+
this->perfTrackPassCount = 0;
245+
}
246+
231247
void RecyclerTelemetryInfo::Reset()
232248
{
233249
FreeGCPassStats();
@@ -248,12 +264,19 @@ namespace Memory
248264
}
249265
}
250266

251-
bool RecyclerTelemetryInfo::ShouldTransmit() const
267+
bool RecyclerTelemetryInfo::ShouldTransmitGCStats() const
252268
{
253269
// for now, try to transmit telemetry when we have >= 16
254270
return (this->hostInterface != nullptr && this->passCount >= 16);
255271
}
256272

273+
bool RecyclerTelemetryInfo::ShouldTransmitPerfTrackEvents() const
274+
{
275+
// for now, try to transmit telemetry when we have >= 16
276+
return (this->hostInterface != nullptr && this->perfTrackPassCount >= 128);
277+
}
278+
279+
257280
void RecyclerTelemetryInfo::IncrementUserThreadBlockedCount(Js::TickDelta waitTime, RecyclerWaitReason caller)
258281
{
259282
RecyclerTelemetryGCPassStats* lastPassStats = this->GetLastPassStats();

lib/Common/Memory/RecyclerTelemetryInfo.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ namespace Memory
2828
{
2929
public:
3030
virtual LPFILETIME GetLastScriptExecutionEndTime() const = 0;
31-
virtual bool TransmitTelemetry(RecyclerTelemetryInfo& rti) = 0;
31+
virtual bool TransmitGCTelemetryStats(RecyclerTelemetryInfo& rti) = 0;
3232
virtual bool TransmitTelemetryError(const RecyclerTelemetryInfo& rti, const char* msg) = 0;
33+
virtual bool TransmitHeapUsage(size_t totalHeapBytes, size_t usedHeapBytes, double heapUsedRatio) = 0;
3334
virtual bool IsTelemetryProviderEnabled() const = 0;
3435
virtual bool IsThreadBound() const = 0;
3536
virtual DWORD GetCurrentScriptThreadID() const = 0;
@@ -151,6 +152,7 @@ namespace Memory
151152
GCPassStatsList gcPassStats;
152153
Js::Tick lastTransmitTime;
153154
uint16 passCount;
155+
uint16 perfTrackPassCount;
154156
bool abortTelemetryCapture;
155157

156158
AllocatorDecommitStats threadPageAllocator_decommitStats;
@@ -160,11 +162,14 @@ namespace Memory
160162
AllocatorDecommitStats recyclerWithBarrierPageAllocator_decommitStats;
161163
#endif
162164

163-
bool ShouldTransmit() const;
165+
bool ShouldTransmitGCStats() const;
164166
void FreeGCPassStats();
165167
void Reset();
166168
void FillInSizeData(IdleDecommitPageAllocator* allocator, AllocatorSizes* sizes) const;
167169

170+
void ResetPerfTrackCounts();
171+
bool ShouldTransmitPerfTrackEvents() const;
172+
168173
static size_t GetProcessCommittedBytes();
169174
};
170175
#else

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,23 @@ LPFILETIME ThreadContext::ThreadContextRecyclerTelemetryHostInterface::GetLastSc
682682
#endif
683683
}
684684

685-
bool ThreadContext::ThreadContextRecyclerTelemetryHostInterface::TransmitTelemetry(RecyclerTelemetryInfo& rti)
685+
bool ThreadContext::ThreadContextRecyclerTelemetryHostInterface::TransmitGCTelemetryStats(RecyclerTelemetryInfo& rti)
686686
{
687687
#if defined(ENABLE_BASIC_TELEMETRY) && defined(NTBUILD)
688-
return Js::TransmitRecyclerTelemetry(rti);
688+
return Js::TransmitRecyclerTelemetryStats(rti);
689689
#else
690690
return false;
691691
#endif
692692
}
693693

694+
bool ThreadContext::ThreadContextRecyclerTelemetryHostInterface::TransmitHeapUsage(size_t totalHeapBytes, size_t usedHeapBytes, double heapUsedRatio)
695+
{
696+
#if defined(ENABLE_BASIC_TELEMETRY) && defined(NTBUILD)
697+
return Js::TransmitRecyclerHeapUsage(totalHeapBytes, usedHeapBytes, heapUsedRatio);
698+
#else
699+
return false;
700+
#endif
701+
}
694702

695703
bool ThreadContext::ThreadContextRecyclerTelemetryHostInterface::IsTelemetryProviderEnabled() const
696704
{

lib/Runtime/Base/ThreadContext.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,8 +1882,9 @@ class ThreadContext sealed :
18821882
}
18831883

18841884
virtual LPFILETIME GetLastScriptExecutionEndTime() const;
1885-
virtual bool TransmitTelemetry(RecyclerTelemetryInfo& rti);
1885+
virtual bool TransmitGCTelemetryStats(RecyclerTelemetryInfo& rti);
18861886
virtual bool TransmitTelemetryError(const RecyclerTelemetryInfo& rti, const char * msg);
1887+
virtual bool TransmitHeapUsage(size_t totalHeapBytes, size_t usedHeapBytes, double heapUsedRatio);
18871888
virtual bool ThreadContextRecyclerTelemetryHostInterface::IsThreadBound() const;
18881889
virtual DWORD ThreadContextRecyclerTelemetryHostInterface::GetCurrentScriptThreadID() const;
18891890
virtual bool IsTelemetryProviderEnabled() const;

0 commit comments

Comments
 (0)