-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathStructuredLogBatchProcessorBenchmarks.cs
More file actions
68 lines (57 loc) · 2.01 KB
/
StructuredLogBatchProcessorBenchmarks.cs
File metadata and controls
68 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using BenchmarkDotNet.Attributes;
using NSubstitute;
using Sentry.Extensibility;
using Sentry.Internal;
namespace Sentry.Benchmarks;
public class StructuredLogBatchProcessorBenchmarks
{
private Hub _hub;
private StructuredLogBatchProcessor _batchProcessor;
private SentryLog _log;
[Params(10, 100)]
public int BatchCount { get; set; }
[Params(100, 200, 1_000)]
public int OperationsPerInvoke { get; set; }
[GlobalSetup]
public void Setup()
{
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
Experimental =
{
EnableLogs = true,
},
};
var batchInterval = Timeout.InfiniteTimeSpan;
var clientReportRecorder = Substitute.For<IClientReportRecorder>();
clientReportRecorder
.When(static recorder => recorder.RecordDiscardedEvent(Arg.Any<DiscardReason>(), Arg.Any<DataCategory>(), Arg.Any<int>()))
.Throw<UnreachableException>();
var diagnosticLogger = Substitute.For<IDiagnosticLogger>();
diagnosticLogger
.When(static logger => logger.IsEnabled(Arg.Any<SentryLevel>()))
.Throw<UnreachableException>();
diagnosticLogger
.When(static logger => logger.Log(Arg.Any<SentryLevel>(), Arg.Any<string>(), Arg.Any<Exception>(), Arg.Any<object[]>()))
.Throw<UnreachableException>();
_hub = new Hub(options, DisabledHub.Instance);
_batchProcessor = new StructuredLogBatchProcessor(_hub, BatchCount, batchInterval, clientReportRecorder, diagnosticLogger);
_log = new SentryLog(DateTimeOffset.Now, SentryId.Empty, SentryLogLevel.Trace, "message");
}
[Benchmark]
public void EnqueueAndFlush()
{
for (var i = 0; i < OperationsPerInvoke; i++)
{
_batchProcessor.Enqueue(_log);
}
_batchProcessor.Flush();
}
[GlobalCleanup]
public void Cleanup()
{
_batchProcessor.Dispose();
_hub.Dispose();
}
}