-
-
Notifications
You must be signed in to change notification settings - Fork 226
Automatically capture heap dumps #3667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
44b7d65
POC
jamescrosswell 157a4a9
Configurable level
jamescrosswell 67a1c38
Changed dependency from net5.0 to net6.0
jamescrosswell 4f8f917
Format code
getsentry-bot 0d1aa2d
Update MemoryMonitor.cs
jamescrosswell 5ceff11
Exclude on Android and iOS
jamescrosswell ae55ae9
Bundle dotnet-gcdump in the Sentry nuget package
jamescrosswell c5b75ad
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 60aeda0
Format code
getsentry-bot cc1a00e
Fixed Bindable tests
jamescrosswell b02fa28
Update CHANGELOG.md
jamescrosswell 0625662
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 1d12b7c
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell ecfbce3
Update CHANGELOG.md
jamescrosswell 1e6d29b
Tweaked the demos
jamescrosswell 5b0f08e
Revert "Bundle dotnet-gcdump in the Sentry nuget package"
jamescrosswell ba4bcd9
Unbundled GCDump from NuGet package
jamescrosswell a357e9f
Switched to built in GC.RegisterForFullGCNotification events for garb…
jamescrosswell b6c3bff
Tweaked settings to expedite full GC in Heap Dump sample
jamescrosswell e36dfef
Added TryGetDumpLocation tests
jamescrosswell d35477b
Added CaptureMemoryDump tests
jamescrosswell 4c0ccc8
Refactored MemoryMonitor to use triggers and debouncers
jamescrosswell ffad135
Format code
getsentry-bot 265e397
Fixed tests
jamescrosswell 7a3b109
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell da07de2
Format code
getsentry-bot 975b9b1
Added CheckMemoryUsage tests
jamescrosswell 38ad7bc
Fixed remaining BindableOptions tests
jamescrosswell ef3a33f
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 4b86619
Bundle dotnet-gcdump in Sentry.nupkg
jamescrosswell 08c9db4
Use bundled version of gcdump if it is present
jamescrosswell 169ef49
Delete buildlog.txt
jamescrosswell 2e6a0f1
Review feedback
jamescrosswell 87b76d8
Refactored error handling on garbage collection monitor to use a Cont…
jamescrosswell 3f15073
Comment in Dispose
jamescrosswell 2dfd4f4
Review feedback
jamescrosswell 99af671
Use _options.FileSystem
jamescrosswell acf93ab
Type
jamescrosswell 8708377
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 3b62d53
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 2a3d8b7
GCDump.props now downloads nuget directly, rather than installing dot…
jamescrosswell 3eb2f73
Created separate demo and tweaked the API
jamescrosswell 60f0b7e
Format code
getsentry-bot 70486da
Typo in transitive build file
jamescrosswell d2755db
Merge branch 'auto-heap-dump' of github.com:getsentry/sentry-dotnet i…
jamescrosswell 8133a63
Updated solution filters
jamescrosswell 58d9e55
Reverted to Continuation to handle errors in the gc monitor
jamescrosswell 7135767
Review feedback
jamescrosswell 22760c8
Update SentrySdk.cs
jamescrosswell f371304
Update Directory.Build.props
jamescrosswell 26c85b8
release: 14.12.1-dump1
getsentry-bot 0142d29
Workaround issue in release action
jamescrosswell 8a831fc
Revert "Workaround issue in release action"
jamescrosswell 056ec48
Merge branch 'release/14.12.1-dump1' into auto-heap-dump
29058f1
Revert "Merge branch 'release/14.12.1-dump1' into auto-heap-dump"
jamescrosswell 5469815
Review feedback
jamescrosswell f1c9e64
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 8a49c01
Update ApiApprovalTests.Run.DotNet9_0.verified.txt
jamescrosswell dbe9f60
Update action.yml
jamescrosswell be63db4
Revert "Update action.yml"
jamescrosswell 36e4a2b
Update workaround for slow release builds for ios
jamescrosswell 076e9f9
Removed async void unit tests
jamescrosswell 506fba1
Drop net6.0 target from Sentry.Tests
jamescrosswell 298f57c
Add diagnostic logging for Windows tests
jamescrosswell a234ef2
Update build.yml
jamescrosswell f4fba3a
Merge branch 'version-5.0.0' into auto-heap-dump
jamescrosswell 4eafc16
Disabled diagnostics output on windows tests
jamescrosswell a09ffef
Update build.yml
jamescrosswell b8cffed
Use mock GC implementation for MemoryMonitorTests
jamescrosswell b216a3c
Update Sentry.Tests.csproj
jamescrosswell e1ba7c2
Try disabling heapdump tests on Windows in CI
jamescrosswell 2c79a4a
Reverse skip condition
jamescrosswell 72c90b5
Try re-enabling GarbageCollectionMonitorTests on Windows
jamescrosswell cadd0cf
Try reinstating MemoryMonitorTests (constructor test changed)
jamescrosswell 84c436f
Update MemoryMonitor.cs
jamescrosswell 3a9ba29
Refactored Constructor_NoHeapdumpsConfigured_Throws
jamescrosswell 9fea039
Try re-enabling remaining MemoryMonitorTests
jamescrosswell 845378c
Re-enable remaining MemoryMonitorTests
jamescrosswell 4245a75
Unbundled dotnet-gcdump
jamescrosswell 5865245
Disable CaptureMemoryDump and TryGetDumpLocation tests
jamescrosswell d9b9306
Re-enable CaptureMemoryDump tests
jamescrosswell 13bfe6f
Disable CaptureMemoryDump and enable TryGetDumpLocation
jamescrosswell d330c2c
Fixed CaptureMemoryDump_CapturesDump
jamescrosswell 8127bb5
Added remarks about dotnet-gcdump dependency to options
jamescrosswell e628bb3
Merge branch 'version-5.0.0' into auto-heap-dump
bruno-garcia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added TryGetDumpLocation tests
- Loading branch information
commit e36dfef4dc1d3d1a766d6d92fe4534e0d0ab3dab
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| namespace Sentry.Testing; | ||
|
|
||
| /// <summary> | ||
| /// We most frequently call IDiagnosticLogger via extension methods on the SentryOptions class, which obscures what | ||
| /// we're expecting to receive via mocks when writing tests. This class provides some test extensions that mirror the | ||
| /// extensions provided for SentryOptions to make it easier to write tests that match the code they're testing. | ||
| /// </summary> | ||
| public static class SentryOptionsExtensions | ||
| { | ||
| private static SentryOptions ReceivedLog(this SentryOptions substitute, SentryLevel level) | ||
| { | ||
| substitute.DiagnosticLogger.Received().Log(level, Arg.Any<string>(), null, Arg.Any<object[]>()); | ||
| return substitute; | ||
| } | ||
|
|
||
| private static SentryOptions ReceivedLog(this SentryOptions substitute, SentryLevel level, string message, params object[] args) | ||
| { | ||
| substitute.DiagnosticLogger.Received().Log(level, message, null, args); | ||
| return substitute; | ||
| } | ||
|
|
||
| public static SentryOptions ReceivedLogInfo(this SentryOptions substitute) | ||
| => ReceivedLog(substitute, SentryLevel.Info); | ||
|
|
||
| public static SentryOptions ReceivedLogInfo(this SentryOptions substitute, string message, params object[] args) | ||
| => ReceivedLog(substitute, SentryLevel.Info, message, args); | ||
|
|
||
| public static SentryOptions ReceivedLogWarning(this SentryOptions substitute) | ||
| => ReceivedLog(substitute, SentryLevel.Warning); | ||
|
|
||
| public static SentryOptions ReceivedLogWarning(this SentryOptions substitute, string message, params object[] args) | ||
| => ReceivedLog(substitute, SentryLevel.Warning, message, args); | ||
|
|
||
| public static SentryOptions ReceivedLogError(this SentryOptions substitute) | ||
| => ReceivedLogError(substitute, string.Empty); | ||
|
|
||
| public static SentryOptions ReceivedLogError(this SentryOptions substitute, string message, params object[] args) | ||
| => ReceivedLog(substitute, SentryLevel.Error, message, args); | ||
|
|
||
| public static SentryOptions ReceivedLogError(this SentryOptions substitute, Exception exception, string message, | ||
| params object[] args) | ||
| { | ||
| substitute.DiagnosticLogger.Received().Log(SentryLevel.Error, message, exception, Arg.Any<object[]>()); | ||
| return substitute; | ||
| } | ||
| } |
This file contains hidden or 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,93 @@ | ||
| #if NET6_0_OR_GREATER && !(IOS || ANDROID) | ||
| namespace Sentry.Tests.Internals; | ||
|
|
||
| public class MemoryMonitorTests | ||
| { | ||
| private class Fixture | ||
| { | ||
| public SentryOptions Options { get; set; } = new() | ||
| { | ||
| Dsn = ValidDsn, | ||
| Debug = true, | ||
| DiagnosticLogger = Substitute.For<IDiagnosticLogger>() | ||
| }; | ||
| public Action<string> OnDumpCollected { get; set; } = _ => { }; | ||
| public short ThresholdPercentage { get; set; } = 5; | ||
|
|
||
| public MemoryMonitor GetSut() | ||
| { | ||
| Options.DiagnosticLogger?.IsEnabled(Arg.Any<SentryLevel>()).Returns(true); | ||
| return new(Options, ThresholdPercentage, OnDumpCollected); | ||
| } | ||
| } | ||
|
|
||
| private readonly Fixture _fixture = new(); | ||
|
|
||
| [Fact] | ||
| public void TryGetDumpLocation_DirectoryCreationFails_ReturnsNull() | ||
| { | ||
| // Arrange | ||
| _fixture.Options.FileSystem = Substitute.For<IFileSystem>(); | ||
| _fixture.Options.FileSystem.CreateDirectory(Arg.Any<string>()).Returns(false); | ||
| using var sut = _fixture.GetSut(); | ||
|
|
||
| // Act | ||
| var result = sut.TryGetDumpLocation(); | ||
|
|
||
| // Assert | ||
| result.Should().BeNull(); | ||
| _fixture.Options.FileSystem.Received().CreateDirectory(Arg.Any<string>()); | ||
| _fixture.Options.FileSystem.DidNotReceive().FileExists(Arg.Any<string>()); | ||
| _fixture.Options.ReceivedLogWarning("Failed to create a directory for memory dump ({0}).", Arg.Any<string>()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetDumpLocation_DumpFileExists_ReturnsNull() | ||
| { | ||
| // Arrange | ||
| _fixture.Options.FileSystem = Substitute.For<IFileSystem>(); | ||
| _fixture.Options.FileSystem.CreateDirectory(Arg.Any<string>()).Returns(true); | ||
| _fixture.Options.FileSystem.FileExists(Arg.Any<string>()).Returns(true); | ||
| using var sut = _fixture.GetSut(); | ||
|
|
||
| // Act | ||
| var result = sut.TryGetDumpLocation(); | ||
|
|
||
| // Assert | ||
| result.Should().BeNull(); | ||
| _fixture.Options.FileSystem.Received().CreateDirectory(Arg.Any<string>()); | ||
| _fixture.Options.FileSystem.Received().FileExists(Arg.Any<string>()); | ||
| _fixture.Options.ReceivedLogWarning("Duplicate dump file detected."); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetDumpLocation_Exception_LogsError() | ||
| { | ||
| // Arrange | ||
| _fixture.Options.FileSystem = Substitute.For<IFileSystem>(); | ||
| _fixture.Options.FileSystem.CreateDirectory(Arg.Any<string>()).Throws(_ => new Exception()); | ||
| using var sut = _fixture.GetSut(); | ||
|
|
||
| // Act | ||
| var result = sut.TryGetDumpLocation(); | ||
|
|
||
| // Assert | ||
| result.Should().BeNull(); | ||
| _fixture.Options.ReceivedLogError(Arg.Any<Exception>(), "Failed to resolve appropriate memory dump location."); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TryGetDumpLocation_ReturnsFilePath() | ||
| { | ||
| // Arrange | ||
| _fixture.Options.FileSystem = new FakeFileSystem(); | ||
| using var sut = _fixture.GetSut(); | ||
|
|
||
| // Act | ||
| var result = sut.TryGetDumpLocation(); | ||
|
|
||
| // Assert | ||
| result.Should().NotBeNull(); | ||
| } | ||
| } | ||
| #endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.