comphelper/source/misc/traceevent.cxx |    7 ++++++-
 include/comphelper/profilezone.hxx    |   14 ++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit 2623b86bcdf90f8fbf1fbf32c4a8e78380625a19
Author:     Gopi Krishna Menon <[email protected]>
AuthorDate: Thu Jul 29 15:21:13 2021 +0530
Commit:     Tor Lillqvist <[email protected]>
CommitDate: Tue Oct 26 10:24:14 2021 +0200

    Fix Nesting Level Bug in ProfileZone
    
    Moves the profile zone global nesting variable into the source from header 
and makes it threadlocal
    
    Change-Id: I97751f5c532d8e0e36adb7d9d383bd88f752953f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119662
    Tested-by: Jenkins
    Reviewed-by: Tor Lillqvist <[email protected]>
    (cherry picked from commit 74f4a1796f94477d459c71d0a0aaa8f4a430e208)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119618
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/comphelper/source/misc/traceevent.cxx 
b/comphelper/source/misc/traceevent.cxx
index 4fc4410615b4..4216de109ca2 100644
--- a/comphelper/source/misc/traceevent.cxx
+++ b/comphelper/source/misc/traceevent.cxx
@@ -29,7 +29,8 @@ std::size_t TraceEvent::s_nBufferSize = 0;
 void (*TraceEvent::s_pBufferFullCallback)() = nullptr;
 
 int AsyncEvent::s_nIdCounter = 0;
-int ProfileZone::s_nNesting = 0;
+
+static thread_local int nProfileZoneNesting = 0; // Level of Nested Profile 
Zones
 
 namespace
 {
@@ -141,6 +142,10 @@ void ProfileZone::stopConsole()
               << nEndTime - m_nCreateTime << " ms" << std::endl;
 }
 
+int ProfileZone::getNestingLevel() { return nProfileZoneNesting; }
+
+void ProfileZone::setNestingLevel(int nNestingLevel) { nProfileZoneNesting = 
nNestingLevel; }
+
 } // namespace comphelper
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/profilezone.hxx 
b/include/comphelper/profilezone.hxx
index 2a8bb9f3dba0..aa5d41070a81 100644
--- a/include/comphelper/profilezone.hxx
+++ b/include/comphelper/profilezone.hxx
@@ -22,8 +22,6 @@ namespace comphelper
 {
 class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent
 {
-    static int s_nNesting; // level of nested zones.
-
     long long m_nCreateTime;
     bool m_bConsole;
     void stopConsole();
@@ -31,7 +29,10 @@ class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent
 
     void addRecording();
 
- ProfileZone(const char* sName, const OUString &sArgs, bool bConsole)
+    static void setNestingLevel(int nNestingLevel);
+    static int getNestingLevel();
+
+    ProfileZone(const char* sName, const OUString &sArgs, bool bConsole)
         : NamedEvent(sName, sArgs)
         , m_bConsole(bConsole)
         , m_nNesting(-1)
@@ -40,7 +41,8 @@ class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent
         {
             m_nCreateTime = getNow();
 
-            m_nNesting = s_nNesting++;
+            m_nNesting = getNestingLevel();
+            setNestingLevel(getNestingLevel() + 1);
         }
         else
             m_nCreateTime = 0;
@@ -77,9 +79,9 @@ class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent
     {
         if (m_nCreateTime > 0)
         {
-            s_nNesting--;
+            setNestingLevel(getNestingLevel() - 1);
 
-            if (m_nNesting != s_nNesting)
+            if (m_nNesting != getNestingLevel())
             {
                 SAL_WARN("comphelper.traceevent", "Incorrect ProfileZone 
nesting for " << m_sName);
             }

Reply via email to