Skip to content

Commit

Permalink
RavenDB-21561 - add the large allocations stats
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler committed Oct 12, 2023
1 parent cb60e8a commit 4248b2e
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions src/Raven.Server/Web/System/AdminGcDebugHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,34 @@ public async Task Allocations()
first = false;
writer.WritePropertyName(alloc.Type);
writer.WriteStartObject();
writer.WritePropertyName("Memory");
writer.WritePropertyName("Allocated");
writer.WriteString(new Size((long)alloc.Allocations, SizeUnit.Bytes).ToString());

var additionalLogging = alloc.Allocations != alloc.SmallObjectAllocations;
if (additionalLogging)
{
writer.WriteComma();
writer.WritePropertyName("AllocatedSmallObjects");
writer.WriteString(new Size((long)alloc.SmallObjectAllocations, SizeUnit.Bytes).ToString());
writer.WriteComma();
writer.WritePropertyName("AllocatedLargeObjects");
writer.WriteString(new Size((long)alloc.LargeObjectAllocations, SizeUnit.Bytes).ToString());
}

writer.WriteComma();
writer.WritePropertyName("Allocations");
writer.WritePropertyName("NumberOfAllocations");
writer.WriteInteger(alloc.NumberOfAllocations);

if (additionalLogging)
{
writer.WriteComma();
writer.WritePropertyName("NumberOfSmallObjectAllocations");
writer.WriteInteger(alloc.NumberOfSmallObjectAllocations);
writer.WriteComma();
writer.WritePropertyName("NumberOfLargeObjectAllocations");
writer.WriteInteger(alloc.NumberOfLargeObjectAllocations);
}

writer.WriteEndObject();
}

Expand Down Expand Up @@ -126,9 +149,25 @@ private class GcAllocationsEventListener : Expensive_GcEventListener

public class AllocationInfo
{
private ulong? _allocations;

public string Type;
public ulong Allocations;
public long NumberOfAllocations;
public ulong SmallObjectAllocations;
public ulong LargeObjectAllocations;
public long NumberOfSmallObjectAllocations;
public long NumberOfLargeObjectAllocations;

public ulong Allocations
{
get
{
// used for ordering
_allocations ??= SmallObjectAllocations + LargeObjectAllocations;
return _allocations.Value;
}
}

public long NumberOfAllocations => NumberOfSmallObjectAllocations + NumberOfLargeObjectAllocations;
}

protected override void OnEventWritten(EventWrittenEventArgs eventData)
Expand All @@ -144,8 +183,20 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
Type = type
};
}
info.Allocations += (ulong)eventData.Payload[3];
info.NumberOfAllocations++;
var allocations = (ulong)eventData.Payload[3];

var smallObjectAllocation = (uint)eventData.Payload[1] == 0x0;
if (smallObjectAllocation)
{
_allocations[type].SmallObjectAllocations += allocations;
_allocations[type].NumberOfSmallObjectAllocations++;
}
else
{
_allocations[type].LargeObjectAllocations += allocations;
_allocations[type].NumberOfLargeObjectAllocations++;
}

break;
}
}
Expand Down

0 comments on commit 4248b2e

Please sign in to comment.