-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Local state tracing instrumentation #66768
Conversation
6906704
to
680a9ac
Compare
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.
Only partly reviewed. Will continue later.
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/MethodToClassRewriter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/MethodToStateMachineRewriter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Emitter/EditAndContinue/PEDeltaAssemblyBuilder.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/AsyncRewriter/AsyncRewriter.AsyncIteratorRewriter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Test/Emit/Emit/DynamicAnalysis/DynamicInstrumentationTests.cs
Show resolved
Hide resolved
Should this call In reply to: 1433995302 In reply to: 1433995302 In reply to: 1433995302 Refers to: src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs:105 in 92ac7e5. [](commit_id = 92ac7e5, deletion_comment = False) |
In reply to: 1433998240 In reply to: 1433998240 In reply to: 1433998240 Refers to: src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs:182 in 92ac7e5. [](commit_id = 92ac7e5, deletion_comment = False) |
What changed between f0 and f1? In reply to: 1434005776 In reply to: 1434005776 In reply to: 1434005776 Refers to: src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs:406 in 92ac7e5. [](commit_id = 92ac7e5, deletion_comment = False) |
Consider using In reply to: 1434018635 In reply to: 1434018635 Refers to: src/Compilers/CSharp/Test/Emit/Emit/LocalStateTracing/LocalStateTracingTests.cs:1168 in 92ac7e5. [](commit_id = 92ac7e5, deletion_comment = False) |
src/Compilers/CSharp/Portable/Lowering/Instrumentation/LocalStateTracingInstrumenter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Jones <[email protected]>
…ateTracingInstrumenter.cs Co-authored-by: Jan Jones <[email protected]>
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.
Last two commits LGTM.
The compiler currently allows for instrumentation of the entire assembly by setting EmitOptions.InstrumentationKinds. Only one kind is available today, which enables instrumentation for dynamic code coverage collection.
This change
EmitDifference
API to instruct the compiler to update a specific method symbol with a given set of instrumentationsInstrumentationKind.LocalStateTracing
.[1] is implemented by making the method compiler ask
PEModuleBuilder
for the instrumentations of the method being compiled. A builder used to compile entire assembly simple returns the value fromEmitOptions
, while the EnC builder uses the information passed toEmitDifference
.[2] A new
LocalStateTracingInstrumenter
is added to the chain of instrumenters applied during local rewrite.This instrumenter adds calls to well-known instrumentation helpers to the bodies of methods. These allow tracing method entries, returns and writes to user-defined local variables and parameters. It also adds the ability to stitch calls to MoveNext methods of a state machine that are executed as continuations of the same instance of the state machine but potentially from multiple different threads.
The instrumentation introduces several new bound nodes:
BoundBlockInstrumentation
This node is attached to a BoundBlock that represents the lowered body of an instrumented method, lambda or local function. It defines a local variable used to store instrumentation context and prologue and epilogue.
BoundBlock with block instrumentation is eventually lowered to:
The prologue is:
Where Xyz is a combination of
StateMachine
and eitherMethod
orLambda
, and is the corresponding set of arguments identifying the context.The -Entry method is a static factory method for LocalStateTracker.
LocalStateTracker is a
ref struct
. It can only be allocated on the stack and accessed only directly from the declaring method (no lifting).For member methods a single id is passed that is the method token.
For lambdas and local functions the token of the lambda method are passed in addition to the containing method token.
For state machines, the state machine instance id is passed. The instance id is stored on a new synthesized field of the state machine type added by the instrumentation that is initialized to a unique number when the state machine type is instantiated.
The epilogue is simply:
BoundStateMachineInstanceId
This node represents a reference to a synthesized state machine instance id field of the state machine. Lowered to a field read during state machine lowering.
BoundParameterId, BoundLocalId
Represents id of a user-defined parameter/local. Emitted as ldc.i4 of either the parameter/local ordinal if the variable was not lifted, or the token of its hoisted field (offset by 0x10000, the limit on number of method parameters/locals)
Each local variable write is followed by a call to one of the
LogLocalStoreXyz
orLogParameterStoreXyz
instance methods on$context
. The logger is passed either BoundParameterId or BoundLocalId and the current value of the local/parameter. The loggers are specialized to handle all kinds of variable types efficiently (without boxing).Specialized loggers are used to track local variable aliases via ref assignments.