-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[mono][eventpipe] Implementing MethodDetails and BulkType events #68571
[mono][eventpipe] Implementing MethodDetails and BulkType events #68571
Conversation
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.
Good start. Could be a little bit less copy-pasty.
The biggest issue is the use of m_class_is_byreflike
when you mean to look at MonoType:byref
.
Also I'm concerned about locking and generally accessing the bulk types buffer from multiple threads. If multiple threads are writing and any one of them could fire the buffer, there's no guarantee that the other threads finished populating their entry.
I would suggest using a simple mutex to only allow one function to access the buffers at a time (basically make ep_rt_mono_log_type_and_parameters
take a mutex),
85e8aaa
to
8450ced
Compare
Writing arrays in generateWriteEventBody had not been previously hit on Mono. With a goal of emitting MethodDetails events on Mono, lttngDataTypeMapping needs to be extended to be compatible with mono types.
8450ced
to
3e2fa00
Compare
dc14adc
to
43ea8b6
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.
It's coming together
The main remaining question is around the memory management of s_name
.
Also some nits about intptr_t
(it's by definition either 8 or 4 bytes, depending on the architecture. so it's not a great idea to use it as a wire format type)
Set BulkTypeValue s_name to null for now Fixed debug trace formatting for pointers Fix type_name_id for types with no token Remove write_event_buffer_intptr as the size is different on Windows x86 Rename ep_rt_bulk_type_value_init to ep_rt_bulk_type_value_clear
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.
Mono bits LGTM. @josalem or @lateralusX any other issues in the generator scripts or in ep-rt-mono that you think need to be addressed in this PR?
Cleanup formatting and style Remove unused write_event_buffer_utf16_str Add BulkTypeEventLogger pointer to function description
Change ep_rt_mono_get_byte_count_in_event type
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.
Overall it looks good, nice work! A couple of smaller things noted. I also think you should do a pass and drop all the variable prefixes used (p_, s_ m_ rg_ etc), its not Mono code style using that, and I assume you pretty much took variable names from CoreCLR C++ implementation and used them in this PR.
Drop variable prefixes Clear BulkTypeValue via memset Rename bulk_type_event_logger helpers to alloc and free Remove redundant bulk type value byte count calculation Utilize memcpy to copy type parameter arrays Reduce padding by moving bulk_type_event_buffer field in struct
…ds from mono types when needed Change type id type from intptr_t to uint64_t as ids in eventpipe are standardized to uint64_t
…namically allocate enough space for type parameters
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.
small quality of life suggestion
Looks like all the default lanes built successfully (except a Browser wasm windows lane on runtime-staging that timed out after 3 hrs).
@josalem could I get another 👀 at this PR, looking to merge as soon as we can |
f7a60d4
to
49d7366
Compare
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
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
The failures look unrelated to this PR |
Thanks @lambdageek @lateralusX @josalem for all of your help! |
This PR looks to implement MethodDetails and BulkType trace events on mono, closely following the implementation of src/coreclr/vm/eventtrace.cpp's SendMethodDetailsEvent and FireBulkTypeEvent. In doing so, apps running on mono can be traced following steps from https://github.com/dotnet/runtime/blob/main/docs/design/mono/diagnostics-tracing.md and produce a
.nettrace
file with relevant MethodDetails and BulkType events. This.nettrace
containingMethodDetails
andBulkType
events is necessary to leverage the dotnet-pgo tool to generate a corresponding .mibc file for future consumption in the mono AOT compiler.This PR makes the following changes:
Creating a
.mibc
on mono from the HelloWorld samplemake run
3a.
DOTNET_DiagnosticPorts="/Users/mdhwang/myport,suspend" <path to app executable>
3b.
dotnet-trace collect --providers Microsoft-Windows-DotNETRuntime:0x1F000080018:5 --diagnostic-port ~/myport
dotnet-pgo create-mibc --trace <path-to-trace>
(built with a dotnet-pgo tool with AddAssembliesAssociatedWithType modified to skip generic parameters)Modification no longer needed.Implementation Details
For the most part, the implementation of the relevant functions are similar to CoreCLR. Below are some key differences
ep_rt_mono_send_method_details_event
Utilizes a helper
get_typeid_for_type
in order to obtain a unique type ID, to fulfill the niche of CoreCLR's type handleep_rt_mono_log_type_and_parameters_if_necessary
Decided to not implement the hash table until it will actually be used, which seems to be when
ep_rt_mono_log_type_and_parameters_if_necessary
is used outside ofep_rt_mono_send_method_details_event
ep_rt_mono_log_type_and_parameters
In line with
LogTypeAndParameters
except for the absence oftypeLogBehavior
, for currently this is only called followingep_rt_mono_send_method_details_event
which always logs.ep_rt_mono_log_single_type
Fills in
MONO_TYPE_VALUETYPE
MONO_TYPE_PTR
MONO_TYPE_BYREF
rg_type_parameters
andc_type_parameters
by three categories of MonoType 1)MONO_TYPE_ARRAY
MONO_TYPE_SZARRAY 2)
MONO_TYPE_GENERICINST3)
MONO_TYPE_CLASSfor any embedded type parameters. Does not set
s_nameand keeps it as
NULL` until the data will actually be used in mono, which GC Heap Dumps are a likely candidate for.ep_rt_mono_fire_bulk_type_event
Copies to the BulkTypeEvent buffer through helper functions.
Various helper functions and
static const
variables have been added in addition toBulkTypeValue
andBulkTypeEventLogger
structs with respective memory managementinit/fini/clear
functions.TODO/Questions
Does sName in eventtrace.cpp need to be carried over?We have opted to keep
s_name
asNULL
until it is actually used in mono, which GC Heap Dumps are a likely candidate for.Variable size array for rg_type_parameters in BulkTypeValue struct that already has variable size field s_nameFigured out that
StackSArray<ULONGLONG>
has a fixed size that evaluates to32
Where else to emit ep_rt_mono_send_method_details_event?
How necessary are the 0x06 method token mask and 0x02 type token masks, should dotnet-pgo be tweaked instead?Found the equivalent for mono using
mono_metadata_make_token
andmono_metadata_token_index
How to implementif_necessary
portion of LogTypeAndParametersIfNecessary (th.IsRestored and what exactly is client usage of LogTypeAndParametersIfNecessary)Decided to not implement the hash table until it will actually be used, which seems to be when
ep_rt_mono_log_type_and_parameters_if_necessary
is used outside ofep_rt_mono_send_method_details_event