Kaydet (Commit) ee9ccdf6 authored tarafından Noel Grandin's avatar Noel Grandin

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/62936Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Tested-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst dc80d60d
......@@ -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: */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment