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

[eventpipe] Use MonoImage:module_name when filename is NULL #73018

Merged
merged 3 commits into from
Aug 1, 2022

Conversation

lambdageek
Copy link
Member

@lambdageek lambdageek commented Jul 28, 2022

When assemblies are bundled (for example in WASM), the filename field is set to NULL; use the module name (from the metadata Module table).

Contributes to #72481

With this PR and with #72859 I can generate a trace and run

dotnet-pgo create-mibc --trace example.nettrace -r ./bin/Debug/AppBundle/managed/'*.dll' --output /tmp/out.mibc

and generate a .mibc file.

…is null

When assemblies are bundled (for example in WASM), the filename field
is set to NULL and the name field is set to the basename of the
assembly.
@lambdageek lambdageek added arch-wasm WebAssembly architecture area-Tracing-mono labels Jul 28, 2022
@lambdageek lambdageek added this to the 7.0.0 milestone Jul 28, 2022
@ghost ghost assigned lambdageek Jul 28, 2022
@ghost
Copy link

ghost commented Jul 28, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

When assemblies are bundled (for example in WASM), the filename field is set to NULL and the name field is set to the basename of the assembly.

Contributes to #72481

With this PR and with #72859 I can generate a trace and run

dotnet-pgo create-mibc --trace example.nettrace -r ./bin/Debug/AppBundle/managed/'*.dll' --output /tmp/out.mibc

and generate a .mibc file.

Author: lambdageek
Assignees: -
Labels:

arch-wasm, area-Tracing-mono

Milestone: 7.0.0

@lambdageek
Copy link
Member Author

lambdageek commented Jul 28, 2022

Sample PerfTrace line for a ModuleLoad event:

ThreadID="694,952" ProcessorNumber="0" ModuleID="38,139,048" AssemblyID="0" ModuleFlags="Manifest" ModuleILPath="System.Runtime.InteropServices.JavaScript.dll" ModuleNativePath="" ManagedPdbSignature="8c78d9aa-29ad-ff33-07d8-215908aea400" ManagedPdbAge="1" ManagedPdbBuildPath="/Users/alklig/work/dotnet-runtime/runtime/artifacts/obj/mono/Wasm.Browser.EventPipe.Sample/wasm/Debug/browser-wasm/linked/System.Runtime.InteropServices.JavaScript.pdb" NativePdbSignature="00000000-0000-0000-0000-000000000000" NativePdbAge="0" NativePdbBuildPath="" ModuleILFileName="System.Runtime.InteropServices.JavaScript.dll" 

without this PR, the ModuleILPath was ""

And here's a DomainModuleLoad. Here too the ModuleILPath was "" before:

ThreadID="694,952" ProcessorNumber="0" ModuleID="38,139,048" AssemblyID="0" AppDomainID="11,531,752" ModuleFlags="Manifest" ModuleILPath="System.Runtime.InteropServices.JavaScript.dll" ModuleNativePath="" ClrInstanceID="9" 

@@ -3784,7 +3784,7 @@ get_module_event_data (
if (image && image->aot_module)
module_data->module_flags |= MODULE_FLAGS_NATIVE_MODULE;

module_data->module_il_path = image && image->filename ? image->filename : "";
module_data->module_il_path = image && image->filename ? image->filename : (image && image->name ? image->name : "");
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, in what case would we get module_il_path = ""?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. good point. image->name is always non-null. If it's not set explicitly (for example when doing Aseembly.Load(byte[]) it's set to "data-%p". @lateralusX is it better to have "" or some arbitrary made-up name?

Copy link
Member

@lateralusX lateralusX Jul 29, 2022

Choose a reason for hiding this comment

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

Not sure, this value can be used by tooling to locate and potentially load the module. if we have "" I guess there is bigger chance that the tool will understand that its missing, compared to having some made up value that it probably will try to use and fail.

Copy link
Member

@lateralusX lateralusX Jul 29, 2022

Choose a reason for hiding this comment

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

This is what CoreCLR does:

    // if we do not have a module path yet, we put the module name
    if(bIsDynamicAssembly || ModuleILPath==NULL || wcslen(ModuleILPath) <= 2)
    {
        moduleName.SetUTF8(pModule->GetSimpleName());
        ModuleILPath = (PWCHAR)moduleName.GetUnicode();
        ModuleNativePath = (PWCHAR)pEmptyString;
    }

So they assume they always have a valid module name or it will end up with an empty string (SString moduleName = SString::Empty();).

So if we should have same behavior in case we have missing module name it should revert to "".

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, changed it to use the module name if available and fall back to ""

module name comes from the metadata Module table and is something like
"Foo.dll" even if the assembly is loaded from a bundle or from
Assembly.Load(byte[]), whereas image->name might be "data-0x00abcdef"
for byte loads
@lambdageek lambdageek changed the title [eventpipe] Use MonoImage:name when available, if MonoImage:filename is null [eventpipe] Use MonoImage:name when available, otherwise module_name Jul 29, 2022
@lateralusX
Copy link
Member

I guess the title should be Use MonoImage:filename ?

@lambdageek lambdageek changed the title [eventpipe] Use MonoImage:name when available, otherwise module_name [eventpipe] Use MonoImage:module_name when filename is NULL Jul 29, 2022
@lambdageek
Copy link
Member Author

lambdageek commented Aug 1, 2022

(accidentally pushed unrelated work to this PR; reverted back to reviewed version)

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Tracing-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants