Skip to content

Commit

Permalink
Enabling profiling on Unix/OS X.
Browse files Browse the repository at this point in the history
  • Loading branch information
sperling committed Jan 31, 2016
1 parent 85f256e commit 4c375f4
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 62 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ add_definitions(-D_BLD_CLR)
add_definitions(-DWINVER=0x0602)
add_definitions(-DWIN32_LEAN_AND_MEAN=1)
add_definitions(-DDEBUGGING_SUPPORTED)
add_definitions(-DPROFILING_SUPPORTED)

if(WIN32)
if(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
# Only enable edit and continue on windows x86 and x64
# exclude Linux, arm & arm64
add_definitions(-DEnC_SUPPORTED)
endif(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
add_definitions(-DPROFILING_SUPPORTED)
endif(CLR_CMAKE_PLATFORM_ARCH_AMD64 OR CLR_CMAKE_PLATFORM_ARCH_I386)
endif(WIN32)

# Features - please keep them alphabetically sorted
Expand Down
6 changes: 3 additions & 3 deletions dac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

add_definitions(-DDACCESS_COMPILE)
add_definitions(-DFEATURE_ENABLE_HARDWARE_EXCEPTIONS)
if(WIN32)
remove_definitions(-DPROFILING_SUPPORTED)
add_definitions(-DPROFILING_SUPPORTED_DATA)
if(WIN32)
add_definitions(-MT)
endif(WIN32)
remove_definitions(-DPROFILING_SUPPORTED)
add_definitions(-DPROFILING_SUPPORTED_DATA)
2 changes: 0 additions & 2 deletions src/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23769,13 +23769,11 @@ void gc_heap::walk_plug (uint8_t* plug, size_t size, BOOL check_last_object_p, w

STRESS_LOG_PLUG_MOVE(plug, (plug + size), -last_plug_relocation);

#ifdef FEATURE_EVENT_TRACE
ETW::GCLog::MovedReference(plug,
(plug + size),
reloc,
profiling_context,
settings.compaction);
#endif

if (check_last_object_p)
{
Expand Down
2 changes: 2 additions & 0 deletions src/gc/gcee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,12 +502,14 @@ void GCProfileWalkHeapWorker(BOOL fProfilerPinned, BOOL fShouldWalkHeapRootsForE
#endif //MULTIPLE_HEAPS
}

#ifdef FEATURE_EVENT_TRACE
// **** Done! Indicate to ETW helpers that the heap walk is done, so any buffers
// should be flushed into the ETW stream
if (fShouldWalkHeapObjectsForEtw || fShouldWalkHeapRootsForEtw)
{
ETW::GCLog::EndHeapDump(&profilerWalkHeapContext);
}
#endif // FEATURE_EVENT_TRACE
}
}
#endif // defined(GC_PROFILING)
Expand Down
2 changes: 2 additions & 0 deletions src/gc/objecthandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ void CALLBACK ScanPointerForProfilerAndETW(_UNCHECKED_OBJECTREF *pObjRef, uintpt
}
#endif // GC_PROFILING

#if defined(FEATURE_EVENT_TRACE)
// Notify ETW of the handle
if (ETW::GCLog::ShouldWalkHeapRootsForEtw())
{
Expand All @@ -535,6 +536,7 @@ void CALLBACK ScanPointerForProfilerAndETW(_UNCHECKED_OBJECTREF *pObjRef, uintpt
0, // dwGCFlags,
rootFlags); // ETW handle flags
}
#endif // defined(FEATURE_EVENT_TRACE)
}
#endif // defined(GC_PROFILING) || defined(FEATURE_EVENT_TRACE)

Expand Down
1 change: 1 addition & 0 deletions src/inc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ install (FILES cor.h
gcinfoencoder.h
gcinfotypes.h
DESTINATION inc)
install (TARGETS corguids DESTINATION lib)
7 changes: 7 additions & 0 deletions src/inc/eventtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,16 @@ namespace ETW
static BOOL ShouldWalkStaticsAndCOMForEtw();
static VOID WalkStaticsAndCOMForETW();
static VOID EndHeapDump(ProfilerWalkHeapContext * profilerWalkHeapContext);
#ifdef FEATURE_EVENT_TRACE
static VOID BeginMovedReferences(size_t * pProfilingContext);
static VOID MovedReference(BYTE * pbMemBlockStart, BYTE * pbMemBlockEnd, ptrdiff_t cbRelocDistance, size_t profilingContext, BOOL fCompacting, BOOL fAllowProfApiNotification = TRUE);
static VOID EndMovedReferences(size_t profilingContext, BOOL fAllowProfApiNotification = TRUE);
#else
// TODO: Need to be implemented for PROFILING_SUPPORTED.
static VOID BeginMovedReferences(size_t * pProfilingContext) {};
static VOID MovedReference(BYTE * pbMemBlockStart, BYTE * pbMemBlockEnd, ptrdiff_t cbRelocDistance, size_t profilingContext, BOOL fCompacting, BOOL fAllowProfApiNotification = TRUE) {};
static VOID EndMovedReferences(size_t profilingContext, BOOL fAllowProfApiNotification = TRUE) {};
#endif // FEATURE_EVENT_TRACE
static VOID SendFinalizeObjectEvent(MethodTable * pMT, Object * pObj);
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ enum EtwThreadFlags
#endif // FEATURE_EVENT_TRACE

#endif // FEATURE_REDHAWK
#ifdef FEATURE_EVENT_TRACE

// During a heap walk, this is the storage for keeping track of all the nodes and edges
// being batched up by ETW, and for remembering whether we're also supposed to call into
Expand All @@ -152,6 +151,8 @@ struct ProfilerWalkHeapContext
LPVOID pvEtwContext;
};

#ifdef FEATURE_EVENT_TRACE

class Object;
#if !defined(FEATURE_PAL)
/******************************/
Expand Down Expand Up @@ -1068,7 +1069,6 @@ McGenEventProviderEnabled(


struct ProfilingScanContext;
struct ProfilerWalkHeapContext;
class Object;

namespace ETW
Expand Down
2 changes: 1 addition & 1 deletion src/pal/prebuilt/inc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ cmake_minimum_required(VERSION 2.8.12.2)

project(COREPAL)

install (FILES corerror.h DESTINATION inc)
install (FILES corerror.h corprof.h DESTINATION inc)

4 changes: 2 additions & 2 deletions src/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ set(VM_SOURCES_WKS
profattachclient.cpp
profattachserver.cpp
profdetach.cpp
profilermetadataemitvalidator.cpp
profilingenumerators.cpp
profilinghelper.cpp
proftoeeinterfaceimpl.cpp
Expand Down Expand Up @@ -304,8 +305,7 @@ list(APPEND VM_SOURCES_WKS
microsoft.comservices_i.c
mngstdinterfaces.cpp
notifyexternals.cpp
olecontexthelpers.cpp
profilermetadataemitvalidator.cpp
olecontexthelpers.cpp
rcwrefcache.cpp
rtlfunctions.cpp
runtimecallablewrapper.cpp
Expand Down
15 changes: 15 additions & 0 deletions src/vm/amd64/unixstubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ extern "C"
PORTABILITY_ASSERT("Implement for PAL");
}

void ProfileEnterNaked(FunctionIDOrClientID functionIDOrClientID)
{
PORTABILITY_ASSERT("Implement for PAL");
}

void ProfileLeaveNaked(FunctionIDOrClientID functionIDOrClientID)
{
PORTABILITY_ASSERT("Implement for PAL");
}

void ProfileTailcallNaked(FunctionIDOrClientID functionIDOrClientID)
{
PORTABILITY_ASSERT("Implement for PAL");
}

DWORD getcpuid(DWORD arg, unsigned char result[16])
{
DWORD eax;
Expand Down
5 changes: 5 additions & 0 deletions src/vm/eetoprofinterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ EEToProfInterfaceImpl::CHashTableImpl::CHashTableImpl(ULONG iBuckets)
WRAPPER_NO_CONTRACT;
}

EEToProfInterfaceImpl::CHashTableImpl::~CHashTableImpl()
{
WRAPPER_NO_CONTRACT;
}

//---------------------------------------------------------------------------------------
//
// Comparison function for hash table of ClassIDs
Expand Down
3 changes: 2 additions & 1 deletion src/vm/eetoprofinterfaceimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ class EEToProfInterfaceImpl
{
public:
CHashTableImpl(ULONG iBuckets);

virtual ~CHashTableImpl();

protected:
virtual BOOL Cmp(SIZE_T k1, const HASHENTRY * pc2);
};
Expand Down
5 changes: 5 additions & 0 deletions src/vm/profilermetadataemitvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ m_cRefCount(0)
maxInitialGenericParam = TokenFromRid(m_pInnerInternalImport->GetCountWithTokenKind(mdtGenericParam), mdtGenericParam);
}

ProfilerMetadataEmitValidator::~ProfilerMetadataEmitValidator()
{
LIMITED_METHOD_CONTRACT;
}

//IUnknown
HRESULT ProfilerMetadataEmitValidator::QueryInterface(REFIID riid, void** ppInterface)
{
Expand Down
3 changes: 2 additions & 1 deletion src/vm/profilermetadataemitvalidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class ProfilerMetadataEmitValidator : public IMetaDataEmit2, public IMetaDataAss
{
public:
ProfilerMetadataEmitValidator(IMetaDataEmit* pInnerEmit);

virtual ~ProfilerMetadataEmitValidator();

//IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppInterface);
virtual ULONG STDMETHODCALLTYPE AddRef();
Expand Down
61 changes: 32 additions & 29 deletions src/vm/profilingenumerators.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@
// (e.g., ICorProfilerObjectEnum)
// Element -- the type of the objects this enumerator returns.
//
// pEnumInterfaceIID -- pointer to the class ID for this interface
// (you probably don't need to use this)
//
//
template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID = &__uuidof(EnumInterface) >
template< typename EnumInterface, typename Element >
class ProfilerEnum : public EnumInterface
{
public:
ProfilerEnum(CDynArray< Element >* elements);
ProfilerEnum();
~ProfilerEnum();
virtual ~ProfilerEnum();

// IUnknown functions

Expand Down Expand Up @@ -67,8 +64,14 @@ class ProfilerEnum : public EnumInterface
CDynArray< Element > m_elements;

LONG m_refCount;

private:
static const IID& m_pEnumInterfaceIID;
};

template< typename EnumInterface, typename Element >
const IID& ProfilerEnum< EnumInterface, Element >::m_pEnumInterfaceIID = __uuidof(EnumInterface);

//
//
// ProfilerEnum implementation
Expand Down Expand Up @@ -98,8 +101,8 @@ class ProfilerEnum : public EnumInterface
// </TODO>
//
//
template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::ProfilerEnum(CDynArray< Element >* elements) :
template< typename EnumInterface, typename Element >
ProfilerEnum< EnumInterface, Element >::ProfilerEnum(CDynArray< Element >* elements) :
m_currentElement(0),
m_refCount(1)
{
Expand All @@ -120,8 +123,8 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::ProfilerEnum(CDynArra
}
}

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::ProfilerEnum() :
template< typename EnumInterface, typename Element >
ProfilerEnum< EnumInterface, Element >::ProfilerEnum() :
m_currentElement(0),
m_refCount(1)
{
Expand All @@ -140,8 +143,8 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::ProfilerEnum() :
// Returns
// None
//
template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::~ProfilerEnum()
template< typename EnumInterface, typename Element >
ProfilerEnum< EnumInterface, Element >::~ProfilerEnum()
{
}

Expand All @@ -160,11 +163,11 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::~ProfilerEnum()
// E_NOINTERFACE -- if the enumerator does not implement the requested interface
//

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::QueryInterface(REFIID id, void** pInterface)
ProfilerEnum< EnumInterface, Element >::QueryInterface(REFIID id, void** pInterface)
{
if (*pEnumInterfaceIID == id)
if (m_pEnumInterfaceIID == id)
{
*pInterface = static_cast< EnumInterface* >(this);
}
Expand All @@ -182,16 +185,16 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::QueryInterface(REFIID
return S_OK;
}

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
ULONG
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::AddRef()
ProfilerEnum< EnumInterface, Element >::AddRef()
{
return InterlockedIncrement(&m_refCount);
}

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
ULONG
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Release()
ProfilerEnum< EnumInterface, Element >::Release()
{
ULONG refCount = InterlockedDecrement(&m_refCount);

Expand Down Expand Up @@ -225,9 +228,9 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Release()
// try to advance 1 item and return S_OK if it is successful
//

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Next(ULONG elementsRequested,
ProfilerEnum< EnumInterface, Element >::Next(ULONG elementsRequested,
Element elements[],
ULONG* elementsFetched)
{
Expand Down Expand Up @@ -307,9 +310,9 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Next(ULONG elementsRe
//
//

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::GetCount(ULONG* count)
ProfilerEnum< EnumInterface, Element >::GetCount(ULONG* count)
{
CONTRACTL
{
Expand Down Expand Up @@ -352,9 +355,9 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::GetCount(ULONG* count
// before and after calling Skip()
//
//
template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Skip(ULONG count)
ProfilerEnum< EnumInterface, Element >::Skip(ULONG count)
{
CONTRACTL
{
Expand Down Expand Up @@ -392,9 +395,9 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Skip(ULONG count)
//
//

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Reset()
ProfilerEnum< EnumInterface, Element >::Reset()
{
CONTRACTL
{
Expand Down Expand Up @@ -424,9 +427,9 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Reset()
// E_INVALIDARG -- if pInterface is an invalid pointer
//

template< typename EnumInterface, typename Element, const IID* pEnumInterfaceIID >
template< typename EnumInterface, typename Element >
HRESULT
ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Clone(EnumInterface** pInterface)
ProfilerEnum< EnumInterface, Element >::Clone(EnumInterface** pInterface)
{
CONTRACTL
{
Expand All @@ -446,7 +449,7 @@ ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >::Clone(EnumInterface**
HRESULT hr = S_OK;
EX_TRY
{
*pInterface = new ProfilerEnum< EnumInterface, Element, pEnumInterfaceIID >(&m_elements);
*pInterface = new ProfilerEnum< EnumInterface, Element >(&m_elements);
}
EX_CATCH
{
Expand Down
Loading

0 comments on commit 4c375f4

Please sign in to comment.