Skip to content

Add RuntimeProperties Trace Event #690

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/src/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,10 @@ namespace ETW

#ifdef FEATURE_EVENT_TRACE
static VOID RuntimeInformation(INT32 type);
static VOID RuntimeInputProperties(int nProperties, LPCWSTR* propertyNames, LPCWSTR* propertyValues);
#else
static VOID RuntimeInformation(INT32 type) {};
static VOID RuntimeInputProperties() {};
#endif // FEATURE_EVENT_TRACE
};

Expand Down
45 changes: 44 additions & 1 deletion src/coreclr/src/vm/ClrEtwAll.man
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,43 @@
</UserData>
</template>

<template tid="RuntimeProperties">
<data name="ClrInstanceID" inType="win:UInt16" />
<data name="TrustedPlatformAssemblies" inType="win:UnicodeString"/>
Copy link
Member

@jkotas jkotas Dec 9, 2019

Choose a reason for hiding this comment

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

There is nothing Trusted nor Platform about these. Should we use this as an opportunity to come up with more sensible name that does not need 5 minute explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, we should choose a better name, since it is just a list of assemblies from which we resolve dependencies by default. I spoke to @richlander about this, he said he'll suggest a better name.

Copy link
Member

Choose a reason for hiding this comment

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

I have heard about the TPA list for many years, but I don't know how it fits into frameworks and other .NET Core-isms. Can you describe what it means to you?

Copy link
Member

Choose a reason for hiding this comment

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

  • Is is a list of assemblies that the application is composed of.
  • It is a list of assemblies that are (logically) pre-loaded into default assembly load context.

Some naming ideas: Assemblies, DefaultAssemblies

Copy link
Member

Choose a reason for hiding this comment

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

Good suggestions. Those help. They are also a bit misleading. For example, DefaultAssemblies doesn't align with the default AssemblyLoaderContext. That would be confusing to me.

When a dependency needs to be resolved from a non-default ALC by the default ALC, I assume assemblies other than the TPA ones would be candidates. Is that right?

I take it that the TPA is basically the set of "pre-bound assemblies." How about ApplicationAssemblies.

Copy link
Member

Choose a reason for hiding this comment

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

When a dependency needs to be resolved from a non-default ALC by the default ALC, I assume assemblies other than the TPA ones would be candidates

Maybe I'm missing what you mean by this, but if the default ALC needs to resolve a dependency that is not on the TPA list, the runtime would not know where to look for that assembly? The user would need to have added some sort of event handler (AssemblyLoadContext.Resolving or AppDomain.AssemblyResolve) to do the resolution themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a dependency needs to be resolved from a non-default ALC by the default ALC, I assume assemblies other than the TPA ones would be candidates. Is that right?

When an assembly is loaded into non-default ALC, the ALC's load method tries to resolve the assembly using custom logic in its Load() overrides. If the assembly cannot be resolved that way, the resolution defers to the default-ALC, which tries to resolve the assembly using the TPA list. So, the TPAs are closely associated with the default-ALC.

How about ApplicationAssemblies.

ApplicationAssemblies sounds like a good name, because typically the application's assemblies are loaded into the default-ALC, while the plugins are loaded into custom-ALC.

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 @elinor-fung used the term DefaultAssemblies in the other PR, which I actually like better. There are two sets of assemblies which are typically present in the TPA:

  • The frameworks
  • Application assemblies

Both are equally important when dealing with plugins and such. Calling it just ApplicationAssemblies might mean to someone that it's just the app stuff, not the shared frameworks.
But it's still much better than TPA :-)

<data name="NativeDllSearchDirectories" inType="win:UnicodeString"/>
<data name="PlatformResourceRoots" inType="win:UnicodeString"/>
<data name="AppContextBaseDirectory" inType="win:UnicodeString"/>
<data name="AppContextDepsFiles" inType="win:UnicodeString"/>
<data name="ProbingDirectories" inType="win:UnicodeString"/>
<data name="FxProductVersion" inType="win:UnicodeString"/>
<data name="JitPath" inType="win:UnicodeString"/>
<data name="FxDepsFile" inType="win:UnicodeString"/>
<data name="AppPaths" inType="win:UnicodeString"/>
<data name="AppNIPaths" inType="win:UnicodeString"/>
<data name="StartUpHooks" inType="win:UnicodeString"/>
<data name="ResolvedFrameworks" inType="win:UnicodeString"/>
<data name="Others" inType="win:UnicodeString"/>
<UserData>
<Type xmlns="myNs">
<ClrInstanceID> %1 </ClrInstanceID>
<TrustedPlatformAssemblies> %2 </TrustedPlatformAssemblies>
<NativeDllSearchDirectories> %3 </NativeDllSearchDirectories>
<PlatformResourceRoots> %4 </PlatformResourceRoots>
<AppContextBaseDirectory> %5 </AppContextBaseDirectory>
<AppContextDepsFiles> %6 </AppContextDepsFiles>
<ProbingDirectories> %7 </ProbingDirectories>
<FxProductVersion> %8 </FxProductVersion>
<JitPath> %9 </JitPath>
<FxDepsFile> %10 </FxDepsFile>
<AppPaths> %11 </AppPaths>
<AppNIPaths> %12 </AppNIPaths>
<StartUpHooks> %13 </StartUpHooks>
<ResolvedFrameworks> %14 </ResolvedFrameworks>
<Others> %15 </Others>
</Type>
</UserData>
</template>

<template tid="GCStart">
<data name="Count" inType="win:UInt32" outType="xs:unsignedInt"/>
<data name="Reason" inType="win:UInt32" map="GCReasonMap" />
Expand Down Expand Up @@ -3470,7 +3507,12 @@
opcode="win:Start"
task="CLRRuntimeInformation"
symbol="RuntimeInformationStart" message="$(string.RuntimePublisher.RuntimeInformationEventMessage)"/>


<event value="296" version="0" level="win:Informational" template="RuntimeProperties"
opcode="win:Start"
task="CLRRuntimeInformation"
symbol="RuntimeProperties" message="$(string.RuntimePublisher.RuntimePropertiesEventMessage)"/>

<!-- Additional GC events 200-239 -->
<event value="200" version="0" level="win:Verbose" template="IncreaseMemoryPressure"
keywords="GCKeyword" opcode="IncreaseMemoryPressure"
Expand Down Expand Up @@ -6791,6 +6833,7 @@
<string id="RuntimePublisher.AuthenticodeVerificationEnd_V1EventMessage" value="VerificationFlags=%1;%nErrorCode=%2;%nModulePath=%3;%nClrInstanceID=%4"/>
<string id="RuntimePublisher.EEStartupStartEventMessage" value="VerificationFlags=%1;%nErrorCode=%2;%nModulePath=%3;%nClrInstanceID=%4"/>
<string id="RuntimePublisher.RuntimeInformationEventMessage" value="ClrInstanceID=%1;%nSKU=%2;%nBclMajorVersion=%3;%nBclMinorVersion=%4;%nBclBuildNumber=%5;%nBclQfeNumber=%6;%nVMMajorVersion=%7;%nVMMinorVersion=%8;%nVMBuildNumber=%9;%nVMQfeNumber=%10;%nStartupFlags=%11;%nStartupMode=%12;%nCommandLine=%13;%nComObjectGUID=%14;%nRuntimeDllPath=%15"/>
<string id="RuntimePublisher.RuntimePropertiesEventMessage" value="ClrInstanceID=%1;%nTrustedPlatformAssemblies=%2;%nNativeDllSearchDirectories=%3;%nPlatformResourceRoots=%4;%nAppContextBaseDirectory=%5;%nAppContextDepsFiles=%6;%nProbingDirectories=%7;%nFxProductVersion=%8;%nJitPath=%9;%nFxDepsFile=%10;%nAppPaths=%11;%nAppNIPaths=%12;%nStartUpHooks=%13;%nResolvedFrameworks=%14;%nOthers=%15" />
<string id="RuntimePublisher.MethodJitInliningFailedEventMessage" value="MethodBeingCompiledNamespace=%1;%nMethodBeingCompiledName=%2;%nMethodBeingCompiledNameSignature=%3;%nInlinerNamespace=%4;%nInlinerName=%5;%nInlinerNameSignature=%6;%nInlineeNamespace=%7;%nInlineeName=%8;%nInlineeNameSignature=%9;%nFailAlways=%10;%nFailReason=%11;%nClrInstanceID=%12" />
<string id="RuntimePublisher.MethodJitInliningSucceededEventMessage" value="MethodBeingCompiledNamespace=%1;%nMethodBeingCompiledName=%2;%nMethodBeingCompiledNameSignature=%3;%nInlinerNamespace=%4;%nInlinerName=%5;%nInlinerNameSignature=%6;%nInlineeNamespace=%7;%nInlineeName=%8;%nInlineeNameSignature=%9;%nClrInstanceID=%10" />
<string id="RuntimePublisher.MethodJitTailCallFailedEventMessage" value="MethodBeingCompiledNamespace=%1;%nMethodBeingCompiledName=%2;%nMethodBeingCompiledNameSignature=%3;%nCallerNamespace=%4;%nCallerName=%5;%nCallerNameSignature=%6;%nCalleeNamespace=%7;%nCalleeName=%8;%nCalleeNameSignature=%9;%nTailPrefix=%10;%nFailReason=%11;%nClrInstanceID=%12" />
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/vm/ClrEtwAllMeta.lst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ nomac:CLRAuthenticodeVerification:::AuthenticodeVerificationStop_V1
# RuntimeInfo events
####################
nostack:CLRRuntimeInformation:::RuntimeInformationStart
nostack:CLRRuntimeInformation:::RuntimeProperties

###########################
# Tiered compilation events
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/vm/corhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ HRESULT CorHost2::_CreateAppDomain(
pDomain->SetFriendlyName(wszFriendlyName);

ETW::LoaderLog::DomainLoad(pDomain, (LPWSTR)wszFriendlyName);
ETW::InfoLog::RuntimeInputProperties(nProperties, pPropertyNames, pPropertyValues);

if (dwFlags & APPDOMAIN_IGNORE_UNHANDLED_EXCEPTIONS)
pDomain->SetIgnoreUnhandledExceptions();
Expand Down
102 changes: 102 additions & 0 deletions src/coreclr/src/vm/eventtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5035,6 +5035,108 @@ VOID ETW::InfoLog::RuntimeInformation(INT32 type)
} EX_CATCH { } EX_END_CATCH(SwallowAllExceptions);
}

/****************************************************************************/
/* This is called by the runtime during startup to log the
properties passed on from the host. */
/****************************************************************************/

VOID ETW::InfoLog::RuntimeInputProperties(int nProperties, LPCWSTR* propertyNames, LPCWSTR* propertyValues)
{
CONTRACTL{
NOTHROW;
GC_TRIGGERS;
} CONTRACTL_END;

EX_TRY{
if (ETW_EVENT_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context, RuntimeProperties))
{
unsigned short ClrInstanceID = GetClrInstanceId();
LPCWSTR trustedPlatformAssemblies = nullptr;
LPCWSTR nativeDllSearchDirectories = nullptr;
LPCWSTR platformResourceRoots = nullptr;
LPCWSTR appContextBaseDirectory = nullptr;
LPCWSTR appContextDepsFiles = nullptr;
LPCWSTR probingDirectories = nullptr;
LPCWSTR fxProductVersion = nullptr;
LPCWSTR jitPath = nullptr;
LPCWSTR fxDepsFile = nullptr;
LPCWSTR appPaths = nullptr;
Copy link
Member

@jkotas jkotas Dec 9, 2019

Choose a reason for hiding this comment

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

appNIPaths is deprecated and not used anywhere. Do we really need to log it?

I would rather delete it.

LPCWSTR appNIPaths = nullptr;
LPCWSTR startUpHooks = nullptr;
LPCWSTR resolvedFrameworks = nullptr;
SString others;

for (int i = 0; i < nProperties; i++)
{
if (wcscmp(propertyNames[i], W("TRUSTED_PLATFORM_ASSEMBLIES")) == 0)
{
trustedPlatformAssemblies = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("NATIVE_DLL_SEARCH_DIRECTORIES")) == 0)
{
nativeDllSearchDirectories = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("PLATFORM_RESOURCE_ROOTS")) == 0)
{
platformResourceRoots = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("APP_CONTEXT_BASE_DIRECTORY")) == 0)
{
appContextBaseDirectory = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("APP_CONTEXT_DEPS_FILES")) == 0)
{
appContextDepsFiles = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("PROBING_DIRECTORIES")) == 0)
{
probingDirectories = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("FX_PRODUCT_VERSION")) == 0)
{
fxProductVersion = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("JIT_PATH")) == 0)
Copy link
Member

@jkotas jkotas Dec 9, 2019

Choose a reason for hiding this comment

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

JIT_PATH is also not relly used for anything.

{
jitPath = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("FX_DEPS_FILE")) == 0)
{
fxDepsFile = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("APP_PATHS")) == 0)
{
appPaths = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("APP_NI_PATHS")) == 0)
{
appNIPaths = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("STARTUP_HOOKS")) == 0)
{
startUpHooks = propertyValues[i];
}
else if (wcscmp(propertyNames[i], W("RESOLVED_FRAMEWORKS")) == 0)
{
resolvedFrameworks = propertyValues[i];
}
else
{
others.Append(propertyNames[i]);
others.Append(W("="));
others.Append(propertyValues[i]);
others.Append(W("\n"));
}
}

FireEtwRuntimeProperties(ClrInstanceID, trustedPlatformAssemblies, nativeDllSearchDirectories,
platformResourceRoots, appContextBaseDirectory, appContextDepsFiles,
probingDirectories, fxProductVersion, jitPath, fxDepsFile,
appPaths, appNIPaths, startUpHooks, resolvedFrameworks, others);
}
} EX_CATCH{ } EX_END_CATCH(SwallowAllExceptions);
}

/* Fires ETW events every time a pdb is dynamically loaded.
*
* The ETW events correspond to sending parts of the pdb in roughly
Expand Down