[Libreoffice-commits] core.git: comphelper/source include/comphelper writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Mar 4 08:04:52 UTC 2020


 comphelper/source/misc/profilezone.cxx   |    9 +++++++
 include/comphelper/profilezone.hxx       |   36 +++++++++++++++++++++++++------
 writerfilter/source/filter/RtfFilter.cxx |    4 ---
 3 files changed, 39 insertions(+), 10 deletions(-)

New commits:
commit c57d6d39c80844c9d4c6bfed85cc151e52a67b34
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Mar 3 21:01:58 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Mar 4 09:04:14 2020 +0100

    comphelper: allow simple ad-hoc measuring with ProfileZones
    
    And then remove the manual measuring from the RTF import.
    
    Sample output:
    
    comphelper::ProfileZone: RtfFilter::filter finished in 180 ms
    
    Change-Id: I85e2e12d82ff491a2991a41e5a6f6d1410e12363
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89905
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/comphelper/source/misc/profilezone.cxx b/comphelper/source/misc/profilezone.cxx
index ff76a4f35e8d..5abcca8a80b3 100644
--- a/comphelper/source/misc/profilezone.cxx
+++ b/comphelper/source/misc/profilezone.cxx
@@ -10,6 +10,7 @@
 #include <sal/config.h>
 
 #include <atomic>
+#include <iostream>
 
 #include <comphelper/sequence.hxx>
 #include <comphelper/profilezone.hxx>
@@ -98,6 +99,14 @@ css::uno::Sequence<OUString> getRecordingAndClear()
 
 } // namespace ProfileRecording
 
+void ProfileZone::startConsole() { m_aCreateTime = osl_getGlobalTimer(); }
+
+void ProfileZone::stopConsole()
+{
+    sal_uInt32 nEndTime = osl_getGlobalTimer();
+    std::cerr << "comphelper::ProfileZone: " << m_sProfileId << " finished in "
+              << nEndTime - m_aCreateTime << " ms" << std::endl;
+}
 
 } // namespace comphelper
 
diff --git a/include/comphelper/profilezone.hxx b/include/comphelper/profilezone.hxx
index 8cbc078f6621..81294a4c41c6 100644
--- a/include/comphelper/profilezone.hxx
+++ b/include/comphelper/profilezone.hxx
@@ -38,22 +38,46 @@ class COMPHELPER_DLLPUBLIC ProfileZone
 {
 private:
     const char * m_sProfileId;
-    long long const m_aCreateTime;
+    long long m_aCreateTime;
+    bool m_bConsole;
+    void startConsole();
+    void stopConsole();
 public:
     static std::atomic<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)
+    /**
+     * Starts measuring the cost of a C++ scope.
+     *
+     * 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.
+     *
+     * The second parameter can be used for ad-hoc local measuring by adding a single line of code
+     * at a C++ scope start. Example:
+     *
+     * comphelper::ProfileZone aZone("RtfFilter::filter", true);
+     *
+     * Similar to the DEBUG macro in sal/log.hxx, don't forget to remove these lines before
+     * committing.
+     */
+    ProfileZone(const char *sProfileId, bool bConsole = false)
         : m_sProfileId(sProfileId),
-          m_aCreateTime(g_bRecording ? ProfileRecording::addRecording(sProfileId, 0) : 0)
+          m_aCreateTime(g_bRecording ? ProfileRecording::addRecording(sProfileId, 0) : 0),
+          m_bConsole(bConsole)
     {
+        if (m_bConsole)
+        {
+            startConsole();
+        }
     }
     ~ProfileZone()
     {
         if (g_bRecording)
             ProfileRecording::addRecording(m_sProfileId, m_aCreateTime);
+        if (m_bConsole)
+        {
+            stopConsole();
+        }
     }
 };
 
diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx
index 68995b348d80..c58867646657 100644
--- a/writerfilter/source/filter/RtfFilter.cxx
+++ b/writerfilter/source/filter/RtfFilter.cxx
@@ -81,7 +81,6 @@ RtfFilter::RtfFilter(uno::Reference<uno::XComponentContext> xContext)
 
 sal_Bool RtfFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescriptor)
 {
-    sal_uInt32 nStartTime = osl_getGlobalTimer();
     if (m_xSrcDoc.is())
     {
         uno::Reference<lang::XMultiServiceFactory> xMSF(m_xContext->getServiceManager(),
@@ -148,9 +147,6 @@ sal_Bool RtfFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescripto
                 m_xContext, xInputStream, m_xDstDoc, xFrame, xStatusIndicator, aMediaDesc));
         pDocument->resolve(*pStream);
         bResult = true;
-        sal_uInt32 nEndTime = osl_getGlobalTimer();
-        SAL_INFO("writerfilter.profile",
-                 "RtfFilter::filter: finished in " << nEndTime - nStartTime << " ms");
     }
     catch (const io::WrongFormatException&)
     {


More information about the Libreoffice-commits mailing list