From: Aleksei Vereshchagin Date: Tue, 3 Apr 2018 20:30:42 +0000 (+0300) Subject: Add GC start/stop info to tracelog X-Git-Tag: submit/tizen/20180619.075036^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d03eb9a9d478d2a977183036dac854a45b3a62ca;p=sdk%2Ftools%2Fcoreprofiler.git Add GC start/stop info to tracelog --- diff --git a/src/profiler.cpp b/src/profiler.cpp index 06be2b8..a259cf1 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -914,11 +914,24 @@ HRESULT STDMETHODCALLTYPE Profiler::GarbageCollectionStarted( { LOG().Trace() << "GarbageCollectionStarted()"; + HRESULT hrReturn = S_OK; HRESULT hr; + + hr = m_commonTrace.GarbageCollectionStarted( + cGenerations, generationCollected, reason); + if (FAILED(hr) && SUCCEEDED(hrReturn)) + { + hrReturn = hr; + } + hr = m_memoryTrace.GarbageCollectionStarted( cGenerations, generationCollected, reason); + if (FAILED(hr) && SUCCEEDED(hrReturn)) + { + hrReturn = hr; + } - return hr; + return hrReturn; } HRESULT STDMETHODCALLTYPE Profiler::SurvivingReferences( @@ -934,10 +947,22 @@ HRESULT STDMETHODCALLTYPE Profiler::GarbageCollectionFinished() { LOG().Trace() << "GarbageCollectionFinished()"; + HRESULT hrReturn = S_OK; HRESULT hr; + hr = m_memoryTrace.GarbageCollectionFinished(); + if (FAILED(hr) && SUCCEEDED(hrReturn)) + { + hrReturn = hr; + } - return S_OK; + hr = m_commonTrace.GarbageCollectionFinished(); + if (FAILED(hr) && SUCCEEDED(hrReturn)) + { + hrReturn = hr; + } + + return hrReturn; } HRESULT STDMETHODCALLTYPE Profiler::FinalizeableObjectQueued( diff --git a/src/trace/commontrace.cpp b/src/trace/commontrace.cpp index 2c5f845..b330902 100644 --- a/src/trace/commontrace.cpp +++ b/src/trace/commontrace.cpp @@ -270,6 +270,7 @@ void CommonTrace::ProcessConfig(ProfilerConfig &config) | COR_PRF_MONITOR_ASSEMBLY_LOADS | COR_PRF_MONITOR_MODULE_LOADS | COR_PRF_MONITOR_CLASS_LOADS + | COR_PRF_MONITOR_GC | COR_PRF_MONITOR_THREADS; // This events are required for tracing of call stack dynamics. @@ -1175,3 +1176,53 @@ HRESULT CommonTrace::ThreadAssignedToOSThread( return hr; } + +HRESULT CommonTrace::GarbageCollectionStarted( + int cGenerations, + BOOL generationCollected[], + COR_PRF_GC_REASON reason) noexcept +{ + if (m_disabled) + return S_OK; + + HRESULT hr = S_OK; + try + { + ThreadInfo *pThreadInfo = m_profiler.GetCommonTrace().GetThreadInfo(); + TRACE().DumpGarbageCollectionStarted( + pThreadInfo == nullptr ? InternalID() : pThreadInfo->internalId, + m_profiler.GetTickCountFromInit(), + cGenerations, + generationCollected, + reason + ); + } + catch (const std::exception &e) + { + hr = m_profiler.HandleException(e); + } + + return hr; +} + +HRESULT CommonTrace::GarbageCollectionFinished() noexcept +{ + if (m_disabled) + return S_OK; + + HRESULT hr = S_OK; + try + { + ThreadInfo *pThreadInfo = m_profiler.GetCommonTrace().GetThreadInfo(); + TRACE().DumpGarbageCollectionFinished( + pThreadInfo == nullptr ? InternalID() : pThreadInfo->internalId, + m_profiler.GetTickCountFromInit() + ); + } + catch (const std::exception &e) + { + hr = m_profiler.HandleException(e); + } + + return hr; +} diff --git a/src/trace/commontrace.h b/src/trace/commontrace.h index 59e0683..2bcb0c1 100644 --- a/src/trace/commontrace.h +++ b/src/trace/commontrace.h @@ -141,6 +141,13 @@ public: ThreadID managedThreadId, DWORD osThreadId) noexcept; + HRESULT GarbageCollectionStarted( + int cGenerations, + BOOL generationCollected[], + COR_PRF_GC_REASON reason) noexcept; + + HRESULT GarbageCollectionFinished() noexcept; + private: int m_tlsThreadInfoIndex; diff --git a/src/tracelog.cpp b/src/tracelog.cpp index 070bba1..a518809 100644 --- a/src/tracelog.cpp +++ b/src/tracelog.cpp @@ -430,6 +430,56 @@ public: } } + virtual void DumpGarbageCollectionStarted( + InternalID threadIid, + DWORD ticksFromStart, + int cGenerations, + BOOL generationCollected[], + COR_PRF_GC_REASON reason) override + { + std::lock_guard streamLock(m_mStream); + if (threadIid.id == -1) + { + PAL_fprintf(m_pStream, "gch gcs ? %d", ticksFromStart); + } + else + { + PAL_fprintf(m_pStream, "gch gcs 0x%08x %d", threadIid.id, + ticksFromStart); + } + switch (reason) + { + case COR_PRF_GC_INDUCED: + PAL_fprintf(m_pStream, " induced"); + break; + default: + PAL_fprintf(m_pStream, " ?"); + break; + } + PAL_fprintf(m_pStream, cGenerations > 0 ? " " : ""); + for (int i = 0; i < cGenerations; ++i) + { + PAL_fprintf(m_pStream, generationCollected[i] ? "t" : "f"); + } + PAL_fprintf(m_pStream, "\n"); + } + + virtual void DumpGarbageCollectionFinished( + InternalID threadIid, + DWORD ticksFromStart) override + { + std::lock_guard streamLock(m_mStream); + if (threadIid.id == -1) + { + PAL_fprintf(m_pStream, "gch gcf ? %d", ticksFromStart); + } + else + { + PAL_fprintf(m_pStream, "gch gcf 0x%08x %d", threadIid.id, + ticksFromStart); + } + } + virtual void DumpGcHeapAllocTable( DWORD ticksFromStart, const AllocTable &allocInfoByTypes) override diff --git a/src/tracelog.h b/src/tracelog.h index 4c9a87b..f83c06c 100644 --- a/src/tracelog.h +++ b/src/tracelog.h @@ -154,6 +154,17 @@ public: InternalID threadIid, const EventSummary &summary) = 0; + virtual void DumpGarbageCollectionStarted( + InternalID threadIid, + DWORD ticksFromStart, + int cGenerations, + BOOL generationCollected[], + COR_PRF_GC_REASON reason) = 0; + + virtual void DumpGarbageCollectionFinished( + InternalID threadIid, + DWORD ticksFromStart) = 0; + virtual void DumpGcHeapAllocTable( DWORD ticksFromStart, const AllocTable &allocInfoByTypes) = 0;