-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MemoryInfo to sentry event (#1337)
- Loading branch information
1 parent
eb191c9
commit 12c46e1
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#if NETCOREAPP3_0_OR_GREATER | ||
|
||
using System; | ||
using System.Text.Json; | ||
using Sentry.Extensibility; | ||
|
||
namespace Sentry | ||
{ | ||
internal sealed class MemoryInfo : IJsonSerializable | ||
{ | ||
public long AllocatedBytes { get; } | ||
public long FragmentedBytes { get; } | ||
public long HeapSizeBytes { get; } | ||
public long HighMemoryLoadThresholdBytes { get; } | ||
public long TotalAvailableMemoryBytes { get; } | ||
public long MemoryLoadBytes { get; } | ||
|
||
#if NET5_0_OR_GREATER | ||
public long TotalCommittedBytes { get; } | ||
public long PromotedBytes { get; } | ||
public long PinnedObjectsCount { get; } | ||
public double PauseTimePercentage { get; } | ||
public TimeSpan[] PauseDurations { get; } | ||
public long Index { get; } | ||
public int Generation { get; } | ||
public long FinalizationPendingCount { get; } | ||
public bool Compacted { get; } | ||
public bool Concurrent { get; } | ||
|
||
public MemoryInfo( | ||
long allocatedBytes, | ||
long fragmentedBytes, | ||
long heapSizeBytes, | ||
long highMemoryLoadThresholdBytes, | ||
long totalAvailableMemoryBytes, | ||
long memoryLoadBytes, | ||
long totalCommittedBytes, | ||
long promotedBytes, | ||
long pinnedObjectsCount, | ||
double pauseTimePercentage, | ||
long index, | ||
int generation, | ||
long finalizationPendingCount, | ||
bool compacted, | ||
bool concurrent, | ||
TimeSpan[] pauseDurations) | ||
{ | ||
AllocatedBytes = allocatedBytes; | ||
FragmentedBytes = fragmentedBytes; | ||
HeapSizeBytes = heapSizeBytes; | ||
HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes; | ||
TotalAvailableMemoryBytes = totalAvailableMemoryBytes; | ||
MemoryLoadBytes = memoryLoadBytes; | ||
TotalCommittedBytes = totalCommittedBytes; | ||
PromotedBytes = promotedBytes; | ||
PinnedObjectsCount = pinnedObjectsCount; | ||
PauseTimePercentage = pauseTimePercentage; | ||
PauseDurations = pauseDurations; | ||
Index = index; | ||
Generation = generation; | ||
FinalizationPendingCount = finalizationPendingCount; | ||
Compacted = compacted; | ||
Concurrent = concurrent; | ||
} | ||
#else | ||
public MemoryInfo( | ||
long allocatedBytes, | ||
long fragmentedBytes, | ||
long heapSizeBytes, | ||
long highMemoryLoadThresholdBytes, | ||
long totalAvailableMemoryBytes, | ||
long memoryLoadBytes) | ||
{ | ||
AllocatedBytes = allocatedBytes; | ||
FragmentedBytes = fragmentedBytes; | ||
HeapSizeBytes = heapSizeBytes; | ||
HighMemoryLoadThresholdBytes = highMemoryLoadThresholdBytes; | ||
TotalAvailableMemoryBytes = totalAvailableMemoryBytes; | ||
MemoryLoadBytes = memoryLoadBytes; | ||
} | ||
#endif | ||
public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? logger) | ||
{ | ||
writer.WriteStartObject(); | ||
|
||
writer.WriteNumber("allocatedBytes", AllocatedBytes); | ||
writer.WriteNumber("fragmentedBytes", FragmentedBytes); | ||
writer.WriteNumber("heapSizeBytes", HeapSizeBytes); | ||
writer.WriteNumber("highMemoryLoadThresholdBytes", HighMemoryLoadThresholdBytes); | ||
writer.WriteNumber("totalAvailableMemoryBytes", TotalAvailableMemoryBytes); | ||
writer.WriteNumber("memoryLoadBytes", MemoryLoadBytes); | ||
|
||
#if NET5_0_OR_GREATER | ||
writer.WriteNumber("totalCommittedBytes", TotalCommittedBytes); | ||
writer.WriteNumber("promotedBytes", PromotedBytes); | ||
writer.WriteNumber("pinnedObjectsCount", PinnedObjectsCount); | ||
writer.WriteNumber("pauseTimePercentage", PauseTimePercentage); | ||
writer.WriteNumber("index", Index); | ||
writer.WriteNumber("generation", Generation); | ||
writer.WriteNumber("finalizationPendingCount", FinalizationPendingCount); | ||
writer.WriteBoolean("compacted", Compacted); | ||
writer.WriteBoolean("concurrent", Concurrent); | ||
writer.WritePropertyName("pauseDurations"); | ||
writer.WriteStartArray(); | ||
foreach (var duration in PauseDurations) | ||
{ | ||
writer.WriteNumberValue(duration.TotalMilliseconds); | ||
} | ||
writer.WriteEndArray(); | ||
#endif | ||
writer.WriteEndObject(); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#if NETCOREAPP3_1_OR_GREATER | ||
using System.Text.Json; | ||
|
||
public class MemoryInfoTests | ||
{ | ||
[Fact] | ||
public void WriteTo() | ||
{ | ||
#if NET5_0_OR_GREATER | ||
var info = new MemoryInfo(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, true, false, new[] { TimeSpan.FromSeconds(1) }); | ||
#else | ||
var info = new MemoryInfo(1, 2, 3, 4, 5, 6); | ||
#endif | ||
|
||
var stream = new MemoryStream(); | ||
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true }); | ||
info.WriteTo(writer, null); | ||
writer.Flush(); | ||
var json = Encoding.UTF8.GetString(stream.ToArray()); | ||
Assert.NotNull(json); | ||
Assert.NotEmpty(json); | ||
//Validate json | ||
var serializer = new Newtonsoft.Json.JsonSerializer(); | ||
serializer.Deserialize(new Newtonsoft.Json.JsonTextReader(new StringReader(json))); | ||
} | ||
} | ||
#endif |