From 2266f186b9e4eef50d94dbf26b3dccdc1b4a39bc Mon Sep 17 00:00:00 2001 From: Andrey Kvochko Date: Fri, 15 Sep 2017 22:33:54 +0300 Subject: [PATCH] Format types differently from methods --- profiler/profiler/src/profiler.cpp | 26 ++++++++++++++++++++++---- profiler/profiler/src/stackentry.h | 3 ++- src/track/tracetree.h | 26 +++++++++++++++++--------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/profiler/profiler/src/profiler.cpp b/profiler/profiler/src/profiler.cpp index 7ded8dd..880fb5c 100644 --- a/profiler/profiler/src/profiler.cpp +++ b/profiler/profiler/src/profiler.cpp @@ -90,8 +90,9 @@ __thread StackEntry* g_freeStackEntryListItems = nullptr; StackEntry::StackEntry(unsigned int funcId, char* className, char* methodName, + bool isType, StackEntry *next) - : m_funcId(funcId), m_next(next) + : m_funcId(funcId), m_isType(isType), m_next(next) { strncpy(m_className, className, sizeof (m_className)); strncpy(m_methodName, methodName, sizeof (m_methodName)); @@ -106,9 +107,26 @@ void PushShadowStack(FunctionID functionId, char* className, char* methodName) g_freeStackEntryListItems = g_freeStackEntryListItems->m_next; - new (se) StackEntry(functionId, className, methodName, g_shadowStack); + new (se) StackEntry(functionId, className, methodName, false, g_shadowStack); } else { - se = new StackEntry(functionId, className, methodName, g_shadowStack); + se = new StackEntry(functionId, className, methodName, false, g_shadowStack); + } + + g_shadowStack = se; +} + +void PushShadowStack(ClassID classId, char* className) +{ + StackEntry *se; + + if (g_freeStackEntryListItems != nullptr) { + se = g_freeStackEntryListItems; + + g_freeStackEntryListItems = g_freeStackEntryListItems->m_next; + + new (se) StackEntry(classId, className, "", true, g_shadowStack); + } else { + se = new StackEntry(classId, className, "", true, g_shadowStack); } g_shadowStack = se; @@ -501,7 +519,7 @@ HRESULT STDMETHODCALLTYPE { char className[MAX_NAME_LENGTH + 1]; encodeWChar(szClassName, className); - PushShadowStack((FunctionID)classId, className, className); + PushShadowStack(classId, className); } ULONG objectSize; diff --git a/profiler/profiler/src/stackentry.h b/profiler/profiler/src/stackentry.h index 0eec2ff..9e457c0 100644 --- a/profiler/profiler/src/stackentry.h +++ b/profiler/profiler/src/stackentry.h @@ -6,11 +6,12 @@ static constexpr size_t MAX_NAME_LENGTH = 512; class StackEntry { public: - StackEntry(unsigned int funcId, char* className, char* methodName, StackEntry *next); + StackEntry(unsigned int funcId, char* className, char* methodName, bool isType, StackEntry *next); unsigned int m_funcId; char m_className[MAX_NAME_LENGTH + 1]; char m_methodName[MAX_NAME_LENGTH + 1]; + bool m_isType; StackEntry *m_next; }; diff --git a/src/track/tracetree.h b/src/track/tracetree.h index 8231e2e..e80d40b 100644 --- a/src/track/tracetree.h +++ b/src/track/tracetree.h @@ -90,8 +90,8 @@ public: StackEntry *stackIter = g_shadowStack; if (stackIter != nullptr) { - void* managedStack[Trace::MAX_SIZE]; - int managedStackSize = 0; + void* managedStack[Trace::MAX_SIZE]; + int managedStackSize = 0; handleIP((void *) (uintptr_t) -1, false); @@ -99,16 +99,24 @@ public: void *ip = reinterpret_cast(stackIter->m_funcId); if (knownNames.find(ip) == knownNames.end()) { - std::string managed_name = stackIter->m_className; - managed_name.append("."); - managed_name.append(stackIter->m_methodName); - + std::string managed_name; + if (stackIter->m_isType) + { + managed_name.append("["); + managed_name.append(stackIter->m_className); + managed_name.append("]"); + } + else + { + managed_name.append(stackIter->m_className); + managed_name.append("."); + managed_name.append(stackIter->m_methodName); + } fprintf(out, "n %" PRIxPTR " %s\n", reinterpret_cast(ip), managed_name.c_str()); - - knownNames.insert(ip); + knownNames.insert(ip); } - managedStack[managedStackSize++] = ip; + managedStack[managedStackSize++] = ip; stackIter = stackIter->m_next; } -- 2.7.4