[Libreoffice-commits] core.git: comphelper/source include/comphelper
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Nov 6 13:26:35 UTC 2018
comphelper/source/misc/profilezone.cxx | 73 ++++++++++++++-------------------
include/comphelper/profilezone.hxx | 13 ++++-
2 files changed, 44 insertions(+), 42 deletions(-)
New commits:
commit ee9ccdf6ecd944c2f448a30d10700754d1f0cfa2
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Nov 6 10:57:09 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Nov 6 14:25:09 2018 +0100
reduce cost of ProfileZone when it is not active
by avoiding taking the mutex
Also reduce the code that the mutex covers to the minimum necessary.
Change-Id: I115c8a447ec17f4800c39557e8de0bc8c669b47b
Reviewed-on: https://gerrit.libreoffice.org/62936
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/comphelper/source/misc/profilezone.cxx b/comphelper/source/misc/profilezone.cxx
index 7847246f09c0..dc2a713228b8 100644
--- a/comphelper/source/misc/profilezone.cxx
+++ b/comphelper/source/misc/profilezone.cxx
@@ -15,10 +15,11 @@
namespace comphelper
{
+volatile bool ProfileZone::g_bRecording(false);
+
namespace ProfileRecording
{
-static bool g_bRecording(false); // true during recording
static std::vector<OUString> g_aRecording; // recorded data
static long long g_aSumTime(0); // overall zone time in microsec
static int g_aNesting; // level of overlapped zones
@@ -27,46 +28,49 @@ static ::osl::Mutex g_aMutex;
void startRecording(bool bStartRecording)
{
- ::osl::MutexGuard aGuard( g_aMutex );
if (bStartRecording)
{
TimeValue systemTime;
osl_getSystemTime( &systemTime );
+ ::osl::MutexGuard aGuard( g_aMutex );
g_aStartTime = static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec/1000;
g_aNesting = 0;
}
- g_bRecording = bStartRecording;
+ ProfileZone::g_bRecording = bStartRecording;
}
long long addRecording(const char * aProfileId, long long aCreateTime)
{
+ assert( ProfileZone::g_bRecording );
+
+ TimeValue systemTime;
+ osl_getSystemTime( &systemTime );
+ long long aTime = static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec/1000;
+
+ if (!aProfileId)
+ aProfileId = "(null)";
+ OUString aString(aProfileId, strlen(aProfileId), RTL_TEXTENCODING_UTF8);
+
+ OUString sRecordingData(OUString::number(osl_getThreadIdentifier(nullptr)) + " " +
+ OUString::number(aTime/1000000.0) + " " + aString + ": " +
+ (aCreateTime == 0 ? OUString("start") : OUString("stop")) +
+ (aCreateTime != 0 ? (" " + OUString::number((aTime - aCreateTime)/1000.0) + " ms") : OUString("")));
+
::osl::MutexGuard aGuard( g_aMutex );
- if ( g_bRecording )
+
+ g_aRecording.emplace_back(sRecordingData);
+ if (aCreateTime == 0)
{
- TimeValue systemTime;
- osl_getSystemTime( &systemTime );
- long long aTime = static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec/1000;
- if (!aProfileId)
- aProfileId = "(null)";
- OUString aString(aProfileId, strlen(aProfileId), RTL_TEXTENCODING_UTF8);
- g_aRecording.emplace_back(OUString::number(osl_getThreadIdentifier(nullptr)) + " " +
- OUString::number(aTime/1000000.0) + " " + aString + ": " +
- (aCreateTime == 0 ? OUString("start") : OUString("stop")) +
- (aCreateTime != 0 ? (" " + OUString::number((aTime - aCreateTime)/1000.0) + " ms") : OUString(""))
- );
- if (aCreateTime == 0)
- {
- g_aNesting++;
- return aTime;
- }
- // neglect ProfileZones created before startRecording
- else if (aCreateTime >= g_aStartTime)
- {
- if (g_aNesting > 0)
- g_aNesting--;
- if (g_aNesting == 0)
- g_aSumTime += aTime - aCreateTime;
- }
+ g_aNesting++;
+ return aTime;
+ }
+ // neglect ProfileZones created before startRecording
+ else if (aCreateTime >= g_aStartTime)
+ {
+ if (g_aNesting > 0)
+ g_aNesting--;
+ if (g_aNesting == 0)
+ g_aSumTime += aTime - aCreateTime;
}
return 0;
}
@@ -77,7 +81,7 @@ css::uno::Sequence<OUString> getRecordingAndClear()
std::vector<OUString> aRecording;
{
::osl::MutexGuard aGuard( g_aMutex );
- bRecording = g_bRecording;
+ bRecording = ProfileZone::g_bRecording;
startRecording(false);
aRecording.swap(g_aRecording);
long long aSumTime = g_aSumTime;
@@ -91,17 +95,6 @@ css::uno::Sequence<OUString> getRecordingAndClear()
} // namespace ProfileRecording
-ProfileZone::ProfileZone(const char * sProfileId) :
- m_sProfileId(sProfileId),
- m_aCreateTime(ProfileRecording::addRecording(sProfileId, 0))
-{
-}
-
-ProfileZone::~ProfileZone()
-{
- ProfileRecording::addRecording(m_sProfileId, m_aCreateTime);
-}
-
} // namespace comphelper
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/profilezone.hxx b/include/comphelper/profilezone.hxx
index 3b3b5ee5041c..9def6f994fba 100644
--- a/include/comphelper/profilezone.hxx
+++ b/include/comphelper/profilezone.hxx
@@ -36,12 +36,21 @@ private:
const char * m_sProfileId;
long long const m_aCreateTime;
public:
+ static volatile bool g_bRecording; // true during recording
// Note that the char pointer is stored as such in the ProfileZone object and used in the
// destructor, so be sure to pass a pointer that stays valid for the duration of the object's
// lifetime.
- ProfileZone(const char * sProfileId);
- ~ProfileZone();
+ ProfileZone(const char *sProfileId)
+ : m_sProfileId(sProfileId),
+ m_aCreateTime(g_bRecording ? ProfileRecording::addRecording(sProfileId, 0) : 0)
+ {
+ }
+ ~ProfileZone()
+ {
+ if (g_bRecording)
+ ProfileRecording::addRecording(m_sProfileId, m_aCreateTime);
+ }
};
} // namespace comphelper
More information about the Libreoffice-commits
mailing list