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

Remove AsyncCausalityTracer by logging into TplEventSource directly #38313

Merged
merged 5 commits into from
Jun 30, 2020

Conversation

sywhang
Copy link
Contributor

@sywhang sywhang commented Jun 24, 2020

For #37945

This PR adds a new cross-platform version of the old AsyncCausalityTracer which was removed in #36715 .

The cross-platform AsyncCausalityTracer is a subset of the old AsyncCausalityTracer and logs events through TplEventSource, and not the Windows AsyncCausalityTracer, removing the need for COM-Interop/WinRT support.

[Edit] After discussion, the PR has been modified to remove AsyncCausalityTracer and change all the call sites to call TplEventSource directly.

I've verified the VS/PerfView scenarios that depend on this feature works again with this fix. I've also verified that TplEventSource/TraceOperation/Start and TplEventSource/TraceOperation/Stop events are now getting emitted on Linux and macOS.

cc @noahfalk @stephentoub @brianrob

}
catch (Exception ex)
{
LogAndDisable(ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exceptions might get thrown? I'm not clear on why the try/catch is needed here and elsewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these may be a left-over from the original WinRT AsyncCausalityTracer implementation and may not be needed anymore.

}

internal static bool LoggingOn => listenerCnt > 0;
private static int listenerCnt = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s_listenerCount


namespace System.Threading.Tasks
{
internal static class AsyncCausalityTracer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the AsyncCausalityTracer type at all at this point? Could call sites just be updated to use TplEventSource directly, as with all of the other call sites to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need it since the WinRT dependent component from this class is removed - we could just update all the call sites to use TplEventSource directly. Would that be something you'd prefer over adding AsyncCausalityTracer back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be something you'd prefer over adding AsyncCausalityTracer back?

Yes, that would be better - especially once the other cruft is deleted and these methods become trivial forwarders.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We can look at TplEventSource if we want to understand the full list of events that can be emitted. I'd only argue for keeping AsyncCausalityTracer if it were holding state, but that doesn't appear to be the case.

// we should catch and log exceptions but never propagate them.
private static void LogAndDisable(Exception ex)
{
Disable();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear why this is the right thing to do. If an exception occurs (and per my previous comment, I'm not sure why/when that would happen), we decrement the ref count, but we don't actually unregister anything. Doesn't that suggest that the count could just keep decreasing and decreasing? That would seem to a) mean you couldn't re-enable it eventually, and b) in an extreme case, it could wrap around and we'd end up seeing it as enabled again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception can be thrown when TplEventSource tries to write events into ETW and an error occurs (i.e. not enough memory). That being said, I'm not entirely sure why we should catch that exception and disable... Like Jan said, it is a remnant from the old WinRT AsyncCausalityTracer. I suppose we can remove this unless @noahfalk has any other thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be fine to remove these exception catches. I don't see any reason why an exception that was acceptable to throw from TplEventSource would be unacceptable to throw here.

@sywhang sywhang changed the title Add cross-platform AsyncCausalityTracer Remove AsyncCausalityTracer by logging into TplEventSource directly Jun 26, 2020
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

@sywhang sywhang merged commit 6710743 into dotnet:master Jun 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants