Skip to content
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

dotnet-trace needs to work better with apps that has the EventSourceSupport feature switched off #46047

Closed
LakshanF opened this issue Dec 14, 2020 · 4 comments
Labels
area-System.Diagnostics.Tracing enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@LakshanF
Copy link
Member

Description

When an out of proc tracing tool like dotnet-trace is used to collect a trace from an application that has been built with the feature EventSourceSupport turned off, it crashes the application. Also the generated trace file (nettraace.trace) is corrupted.

Repro steps

  • Build a runtime that allows EventSource feature to be turned off. Currently requires, EventPipe and NativeRuntimeEventSource types not to be rooted in corelib.
  • Create a HelloWorld app with the EventSource feature turned off <EventSourceSupport>false</EventSourceSupport>
  • Ensure that the app runs for a short time (ex. use Thread.Sleep) so as to mimic dotnet-trace collect
  • publish a trimmed app with libraries linked <TrimMode>link</TrimMode> and <PublishTrimmed>true</PublishTrimmed>
  • Use dotnet-trace to collect events from this app `(dotnet-trace collect -- .exe)'

Expected Behavior

dotnet-trace exits with a message indicating that EventSource is turned off

Current Behavior

`dotnet-trace collect -- test2.exe
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

Process : D:\work\Core\Test\Dec_6\test2\bin\Debug\net5.0\win-x64\publish\test2.exe
Output File : D:\work\Core\Test\Dec_6\test2\bin\Debug\net5.0\win-x64\publish\trace.nettrace

[00:00:00:01] Recording trace 0.00 (B)
Press or <Ctrl+C> to exit...

Trace completed.`

Reading the generated trace file, nettrace.trace, shows the following stack trace

***** Consider using /ContinueOnError to ignore the bad part of the trace. *****
Error: Exception EventPipe conversion: System.Exception: Read past end of stream.
at FastSerialization.IOStreamStreamReader.Fill(Int32 minimum)
at FastSerialization.MemoryStreamReader.ReadByte()
at FastSerialization.Deserializer.ReadObject()
at Microsoft.Diagnostics.Tracing.EventPipeEventSource.Process()
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CopyRawEvents(TraceEventDispatcher rawEvents, IStreamWriter writer)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.<>c__DisplayClass120_0.<FastSerialization.IFastSerializable.ToStream>b__0()
at FastSerialization.DeferedRegion.Write(Serializer serializer, Action toStream)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.FastSerialization.IFastSerializable.ToStream(Serializer serializer)
at FastSerialization.Serializer.WriteObjectData(IFastSerializable obj, Tags beginTag)
at FastSerialization.Serializer.WriteObjectRef(IFastSerializable obj, Boolean defered)
at FastSerialization.Serializer..ctor(IStreamWriter writer, IFastSerializable entryObject)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeEventSources(TraceEventDispatcher source, String etlxFilePath, TraceLogOptions options)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeDataFile(String filePath, String etlxFilePath, TraceLogOptions options)
at PerfView.EventPipePerfViewData.GetTraceLog(TextWriter log, Action`3 onLostEvents

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Diagnostics.Tracing untriaged New issue has not been triaged by the area owner labels Dec 14, 2020
@ghost
Copy link

ghost commented Dec 14, 2020

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

When an out of proc tracing tool like dotnet-trace is used to collect a trace from an application that has been built with the feature EventSourceSupport turned off, it crashes the application. Also the generated trace file (nettraace.trace) is corrupted.

Repro steps

  • Build a runtime that allows EventSource feature to be turned off. Currently requires, EventPipe and NativeRuntimeEventSource types not to be rooted in corelib.
  • Create a HelloWorld app with the EventSource feature turned off <EventSourceSupport>false</EventSourceSupport>
  • Ensure that the app runs for a short time (ex. use Thread.Sleep) so as to mimic dotnet-trace collect
  • publish a trimmed app with libraries linked <TrimMode>link</TrimMode> and <PublishTrimmed>true</PublishTrimmed>
  • Use dotnet-trace to collect events from this app `(dotnet-trace collect -- .exe)'

Expected Behavior

dotnet-trace exits with a message indicating that EventSource is turned off

Current Behavior

`dotnet-trace collect -- test2.exe
No profile or providers specified, defaulting to trace profile 'cpu-sampling'

Provider Name Keywords Level Enabled By
Microsoft-DotNETCore-SampleProfiler 0x0000F00000000000 Informational(4) --profile
Microsoft-Windows-DotNETRuntime 0x00000014C14FCCBD Informational(4) --profile

Process : D:\work\Core\Test\Dec_6\test2\bin\Debug\net5.0\win-x64\publish\test2.exe
Output File : D:\work\Core\Test\Dec_6\test2\bin\Debug\net5.0\win-x64\publish\trace.nettrace

[00:00:00:01] Recording trace 0.00 (B)
Press or <Ctrl+C> to exit...

Trace completed.`

Reading the generated trace file, nettrace.trace, shows the following stack trace

***** Consider using /ContinueOnError to ignore the bad part of the trace. *****
Error: Exception EventPipe conversion: System.Exception: Read past end of stream.
at FastSerialization.IOStreamStreamReader.Fill(Int32 minimum)
at FastSerialization.MemoryStreamReader.ReadByte()
at FastSerialization.Deserializer.ReadObject()
at Microsoft.Diagnostics.Tracing.EventPipeEventSource.Process()
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CopyRawEvents(TraceEventDispatcher rawEvents, IStreamWriter writer)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.<>c__DisplayClass120_0.<FastSerialization.IFastSerializable.ToStream>b__0()
at FastSerialization.DeferedRegion.Write(Serializer serializer, Action toStream)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.FastSerialization.IFastSerializable.ToStream(Serializer serializer)
at FastSerialization.Serializer.WriteObjectData(IFastSerializable obj, Tags beginTag)
at FastSerialization.Serializer.WriteObjectRef(IFastSerializable obj, Boolean defered)
at FastSerialization.Serializer..ctor(IStreamWriter writer, IFastSerializable entryObject)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeEventSources(TraceEventDispatcher source, String etlxFilePath, TraceLogOptions options)
at Microsoft.Diagnostics.Tracing.Etlx.TraceLog.CreateFromEventPipeDataFile(String filePath, String etlxFilePath, TraceLogOptions options)
at PerfView.EventPipePerfViewData.GetTraceLog(TextWriter log, Action`3 onLostEvents

Author: LakshanF
Assignees: -
Labels:

area-System.Diagnostics.Tracing, untriaged

Milestone: -

@tommcdon tommcdon added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Dec 14, 2020
@tommcdon tommcdon added this to the 6.0.0 milestone Dec 14, 2020
@josalem
Copy link
Contributor

josalem commented Dec 15, 2020

Expected Behavior
dotnet-trace exits with a message indicating that EventSource is turned off

I'm not sure this is something we'll be able to observe external to the application without runtime changes. More likely I would expect dotnet-trace to receive 0 events and have an empty trace file. EventSource being turned off isn't equivalent to EventPipe/DiagnosticServer being turned off.

We could add a special event that gets sent in the event we find EventSource types to be null at session creation time. That would give dotnet-trace and other readers the ability to know when EventSource is turned off/linked out.

@LakshanF
Copy link
Member Author

From a team discussion related to #43657

@tommcdon tommcdon modified the milestones: 6.0.0, 7.0.0 Jun 16, 2021
@mikelle-rogers
Copy link
Member

Attempting to repro this was not successful. I messaged @LakshanF, who could not repro it either. We are closing this issue.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.Tracing enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

No branches or pull requests

5 participants