-
Notifications
You must be signed in to change notification settings - Fork 363
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
Make DiagnosticClient start the client process to capture early stages events #1810
Comments
I am facing the same issue, and have to place the events that happen at the very beginning of my application as late as possible. |
@sebastienros The .NET 5 version of But I am not sure it is able to capture the very first events. The early events are fundamental. |
@raffaeler Here is the code I use to get it working: https://github.com/dotnet/crank/blob/master/src/Microsoft.Crank.Agent/Startup.cs#L3811-L3871 The delay could probably be smaller, from experience. |
Unless you are talking about the cli tools only, not the APIs, in which case the name of the exe would make more sense. |
I see you retrying in the loop, but this is not the best option in my case. I really need to trap the very first moments and I am afraid to lose something. |
Thanks @raffaeler! As you mentioned, capturing early runtime events isn't possible with the public set of APIs for diagnostics client library. That being said, this is already possible with .NET 5 runtime changes; we just haven't standardized on a public API yet - this is one of the items that we are going to be working on in the next few months (See #1794). I will actually use this issue to track the work on the diagnostics client library side. |
Great to hear that @sywhang Thanks! |
@raffaeler of course. In .NET 5 we added "diagnostic port" feature to the runtime, which allow the runtime to connect to the port. You can think of it as a reverse mechanism of the "diagnostics server" the runtime had since .NET Core 3.0. When you launch a process with the environment variable To make use of this, you need to do the following:
We're trying to make a public API that will let you do these with few lines of code (just like we did for starting an EventPipe session in .NET Core 3.1). You can read more about this in our docs on diagnostic ports as well. Hope that helps! |
Thank you @sywhang. I now understand better the meaning of the code I was reading in these hours. |
@sywhang I was able to make it work, but I need a small clarification please. Question: I expected to be able to call ResumeRuntime after creating the EventPipeEventSource, but if I do it, it hangs in the creation indefinitely. Is there not the risk to lose events on startup? What I am doing:
Thank you |
Hi @raffaeler, Apologies for the delay! I was away for vacation at the end of the year and this slipped off my radar after I came back...
The constructor to EventPipeEventSource blocks until the first event is read from the pipe. What you want to do is in the order of:
You won't lose events on startup because those are not written directly to the port. They're written to an internal buffer in the runtime that stores it until the events are flushed. As long as the buffer size is not set ridiculously small, and you started the session using the diagnostic ports, it should be early enough in the runtime startup to capture the interesting runtime events at startup. Hope that helps! |
Thank you @sywhang Two questions:
|
|
Thank you @josalem but I need to use that functionality from my own tool, therefore making public the methods required to use the reverse protocol is fundamental. With regards to dotnet-trace, I tried it as soon as .NET 5 was released, but I could not make it work. I will try again, but I defintely want integrate this functionality in my visual tool as the loading issues are too common. |
As John mentioned, this is one of the work items that we've committed to working on. At the moment it's not the highest priority because we have some work items we are trying to complete for .NET 6, but we hope to get started with this some time soon, starting with the API design.
We are currently in process of implementing |
Thank you for the good news @sywhang With regard to |
Sorry this issue slipped out of my inbox. |
Background and Motivation
The current constructor for
DiagnosticClient
only accepts the process id.Anyway there are certain events happening only at the very early stages. I am not sure whether starting the process as suspended (non trivial if done cross platform) could help as the diagnostic server would also be suspended.
Proposed Feature
The simplest solution would be to make
DiagnosticClient
accept the executable file name as well as its arguments so that the child process can be attached at the early stages and capture/collect the very first events.If this is already possible, please explain how.
The text was updated successfully, but these errors were encountered: