comphelper/source/misc/traceevent.cxx | 16 ++++++++++++++++ include/comphelper/traceevent.hxx | 4 ++++ 2 files changed, 20 insertions(+)
New commits: commit 09e89e7282a032c4cb944a66c0ddf199b9aa4a0b Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Tue Jun 29 15:03:23 2021 +0300 Commit: Tor Lillqvist <t...@collabora.com> CommitDate: Tue Jun 29 16:01:53 2021 +0200 Enable flushing accumulated Trace Events when their number reaches a limit Change-Id: I99ecf56b0faa5c444dbe9e22b8cce035f240c35c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118088 Tested-by: Jenkins Reviewed-by: Tor Lillqvist <t...@collabora.com> diff --git a/comphelper/source/misc/traceevent.cxx b/comphelper/source/misc/traceevent.cxx index 793fea6cdb0e..c379bbb97f7e 100644 --- a/comphelper/source/misc/traceevent.cxx +++ b/comphelper/source/misc/traceevent.cxx @@ -24,6 +24,10 @@ std::atomic<bool> TraceEvent::s_bRecording = (getenv("TRACE_EVENT_RECORDING") != #else std::atomic<bool> TraceEvent::s_bRecording = false; #endif + +std::size_t TraceEvent::s_nBufferSize = 0; +void (*TraceEvent::s_pBufferFullCallback)() = nullptr; + int AsyncEvent::s_nIdCounter = 0; int ProfileZone::s_nNesting = 0; @@ -38,6 +42,12 @@ void TraceEvent::addRecording(const OUString& sObject) osl::MutexGuard aGuard(g_aMutex); g_aRecording.emplace_back(sObject); + + if (s_nBufferSize > 0 && g_aRecording.size() >= s_nBufferSize) + { + if (s_pBufferFullCallback != nullptr) + (*s_pBufferFullCallback)(); + } } void TraceEvent::addInstantEvent(const char* sName, const std::map<OUString, OUString>& args) @@ -72,6 +82,12 @@ void TraceEvent::startRecording() void TraceEvent::stopRecording() { s_bRecording = false; } +void TraceEvent::setBufferSizeAndCallback(std::size_t bufferSize, void (*bufferFullCallback)()) +{ + s_nBufferSize = bufferSize; + s_pBufferFullCallback = bufferFullCallback; +} + std::vector<OUString> TraceEvent::getEventVectorAndClear() { bool bRecording; diff --git a/include/comphelper/traceevent.hxx b/include/comphelper/traceevent.hxx index 3c8bedfe8dec..044d1686b35e 100644 --- a/include/comphelper/traceevent.hxx +++ b/include/comphelper/traceevent.hxx @@ -43,6 +43,9 @@ private: return -1; } + static std::size_t s_nBufferSize; + static void (*s_pBufferFullCallback)(); + protected: static std::atomic<bool> s_bRecording; // true during recording @@ -99,6 +102,7 @@ public: static void startRecording(); static void stopRecording(); + static void setBufferSizeAndCallback(std::size_t bufferSize, void (*bufferFullCallback)()); static std::vector<OUString> getEventVectorAndClear(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits