Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
68bafaa
wip: in-memory tracelog
vaind May 4, 2023
f6657f5
in-memory tracelog support
vaind May 5, 2023
9f8727f
profiler - remove temp dir
vaind May 8, 2023
3833b5f
tracelog streaming
vaind May 8, 2023
ad5e21f
fix sample collection
vaind May 9, 2023
1510734
migrate downsampling & fix tests
vaind May 9, 2023
886a2e9
fix: SparseArray
vaind May 10, 2023
2b70a79
update benchmark & profile builder
vaind May 10, 2023
ba3b4e1
minor changes rundown issue investigation
vaind May 11, 2023
079a72c
Merge branch 'main' into feat/streaming-tracelog
vaind May 18, 2023
25592ba
separate rundown session during tracelog init
vaind May 19, 2023
aa3ff4d
fixes
vaind May 20, 2023
3f7b063
Merge branch 'main' into feat/streaming-tracelog
vaind May 22, 2023
9a780eb
update profiling benchmark results
vaind May 22, 2023
61d2718
Merge branch 'main' into feat/streaming-tracelog
vaind May 22, 2023
cc6119f
update tests
vaind May 23, 2023
9005697
Merge branch 'main' into feat/streaming-tracelog
vaind May 23, 2023
f88a20d
update tests
vaind May 23, 2023
f864e7c
fixes
vaind May 23, 2023
04d38a5
update tests to support streaming tracelog
vaind May 30, 2023
8b3691d
Merge branch 'main' into feat/streaming-tracelog
vaind May 30, 2023
9b51611
Merge branch 'main' into feat/streaming-tracelog
vaind Jun 4, 2023
d171989
Merge branch 'main' into feat/streaming-tracelog
vaind Aug 4, 2023
c7f6929
update to latest perfview
vaind Aug 4, 2023
5b159e1
fix test code
vaind Aug 16, 2023
f457e3a
Merge branch 'main' into feat/streaming-tracelog
vaind Aug 16, 2023
b4693e8
Merge branch 'main' into feat/streaming-tracelog
vaind Aug 21, 2023
2634169
Squashed commit of the following (PR #2555):
vaind Aug 21, 2023
670b6fe
perfview submodule setup - unalatered branch
vaind Aug 21, 2023
e89d574
chore: update changelog
vaind Aug 21, 2023
b7ca7b4
fixup: squash
vaind Aug 21, 2023
33e59c6
build
bruno-garcia Aug 22, 2023
4e4b63e
Merge branch 'main' into feat/streaming-tracelog
bruno-garcia Aug 22, 2023
11f2b34
add perfview feed
bruno-garcia Aug 22, 2023
223913a
ms feed pkg
bruno-garcia Aug 22, 2023
1617ef2
ms feed pkg
bruno-garcia Aug 22, 2023
0f5fc2f
ms feed pkg
bruno-garcia Aug 22, 2023
d970fbf
ms feed pkg
bruno-garcia Aug 22, 2023
12e53e5
test: profiler snapshot update
vaind Aug 22, 2023
7a00db9
fix CI
vaind Aug 23, 2023
ba89304
update perfview
vaind Aug 23, 2023
614ae76
fix CI
vaind Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip: in-memory tracelog
  • Loading branch information
vaind committed May 4, 2023
commit 68bafaabbfc57a91486f552b382a5aa215aa0c0b
100 changes: 12 additions & 88 deletions src/Sentry.Profiling/SamplingTransactionProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,31 +92,21 @@ public async Task<ProfileInfo> CollectAsync(Transaction transaction)
_options.LogDebug("Starting profile processing.");

_transaction = transaction;
using var traceLog = await CreateTraceLogAsync().ConfigureAwait(false);
using var nettraceStream = await _data.ConfigureAwait(false);
using var eventPipeEventSource = new EventPipeEventSource(nettraceStream);
using var traceLogEventSource = TraceLog.CreateFromEventPipeEventSource(eventPipeEventSource);

try
{
_options.LogDebug("Converting profile to Sentry format.");
_options.LogDebug("Converting profile to Sentry format.");

_cancellationToken.ThrowIfCancellationRequested();
var processor = new TraceLogProcessor(_options, traceLog)
{
MaxTimestampMs = _duration.Value.TotalMilliseconds
};

var profile = processor.Process(_cancellationToken);
_options.LogDebug("Profiling finished successfully.");
return CreateProfileInfo(transaction, profile);
}
finally
_cancellationToken.ThrowIfCancellationRequested();
var processor = new TraceLogProcessor(_options, traceLogEventSource)
{
traceLog.Dispose();
if (File.Exists(traceLog.FilePath))
{
_options.LogDebug("Removing temporarily file '{0}'.", traceLog.FilePath);
File.Delete(traceLog.FilePath);
}
}
MaxTimestampMs = _duration.Value.TotalMilliseconds
};

var profile = processor.Process(_cancellationToken);
_options.LogDebug("Profiling finished successfully.");
return CreateProfileInfo(transaction, profile);
}

internal static ProfileInfo CreateProfileInfo(Transaction transaction, SampleProfile profile)
Expand All @@ -134,70 +124,4 @@ internal static ProfileInfo CreateProfileInfo(Transaction transaction, SamplePro
Profile = profile
};
}

// We need the TraceLog for all the stack processing it does.
private async Task<TraceLog> CreateTraceLogAsync()
{
_cancellationToken.ThrowIfCancellationRequested();
Debug.Assert(_data is not null);
using var nettraceStream = await _data.ConfigureAwait(false);
using var eventSource = CreateEventPipeEventSource(nettraceStream);
return ConvertToETLX(eventSource);
}

// EventPipeEventSource(Stream stream) sets isStreaming = true even though the stream is pre-collected. This
// causes read issues when converting to ETLX. It works fine if we use the private constructor, setting false.
// TODO make a PR to change this
private EventPipeEventSource CreateEventPipeEventSource(MemoryStream nettraceStream)
{
var privateNewEventPipeEventSource = typeof(EventPipeEventSource).GetConstructor(
_commonBindingFlags,
new Type[] { typeof(PinnedStreamReader), typeof(string), typeof(bool) });

var eventSource = privateNewEventPipeEventSource?.Invoke(new object[] {
new PinnedStreamReader(nettraceStream, 16384, new SerializationConfiguration{ StreamLabelWidth = StreamLabelWidth.FourBytes }, StreamReaderAlignment.OneByte),
"stream",
false
}) as EventPipeEventSource;

if (eventSource is null)
{
throw new InvalidOperationException("Couldn't initialize EventPipeEventSource");
}

// TODO make downsampling conditional once this is available: https://github.com/dotnet/runtime/issues/82939
// _options.LogDebug("Profile will be downsampled before processing.");
new Downsampler().AttachTo(eventSource);

return eventSource;
}

private TraceLog ConvertToETLX(EventPipeEventSource source)
{
Debug.Assert(_transaction is not null);
var etlxPath = Path.Combine(_tempDirectoryPath, $"{_transaction.EventId}.etlx");
_options.LogDebug("Writing profile temporarily to '{0}'.", etlxPath);
if (File.Exists(etlxPath))
{
_options.LogDebug("Temporary file '{0}' already exists, deleting first.", etlxPath);
File.Delete(etlxPath);
}

_cancellationToken.ThrowIfCancellationRequested();
typeof(TraceLog)
.GetMethod(
"CreateFromEventPipeEventSources",
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static,
new Type[] { typeof(TraceEventDispatcher), typeof(string), typeof(TraceLogOptions) })?
.Invoke(null, new object[] { source, etlxPath, new TraceLogOptions() { ContinueOnError = true } });

if (!File.Exists(etlxPath))
{
throw new FileNotFoundException($"Profiler failed at CreateFromEventPipeEventSources() - temporary file doesn't exist", etlxPath);
}

return new TraceLog(etlxPath);
}

private readonly BindingFlags _commonBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
}
2 changes: 1 addition & 1 deletion src/Sentry.Profiling/Sentry.Profiling.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ProjectReference Include="..\..\src\Sentry\Sentry.csproj" />

<PackageReference Include="Microsoft.Diagnostics.NETCore.Client" Version="0.2.421201" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="3.1.2" />
<ProjectReference Include="/dev/perfview/src/TraceEvent/TraceEvent.csproj" />
</ItemGroup>

</Project>
9 changes: 4 additions & 5 deletions src/Sentry.Profiling/TraceEvent/TraceLogProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class TraceLogProcessor
private readonly Dictionary<SentryProfileStackTrace, int> _stackIndexes = new(100);

// A sparse array mapping from a ThreadIndex to an index in Profile.Threads.
private readonly SparseScalarArray<int> _threadIndexes;
private readonly SparseScalarArray<int> _threadIndexes = new(-1, 10);

// A sparse array mapping from an ActivityIndex to an index in Profile.Threads.
private readonly SparseScalarArray<int> _activityIndexes = new(-1, 100);
Expand Down Expand Up @@ -95,12 +95,11 @@ internal class TraceLogProcessor

public double MaxTimestampMs { get; set; } = double.MaxValue;

public TraceLogProcessor(SentryOptions options, TraceLog traceLog)
public TraceLogProcessor(SentryOptions options, TraceLogEventSource eventSource)
{
_threadIndexes = new(-1, traceLog.Threads.Count);
_options = options;
_traceLog = traceLog;
_eventSource = _traceLog.Events.GetSource();
_traceLog = eventSource.TraceLog;
_eventSource = eventSource;
_stackSource = new MutableTraceEventStackSource(_traceLog)
{
//_stackSource = new TraceEventStackSource(_eventLog.Events) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ private SampleProfile GetProfile()
}

using var eventLog = new TraceLog(etlxFilePath);
var processor = new TraceLogProcessor(new(), eventLog);
return processor.Process(CancellationToken.None);
// FIXME
// var processor = new TraceLogProcessor(new(), eventLog);
// return processor.Process(CancellationToken.None);
return new();
}

[Fact]
Expand Down