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

Doc: how to get event call stack from .nettrace events #1959

Open
verdie-g opened this issue Dec 9, 2023 · 1 comment
Open

Doc: how to get event call stack from .nettrace events #1959

verdie-g opened this issue Dec 9, 2023 · 1 comment

Comments

@verdie-g
Copy link
Contributor

verdie-g commented Dec 9, 2023

I'm a bit confused about how to read events from a .nettrace file. I think I'm supposed to use the EventPipeEventSource with such code

using EventPipeEventSource source = new(nettraceFileStream);
source.Clr.All += evt => evt.CallStack();
source.Process();

but TraceEvent.CallStack throws with Attempted to use TraceLog support on a non-TraceLog TraceEventSource so now it seems like I'm not using the right event source. What is the right API to use?

@verdie-g verdie-g changed the title Doc: how to event call stack from .nettrace events Doc: how to get event call stack from .nettrace events Dec 9, 2023
@brianrob
Copy link
Member

brianrob commented Jan 9, 2024

The issue that you're running into here is that the CallStack method can only be used on events that come from a TraceLogEventSource. You will need to create a TraceLog, and then you can call TraceLog.Events.GetSource(), register the callbacks, and then call Process on the source.

string etlxPath = TraceLog.CreateFromEventPipeDataFile(pathToNetTrace);
using TraceLog traceLog = new TraceLog(etlxPath);
using TraceLogEventSource source = traceLog.Events.GetSource();
source.Clr.All += evt => evt.CallStack();
source.Process();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants