diff options
author | Tor Lillqvist <tml@collabora.com> | 2021-04-27 18:43:16 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-04-29 08:45:07 +0200 |
commit | 89c0d087c657c31a3198c481a63ca0549b8a4503 (patch) | |
tree | b578887c79856f9050eb879efdd5255bae8d4d51 /comphelper/source | |
parent | 896586e91a2b0b3437ff1c9ad1d72fbce04a7fed (diff) |
Introduce Async trace events and a unit test
Async events are ones that emit separate 'b' (begin) and 'e' (end)
traces. (Compare to the Complete event that emit a single 'X' trace
that contains both the start timstamp and the duration.)
There are two kinds of Async events: Freestanding ones that are not
related to other events at all, and nested ones that have to be nested
between the 'b' and 'e' events of a parent Async event.
Still needs some work, at least a way to end a nested AsyncEvent
(cause it to emit the 'e' event) before it gets destructed thanks to
the parent being destructed.
Change-Id: I3721fa701ad32639b1edc1cfa8db7acde5caf9b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114756
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'comphelper/source')
-rw-r--r-- | comphelper/source/misc/traceevent.cxx | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/comphelper/source/misc/traceevent.cxx b/comphelper/source/misc/traceevent.cxx index 9febf71e2db7..81039c9ca82d 100644 --- a/comphelper/source/misc/traceevent.cxx +++ b/comphelper/source/misc/traceevent.cxx @@ -17,9 +17,6 @@ #include <comphelper/sequence.hxx> #include <comphelper/traceevent.hxx> -#include <osl/time.h> -#include <osl/thread.h> - namespace comphelper { #ifdef DBG_UTIL @@ -27,27 +24,25 @@ std::atomic<bool> TraceEvent::s_bRecording = (getenv("TRACE_EVENT_RECORDING") != #else std::atomic<bool> TraceEvent::s_bRecording = false; #endif +int AsyncEvent::s_nIdCounter = 0; int ProfileZone::s_nNesting = 0; namespace { std::vector<OUString> g_aRecording; // recorded data -::osl::Mutex g_aMutex; +osl::Mutex g_aMutex; } void TraceEvent::addRecording(const OUString& sObject) { - ::osl::MutexGuard aGuard(g_aMutex); + osl::MutexGuard aGuard(g_aMutex); g_aRecording.emplace_back(sObject); } void TraceEvent::addInstantEvent(const char* sName) { - TimeValue aSystemTime; - osl_getSystemTime(&aSystemTime); - long long nNow - = static_cast<long long>(aSystemTime.Seconds) * 1000000 + aSystemTime.Nanosec / 1000; + long long nNow = getNow(); int nPid = 0; oslProcessInfo aProcessInfo; @@ -72,18 +67,18 @@ void TraceEvent::addInstantEvent(const char* sName) void TraceEvent::startRecording() { - ::osl::MutexGuard aGuard(g_aMutex); + osl::MutexGuard aGuard(g_aMutex); s_bRecording = true; } void TraceEvent::stopRecording() { s_bRecording = false; } -css::uno::Sequence<OUString> TraceEvent::getRecordingAndClear() +std::vector<OUString> TraceEvent::getEventVectorAndClear() { bool bRecording; std::vector<OUString> aRecording; { - ::osl::MutexGuard aGuard(g_aMutex); + osl::MutexGuard aGuard(g_aMutex); bRecording = s_bRecording; stopRecording(); aRecording.swap(g_aRecording); @@ -91,17 +86,19 @@ css::uno::Sequence<OUString> TraceEvent::getRecordingAndClear() // reset start time and nesting level if (bRecording) startRecording(); - return ::comphelper::containerToSequence(aRecording); + return aRecording; +} + +css::uno::Sequence<OUString> TraceEvent::getRecordingAndClear() +{ + return comphelper::containerToSequence(getEventVectorAndClear()); } void ProfileZone::addRecording() { assert(s_bRecording); - TimeValue aSystemTime; - osl_getSystemTime(&aSystemTime); - long long nNow - = static_cast<long long>(aSystemTime.Seconds) * 1000000 + aSystemTime.Nanosec / 1000; + long long nNow = getNow(); // Generate a single "Complete Event" (type X) TraceEvent::addRecording("{" |