-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Move AsyncCausality to shared partition #22062
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#if !FEATURE_COMINTEROP | ||
|
||
using System.Diagnostics; | ||
|
||
namespace System.Threading.Tasks | ||
{ | ||
internal enum CausalityTraceLevel | ||
{ | ||
Required = 0, | ||
Important = 1, | ||
Verbose = 2, | ||
} | ||
|
||
internal enum AsyncCausalityStatus | ||
{ | ||
Started = 0, | ||
Completed = 1, | ||
Canceled = 2, | ||
Error = 3, | ||
} | ||
|
||
internal enum CausalityRelation | ||
{ | ||
AssignDelegate = 0, | ||
Join = 1, | ||
Choice = 2, | ||
Cancel = 3, | ||
Error = 4, | ||
} | ||
|
||
internal enum CausalitySynchronousWork | ||
{ | ||
CompletionNotification = 0, | ||
ProgressNotification = 1, | ||
Execution = 2, | ||
} | ||
|
||
// | ||
// Empty implementation of AsyncCausality events | ||
// | ||
internal static class AsyncCausalityTracer | ||
{ | ||
public static readonly bool LoggingOn = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be const. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory yes but we end up with a lot of C# Unreachable Code warnings, is that ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, we do not like warnings. Maybe property returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why property? this should not generate static ctor as it's the default value and codegen and linker can recognize this pattern easier without evaluating the property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you make it a property, linker can recognize property returning constant too and it is easier to do right. Properties returning constant cannot be overridden by reflection or other means. It makes them easy for optimizers to reason about. Static fields are much harder for optimizers to reason about because of reflection, cctor triggers, static fields set by debugger, etc. |
||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May call this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like dummy, will go with |
||
public static void EnableToETW(bool enabled) | ||
{ | ||
} | ||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
public static void TraceOperationCreation(CausalityTraceLevel traceLevel, int taskId, string operationName, ulong relatedContext) | ||
{ | ||
} | ||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
public static void TraceOperationCompletion(CausalityTraceLevel traceLevel, int taskId, AsyncCausalityStatus status) | ||
{ | ||
} | ||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
public static void TraceOperationRelation(CausalityTraceLevel traceLevel, int taskId, CausalityRelation relation) | ||
{ | ||
} | ||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
public static void TraceSynchronousWorkStart(CausalityTraceLevel traceLevel, int taskId, CausalitySynchronousWork work) | ||
{ | ||
} | ||
|
||
[Conditional("NOOP_ASYNCCASUALITYTRACER")] | ||
public static void TraceSynchronousWorkCompletion(CausalityTraceLevel traceLevel, CausalitySynchronousWork work) | ||
{ | ||
} | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,107 +2,69 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// | ||
// | ||
#if FEATURE_COMINTEROP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to condition in the project file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done that already just forgot to remove the #if |
||
|
||
using System; | ||
using System.Security; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
#if FEATURE_COMINTEROP | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
|
||
using WFD = Windows.Foundation.Diagnostics; | ||
#endif | ||
|
||
|
||
namespace System.Threading.Tasks | ||
{ | ||
internal enum CausalityTraceLevel | ||
{ | ||
#if FEATURE_COMINTEROP | ||
Required = WFD.CausalityTraceLevel.Required, | ||
Important = WFD.CausalityTraceLevel.Important, | ||
Verbose = WFD.CausalityTraceLevel.Verbose | ||
#else | ||
Required, | ||
Important, | ||
Verbose | ||
#endif | ||
} | ||
|
||
internal enum AsyncCausalityStatus | ||
{ | ||
#if FEATURE_COMINTEROP | ||
Canceled = WFD.AsyncCausalityStatus.Canceled, | ||
Completed = WFD.AsyncCausalityStatus.Completed, | ||
Error = WFD.AsyncCausalityStatus.Error, | ||
Started = WFD.AsyncCausalityStatus.Started | ||
#else | ||
Started, | ||
Completed, | ||
Canceled, | ||
Error | ||
#endif | ||
} | ||
|
||
internal enum CausalityRelation | ||
{ | ||
#if FEATURE_COMINTEROP | ||
AssignDelegate = WFD.CausalityRelation.AssignDelegate, | ||
Join = WFD.CausalityRelation.Join, | ||
Choice = WFD.CausalityRelation.Choice, | ||
Cancel = WFD.CausalityRelation.Cancel, | ||
Error = WFD.CausalityRelation.Error | ||
#else | ||
AssignDelegate, | ||
Join, | ||
Choice, | ||
Cancel, | ||
Error | ||
#endif | ||
} | ||
|
||
internal enum CausalitySynchronousWork | ||
{ | ||
#if FEATURE_COMINTEROP | ||
CompletionNotification = WFD.CausalitySynchronousWork.CompletionNotification, | ||
ProgressNotification = WFD.CausalitySynchronousWork.ProgressNotification, | ||
Execution = WFD.CausalitySynchronousWork.Execution | ||
#else | ||
CompletionNotification, | ||
ProgressNotification, | ||
Execution | ||
#endif | ||
} | ||
|
||
internal static class AsyncCausalityTracer | ||
{ | ||
internal static void EnableToETW(bool enabled) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
if (enabled) | ||
f_LoggingOn |= Loggers.ETW; | ||
else | ||
f_LoggingOn &= ~Loggers.ETW; | ||
#endif | ||
} | ||
|
||
internal static bool LoggingOn | ||
{ | ||
get | ||
{ | ||
#if FEATURE_COMINTEROP | ||
return f_LoggingOn != 0; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
} | ||
|
||
#if FEATURE_COMINTEROP | ||
//s_PlatformId = {4B0171A6-F3D0-41A0-9B33-02550652B995} | ||
private static readonly Guid s_PlatformId = new Guid(0x4B0171A6, 0xF3D0, 0x41A0, 0x9B, 0x33, 0x02, 0x55, 0x06, 0x52, 0xB9, 0x95); | ||
|
||
|
@@ -164,15 +126,13 @@ private static void TracingStatusChangedHandler(object sender, WFD.TracingStatus | |
else | ||
f_LoggingOn &= ~Loggers.CausalityTracer; | ||
} | ||
#endif | ||
|
||
// | ||
// The TraceXXX methods should be called only if LoggingOn property returned true | ||
// | ||
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Tracking is slow path. Disable inlining for it. | ||
internal static void TraceOperationCreation(CausalityTraceLevel traceLevel, int taskId, string operationName, ulong relatedContext) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
try | ||
{ | ||
if ((f_LoggingOn & Loggers.ETW) != 0) | ||
|
@@ -185,13 +145,11 @@ internal static void TraceOperationCreation(CausalityTraceLevel traceLevel, int | |
//view function comment | ||
LogAndDisable(ex); | ||
} | ||
#endif | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
internal static void TraceOperationCompletion(CausalityTraceLevel traceLevel, int taskId, AsyncCausalityStatus status) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
try | ||
{ | ||
if ((f_LoggingOn & Loggers.ETW) != 0) | ||
|
@@ -204,13 +162,11 @@ internal static void TraceOperationCompletion(CausalityTraceLevel traceLevel, in | |
//view function comment | ||
LogAndDisable(ex); | ||
} | ||
#endif | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
internal static void TraceOperationRelation(CausalityTraceLevel traceLevel, int taskId, CausalityRelation relation) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
try | ||
{ | ||
if ((f_LoggingOn & Loggers.ETW) != 0) | ||
|
@@ -223,13 +179,11 @@ internal static void TraceOperationRelation(CausalityTraceLevel traceLevel, int | |
//view function comment | ||
LogAndDisable(ex); | ||
} | ||
#endif | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
internal static void TraceSynchronousWorkStart(CausalityTraceLevel traceLevel, int taskId, CausalitySynchronousWork work) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
try | ||
{ | ||
if ((f_LoggingOn & Loggers.ETW) != 0) | ||
|
@@ -242,13 +196,11 @@ internal static void TraceSynchronousWorkStart(CausalityTraceLevel traceLevel, i | |
//view function comment | ||
LogAndDisable(ex); | ||
} | ||
#endif | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.NoInlining)] | ||
internal static void TraceSynchronousWorkCompletion(CausalityTraceLevel traceLevel, CausalitySynchronousWork work) | ||
{ | ||
#if FEATURE_COMINTEROP | ||
try | ||
{ | ||
if ((f_LoggingOn & Loggers.ETW) != 0) | ||
|
@@ -261,22 +213,21 @@ internal static void TraceSynchronousWorkCompletion(CausalityTraceLevel traceLev | |
//view function comment | ||
LogAndDisable(ex); | ||
} | ||
#endif | ||
} | ||
|
||
#if FEATURE_COMINTEROP | ||
//fix for 796185: leaking internal exceptions to customers, | ||
//we should catch and log exceptions but never propagate them. | ||
private static void LogAndDisable(Exception ex) | ||
{ | ||
f_LoggingOn = 0; | ||
Debugger.Log(0, "AsyncCausalityTracer", ex.ToString()); | ||
} | ||
#endif | ||
|
||
private static ulong GetOperationId(uint taskId) | ||
{ | ||
return (((ulong)Thread.GetDomainID()) << 32) + taskId; | ||
} | ||
} | ||
} | ||
|
||
#endif |
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.
We prefer conditions in the .csproj files to end-to-end ifdefs.
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.
Yep, I was not sure how to best indicate this file is for FEATURE_COMINTEROP only
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.
The condition for the file can be
'$(FeatureAsyncCausalityTracer)'!='true'
so that each runtime can have its own idea whether and when to use the noop implementation.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.
@jkotas Where would I set that flag for CoreCLR FEATURE_COMINTEROP ?
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.
Adding this to System.Private.CoreLib.csproj in CoreCLR should do the trick:
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.
ok