This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic infrastructure for binder tracing (#27383)
- Loading branch information
1 parent
b46c857
commit f55bc3a
Showing
21 changed files
with
529 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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. | ||
// ============================================================ | ||
// | ||
// activitytracker.cpp | ||
// | ||
|
||
|
||
// | ||
// Helpers for interaction with the managed ActivityTracker | ||
// | ||
// ============================================================ | ||
|
||
#include "common.h" | ||
#include "activitytracker.h" | ||
|
||
void ActivityTracker::Start(/*out*/ GUID *activityId, /*out*/ GUID *relatedActivityId) | ||
{ | ||
GCX_COOP(); | ||
|
||
PREPARE_NONVIRTUAL_CALLSITE(METHOD__ACTIVITY_TRACKER__START_ASSEMBLY_LOAD); | ||
DECLARE_ARGHOLDER_ARRAY(args, 2); | ||
args[ARGNUM_0] = PTR_TO_ARGHOLDER(activityId); | ||
args[ARGNUM_1] = PTR_TO_ARGHOLDER(relatedActivityId); | ||
|
||
CALL_MANAGED_METHOD_NORET(args) | ||
} | ||
|
||
void ActivityTracker::Stop(/*out*/ GUID *activityId) | ||
{ | ||
GCX_COOP(); | ||
|
||
PREPARE_NONVIRTUAL_CALLSITE(METHOD__ACTIVITY_TRACKER__STOP_ASSEMBLY_LOAD); | ||
DECLARE_ARGHOLDER_ARRAY(args, 1); | ||
args[ARGNUM_0] = PTR_TO_ARGHOLDER(activityId); | ||
|
||
CALL_MANAGED_METHOD_NORET(args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// 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. | ||
// ============================================================ | ||
// | ||
// bindertracing.cpp | ||
// | ||
|
||
|
||
// | ||
// Implements helpers for binder tracing | ||
// | ||
// ============================================================ | ||
|
||
#include "common.h" | ||
#include "bindertracing.h" | ||
|
||
#include "activitytracker.h" | ||
|
||
#ifdef FEATURE_EVENT_TRACE | ||
#include "eventtracebase.h" | ||
#endif // FEATURE_EVENT_TRACE | ||
|
||
using namespace BINDER_SPACE; | ||
|
||
namespace | ||
{ | ||
void FireAssemblyLoadStart(const BinderTracing::AssemblyBindOperation::BindRequest &request) | ||
{ | ||
#ifdef FEATURE_EVENT_TRACE | ||
if (!EventEnabledAssemblyLoadStart()) | ||
return; | ||
|
||
GUID activityId = GUID_NULL; | ||
GUID relatedActivityId = GUID_NULL; | ||
ActivityTracker::Start(&activityId, &relatedActivityId); | ||
|
||
FireEtwAssemblyLoadStart( | ||
GetClrInstanceId(), | ||
request.AssemblyName, | ||
request.AssemblyPath, | ||
request.RequestingAssembly, | ||
request.AssemblyLoadContext, | ||
&activityId, | ||
&relatedActivityId); | ||
#endif // FEATURE_EVENT_TRACE | ||
} | ||
|
||
void FireAssemblyLoadStop(const BinderTracing::AssemblyBindOperation::BindRequest &request, bool success, const WCHAR *resultName, const WCHAR *resultPath, bool cached) | ||
{ | ||
#ifdef FEATURE_EVENT_TRACE | ||
if (!EventEnabledAssemblyLoadStop()) | ||
return; | ||
|
||
GUID activityId = GUID_NULL; | ||
ActivityTracker::Stop(&activityId); | ||
|
||
FireEtwAssemblyLoadStop( | ||
GetClrInstanceId(), | ||
request.AssemblyName, | ||
request.AssemblyPath, | ||
request.RequestingAssembly, | ||
request.AssemblyLoadContext, | ||
success, | ||
resultName, | ||
resultPath, | ||
cached, | ||
&activityId); | ||
#endif // FEATURE_EVENT_TRACE | ||
} | ||
} | ||
|
||
bool BinderTracing::IsEnabled() | ||
{ | ||
#ifdef FEATURE_EVENT_TRACE | ||
// Just check for the AssemblyLoadStart event being enabled. | ||
return EventEnabledAssemblyLoadStart(); | ||
#endif // FEATURE_EVENT_TRACE | ||
return false; | ||
} | ||
|
||
namespace BinderTracing | ||
{ | ||
AssemblyBindOperation::AssemblyBindOperation(AssemblySpec *assemblySpec) | ||
: m_bindRequest { assemblySpec } | ||
, m_success { false } | ||
, m_cached { false } | ||
{ | ||
_ASSERTE(assemblySpec != nullptr); | ||
|
||
// ActivityTracker or EventSource may have triggered the system satellite load. | ||
// Don't track system satellite binding to avoid potential infinite recursion. | ||
m_trackingBind = BinderTracing::IsEnabled() && !m_bindRequest.AssemblySpec->IsMscorlibSatellite(); | ||
if (m_trackingBind) | ||
{ | ||
m_bindRequest.AssemblySpec->GetFileOrDisplayName(ASM_DISPLAYF_VERSION | ASM_DISPLAYF_CULTURE | ASM_DISPLAYF_PUBLIC_KEY_TOKEN, m_bindRequest.AssemblyName); | ||
FireAssemblyLoadStart(m_bindRequest); | ||
} | ||
} | ||
|
||
AssemblyBindOperation::~AssemblyBindOperation() | ||
{ | ||
if (m_trackingBind) | ||
FireAssemblyLoadStop(m_bindRequest, m_success, m_resultName.GetUnicode(), m_resultPath.GetUnicode(), m_cached); | ||
} | ||
|
||
void AssemblyBindOperation::SetResult(PEAssembly *assembly) | ||
{ | ||
m_success = assembly != nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
// | ||
// activitytracker.h | ||
// | ||
|
||
#ifndef __ACTIVITY_TRACKER_H__ | ||
#define __ACTIVITY_TRACKER_H__ | ||
|
||
namespace ActivityTracker | ||
{ | ||
void Start(/*out*/ GUID *activityId, /*out*/ GUID *relatedActivityId); | ||
void Stop(/*out*/ GUID *activityId); | ||
}; | ||
|
||
#endif // __ACTIVITY_TRACKER_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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. | ||
// | ||
// bindertracing.h | ||
// | ||
|
||
#ifndef __BINDER_TRACING_H__ | ||
#define __BINDER_TRACING_H__ | ||
|
||
class AssemblySpec; | ||
class PEAssembly; | ||
|
||
namespace BinderTracing | ||
{ | ||
bool IsEnabled(); | ||
|
||
// If tracing is enabled, this class fires an assembly bind start event on construction | ||
// and the corresponding stop event on destruction | ||
class AssemblyBindOperation | ||
{ | ||
public: | ||
// This class assumes the assembly spec will have a longer lifetime than itself | ||
AssemblyBindOperation(AssemblySpec *assemblySpec); | ||
~AssemblyBindOperation(); | ||
|
||
void SetResult(PEAssembly *assembly); | ||
|
||
struct BindRequest | ||
{ | ||
AssemblySpec *AssemblySpec; | ||
SString AssemblyName; | ||
SString AssemblyPath; | ||
SString RequestingAssembly; | ||
SString AssemblyLoadContext; | ||
}; | ||
|
||
private: | ||
BindRequest m_bindRequest; | ||
|
||
bool m_trackingBind; | ||
|
||
bool m_success; | ||
SString m_resultName; | ||
SString m_resultPath; | ||
bool m_cached; | ||
}; | ||
}; | ||
|
||
#endif // __BINDER_TRACING_H__ |
Oops, something went wrong.