summaryrefslogtreecommitdiffstats
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-06 10:57:09 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-06 14:25:09 +0100
commitee9ccdf6ecd944c2f448a30d10700754d1f0cfa2 (patch)
treed9a9877a178229488df17ac7a3fca8e22135ed67 /comphelper
parentBring back signature line context menu items (diff)
downloadcore-ee9ccdf6ecd944c2f448a30d10700754d1f0cfa2.tar.gz
core-ee9ccdf6ecd944c2f448a30d10700754d1f0cfa2.zip
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@collabora.com> Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/profilezone.cxx73
1 files changed, 33 insertions, 40 deletions
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: */