Skip to content

Commit

Permalink
Merge branch 'chore/integrate-traceevent' into feat/profiling-low-ove…
Browse files Browse the repository at this point in the history
…rhead
  • Loading branch information
bruno-garcia committed Aug 19, 2023
2 parents 5ff8f1a + b4f9485 commit 0bbb0bd
Show file tree
Hide file tree
Showing 29 changed files with 1,463 additions and 2,471 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
path = modules/Carthage
url = https://github.com/Carthage/Carthage
branch = xcframework-catalyst
[submodule "modules/perfview"]
path = modules/perfview
url = https://github.com/getsentry/perfview.git
7 changes: 3 additions & 4 deletions before.Sentry.sln.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project InitialTargets="RestoreSubmodule">
<!-- If Ben.Demystifer is not found, restore git submodules -->
<Target Name="RestoreSubmodule"
Condition="!Exists('modules\Ben.Demystifier\Ben.Demystifier.sln')">
<Message Importance="High" Text="Ben.Demystifer not found. Restoring git submodules." />
<!-- Restore git submodules if needed-->
<Target Name="RestoreSubmodule" Condition="!Exists('modules\Ben.Demystifier\Ben.Demystifier.sln') or !Exists('modules\perfview\PerfView.sln')">
<Message Importance="High" Text="Restoring git submodules." />
<Exec Command="git submodule update --init --recursive" />
</Target>
</Project>

Large diffs are not rendered by default.

71 changes: 30 additions & 41 deletions benchmarks/Sentry.Benchmarks/ProfilingBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,48 @@ namespace Sentry.Benchmarks;
public class ProfilingBenchmarks
{
private IHub _hub = Substitute.For<IHub>();
private ITransactionProfilerFactory _factory = new SamplingTransactionProfilerFactory(Path.GetTempPath(), new());
private SamplingTransactionProfilerFactory _factory;
private ITransactionProfiler _profiler;

[GlobalSetup(Targets = new string[] { nameof(Transaction), nameof(DoHardWorkWhileProfiling) })]
public void StartProfiler()
{
_factory = SamplingTransactionProfilerFactory.Create(new());
}

[GlobalCleanup(Targets = new string[] { nameof(Transaction), nameof(DoHardWorkWhileProfiling) })]
public void StopProfiler()
{
_profiler?.Finish();
_profiler?.CollectAsync(new Transaction("", "")).Wait();
_profiler = null;
_factory.Dispose();
_factory = null;
}

#region full transaction profiling
public IEnumerable<object[]> ProfilerArguments()
public IEnumerable<object[]> TransactionBenchmarkArguments()
{
foreach (var runtimeMs in new[] { 25, 100, 1000, 10000 })
{
foreach (var processing in new[] { true, false })
foreach (var collect in new[] { true, false })
{
yield return new object[] { runtimeMs, processing };
yield return new object[] { runtimeMs, collect };
}
}
}

// Run a profiled transaction. Profiler starts and stops for each transaction separately.
[Benchmark]
[ArgumentsSource(nameof(ProfilerArguments))]
public long Transaction(int runtimeMs, bool processing)
[ArgumentsSource(nameof(TransactionBenchmarkArguments))]
public long Transaction(int runtimeMs, bool collect)
{
var tt = new TransactionTracer(_hub, "test", "");
tt.TransactionProfiler = _factory.Start(tt, CancellationToken.None);
var result = RunForMs(runtimeMs);
tt.TransactionProfiler?.Finish();
tt.TransactionProfiler.Finish();
var transaction = new Transaction(tt);
if (processing)
if (collect)
{
var collectTask = tt.TransactionProfiler.CollectAsync(transaction);
collectTask.Wait();
Expand Down Expand Up @@ -97,11 +114,7 @@ public DiagnosticsClient DiagnosticsClientNew()
[Benchmark]
public void DiagnosticsSessionStartStop()
{
var session = DiagnosticsClientNew().StartEventPipeSession(
SampleProfilerSession.Providers,
SampleProfilerSession.RequestRundown,
SampleProfilerSession.CircularBufferMB
);
var session = DiagnosticsClientNew().StartEventPipeSession(SampleProfilerSession.Providers, true, SampleProfilerSession.CircularBufferMB);
session.EventStream.Dispose();
session.Dispose();
}
Expand Down Expand Up @@ -139,19 +152,10 @@ public void DiagnosticsSessionStartCopyStop(bool rundown, string provider)
session.Dispose();
}

// Same as DiagnosticsSessionStartCopyStop(rundown: true, provider: 'all')
[Benchmark]
public void SampleProfilerSessionStartStopFinishWait()
{
var session = SampleProfilerSession.StartNew(CancellationToken.None);
session.Stop();
session.FinishAsync().Wait();
}

[Benchmark]
public void SampleProfilerSessionStartStop()
{
var session = SampleProfilerSession.StartNew(CancellationToken.None);
using var session = SampleProfilerSession.StartNew();
session.Stop();
}
#endregion
Expand All @@ -163,30 +167,15 @@ public void SampleProfilerSessionStartStop()
[ArgumentsSource(nameof(OverheadRunArguments))]
public long DoHardWork(int n)
{
return ProfilingBenchmarks.FindPrimeNumber(n);
return FindPrimeNumber(n);
}

[BenchmarkCategory("overhead"), Benchmark]
[ArgumentsSource(nameof(OverheadRunArguments))]
public long DoHardWorkWhileProfiling(int n)
{
return ProfilingBenchmarks.FindPrimeNumber(n);
}

private ITransactionProfiler _profiler;

[GlobalSetup(Target = nameof(DoHardWorkWhileProfiling))]
public void StartProfiler()
{
_profiler = _factory.Start(new TransactionTracer(_hub, "", ""), CancellationToken.None);
}

[GlobalCleanup(Target = nameof(DoHardWorkWhileProfiling))]
public void StopProfiler()
{
_profiler?.Finish();
_profiler?.CollectAsync(new Transaction("", "")).Wait();
_profiler = null;
_profiler ??= _factory.Start(new TransactionTracer(_hub, "", ""), CancellationToken.None);
return FindPrimeNumber(n);
}
#endregion
}
33 changes: 33 additions & 0 deletions modules/make-internal-perfview.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function UpdateSourceFiles([string]$Path)
{
$files = Get-ChildItem -Recurse "$PSScriptRoot/perfview/$Path" -Filter '*.cs'
foreach ($file in $files)
{
$oldText = Get-Content $file.FullName -Raw
$text = $oldText

# Make types internal.
$text = $text -replace 'public( +([a-z ]+)?(class|struct|enum|interface|delegate) +)', 'internal$1'
$text = $text -creplace "(`n +)(class | struct | enum | interface) ", '$1internal $2 '

# Allow nullable types.
$text = "#nullable disable`n`n" + ($text -replace "#nullable disable[`n`r]+", '')

# Don't error out on obsolete code usage.
$text = $text -replace '(?<!// )\[Obsolete\(.+\)\]', '// $0'
$text = $text -replace '(?<!/* ), (Obsolete\(.+\))', '/* $0 */'

# Only write in case we see a change to avoid unnecessary git changes due to Encoding differences.
if ($oldText -ne $text)
{
Set-Content $file.FullName $text -NoNewline
}
}
}

UpdateSourceFiles -Path 'src/TraceEvent'
UpdateSourceFiles -Path 'src/FastSerialization'
UpdateSourceFiles -Path 'src/Utilities'
1 change: 1 addition & 0 deletions modules/perfview
Submodule perfview added at 9e1039
Loading

0 comments on commit 0bbb0bd

Please sign in to comment.