-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fixes issue when monitoring a process launched via the same command line #76965
Conversation
Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti Issue DetailsFixes dotnet/diagnostics#3366. A NullReferenceException was being thrown and caught because the CommandHandler in MetricsEventSource was being referenced before being initialized. Now custom metrics are displayed when trying to monitor a process in the same command line. Here is example output for a simple application with a custom meter that displays random values:
|
Can you include the callstack where the NullReferenceException occurs? A lot of the changes were swapping the Log property to a local parent field so does that also mean the static Log property was not initialized at that point? I want to understand what constraints we are working within :) |
@noahfalk we're trying to grab the original exception but running in to technical difficulties. The reason it fails is if you start a session before the runtime starts, you see the following scenario
|
Got it. What if we did something like this?
private CommandHandler Handler {
get {
if(_handler == null) {
Interlocked.CompareExchange(ref _handler, new CommandHandler(this), null);
}
return handler;
}
public CommandHandler(MetricsEventSource parent) {
Parent = parent;
}
public MetricsEventSource Parent { get; }
// some code that needs to use parent
Parent.Error("Something bad happened"); |
Works for me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes dotnet/diagnostics#3366. A NullReferenceException was being thrown and caught because the CommandHandler in MetricsEventSource was being referenced before being initialized. Now custom metrics are displayed when trying to monitor a process in the same command line. Here is example output for a simple application with a custom meter that displays random values:
Running
dotnet-counters monitor --counters System.Runtime,demo_meter -- countersbug.exe
will now output:Running
dotnet-counters monitor --counters demo_meter -- countersbug.exe
will now output: