[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - comphelper/Library_comphelper.mk comphelper/source include/comphelper

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 29 08:37:21 UTC 2021


 comphelper/Library_comphelper.mk       |    2 
 comphelper/source/misc/profilezone.cxx |   95 -----------------------
 comphelper/source/misc/traceevent.cxx  |  134 +++++++++++++++++++++++++++++++++
 include/comphelper/profilezone.hxx     |   13 ---
 include/comphelper/traceevent.hxx      |   43 ++++++++++
 5 files changed, 180 insertions(+), 107 deletions(-)

New commits:
commit 6aed228d77738a7e94610c3d114218d760ebaf48
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue Apr 27 09:20:32 2021 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Thu Apr 29 10:36:38 2021 +0200

    Extend the trace event API with instant events
    
    Change-Id: I3a93c79f46ffc5768ddaf338789fe2daa225ef4d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114790
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/comphelper/Library_comphelper.mk b/comphelper/Library_comphelper.mk
index 46527d164abb..1da5e7daa658 100644
--- a/comphelper/Library_comphelper.mk
+++ b/comphelper/Library_comphelper.mk
@@ -116,7 +116,7 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
     comphelper/source/misc/numberedcollection \
     comphelper/source/misc/numbers \
     comphelper/source/misc/officerestartmanager \
-    comphelper/source/misc/profilezone \
+    comphelper/source/misc/traceevent \
     comphelper/source/misc/proxyaggregation \
     comphelper/source/misc/random \
     comphelper/source/misc/SelectionMultiplex \
diff --git a/comphelper/source/misc/profilezone.cxx b/comphelper/source/misc/profilezone.cxx
deleted file mode 100644
index 298e46e66d36..000000000000
--- a/comphelper/source/misc/profilezone.cxx
+++ /dev/null
@@ -1,95 +0,0 @@
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include <sal/config.h>
-
-#include <atomic>
-#include <iostream>
-#include <string_view>
-
-#include <comphelper/sequence.hxx>
-#include <comphelper/profilezone.hxx>
-#include <osl/time.h>
-#include <osl/thread.h>
-
-namespace comphelper
-{
-
-std::atomic<bool> ProfileZone::s_bRecording = false;
-
-int ProfileZone::s_nNesting = 0; // level of overlapped zones
-
-namespace
-{
-    std::vector<OUString> g_aRecording; // recorded data
-    ::osl::Mutex g_aMutex;
-}
-
-void ProfileZone::startRecording()
-{
-    ::osl::MutexGuard aGuard(g_aMutex);
-    s_nNesting = 0;
-    s_bRecording = true;
-}
-
-void ProfileZone::stopRecording()
-{
-    s_bRecording = false;
-}
-
-void ProfileZone::addRecording()
-{
-    assert(s_bRecording);
-
-    TimeValue aSystemTime;
-    osl_getSystemTime(&aSystemTime);
-    long long nNow = static_cast<long long>(aSystemTime.Seconds) * 1000000 + aSystemTime.Nanosec/1000;
-
-     // Generate a single "Complete Event" (type X)
-    OUString sRecordingData("{"
-                            "\"name\":\"" + OUString(m_sProfileId, strlen(m_sProfileId), RTL_TEXTENCODING_UTF8) + "\","
-                            "\"ph\":\"X\","
-                            "\"ts\":" + OUString::number(m_nCreateTime) + ","
-                            "\"dur\":" + OUString::number(nNow - m_nCreateTime) + ","
-                            "\"pid\":" + OUString::number(m_nPid) + ","
-                            "\"tid\":" + OUString::number(osl_getThreadIdentifier(nullptr)) +
-                            "},");
-    ::osl::MutexGuard aGuard(g_aMutex);
-
-    g_aRecording.emplace_back(sRecordingData);
-}
-
-css::uno::Sequence<OUString> ProfileZone::getRecordingAndClear()
-{
-    bool bRecording;
-    std::vector<OUString> aRecording;
-    {
-        ::osl::MutexGuard aGuard( g_aMutex );
-        bRecording = s_bRecording;
-        stopRecording();
-        aRecording.swap(g_aRecording);
-    }
-    // reset start time and nesting level
-    if (bRecording)
-        startRecording();
-    return ::comphelper::containerToSequence(aRecording);
-}
-
-void ProfileZone::startConsole() { m_nCreateTime = osl_getGlobalTimer(); }
-
-void ProfileZone::stopConsole()
-{
-    sal_uInt32 nEndTime = osl_getGlobalTimer();
-    std::cerr << "comphelper::ProfileZone: " << m_sProfileId << " finished in "
-              << nEndTime - m_nCreateTime << " ms" << std::endl;
-}
-
-} // namespace comphelper
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/comphelper/source/misc/traceevent.cxx b/comphelper/source/misc/traceevent.cxx
new file mode 100644
index 000000000000..aa99e8bf7e39
--- /dev/null
+++ b/comphelper/source/misc/traceevent.cxx
@@ -0,0 +1,134 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <atomic>
+#include <iostream>
+#include <string_view>
+
+#include <comphelper/profilezone.hxx>
+#include <comphelper/sequence.hxx>
+#include <comphelper/traceevent.hxx>
+
+#include <osl/time.h>
+#include <osl/thread.h>
+
+namespace comphelper
+{
+std::atomic<bool> TraceEvent::s_bRecording = false;
+
+int TraceEvent::s_nNesting = 0; // level of overlapped zones
+
+namespace
+{
+std::vector<OUString> g_aRecording; // recorded data
+::osl::Mutex g_aMutex;
+}
+
+void TraceEvent::addRecording(const OUString& sObject)
+{
+    ::osl::MutexGuard aGuard(g_aMutex);
+
+    g_aRecording.emplace_back(sObject);
+}
+
+void TraceEvent::addInstantEvent(const char* sProfileId)
+{
+    TimeValue aSystemTime;
+    osl_getSystemTime(&aSystemTime);
+    long long nNow
+        = static_cast<long long>(aSystemTime.Seconds) * 1000000 + aSystemTime.Nanosec / 1000;
+
+    int nPid = 0;
+    oslProcessInfo aProcessInfo;
+    aProcessInfo.Size = sizeof(oslProcessInfo);
+    if (osl_getProcessInfo(nullptr, osl_Process_IDENTIFIER, &aProcessInfo) == osl_Process_E_None)
+        nPid = aProcessInfo.Ident;
+
+    addRecording("{"
+                 "\"name:\""
+                 + OUString(sProfileId, strlen(sProfileId), RTL_TEXTENCODING_UTF8)
+                 + "\","
+                   "\"ph\":\"i\","
+                   "\"ts\":"
+                 + OUString::number(nNow)
+                 + ","
+                   "\"pid\":"
+                 + OUString::number(nPid)
+                 + ","
+                   "\"tid\":"
+                 + OUString::number(osl_getThreadIdentifier(nullptr)) + "},");
+}
+
+void ProfileZone::startRecording()
+{
+    ::osl::MutexGuard aGuard(g_aMutex);
+    s_nNesting = 0;
+    s_bRecording = true;
+}
+
+void ProfileZone::stopRecording() { s_bRecording = false; }
+
+void ProfileZone::addRecording()
+{
+    assert(s_bRecording);
+
+    TimeValue aSystemTime;
+    osl_getSystemTime(&aSystemTime);
+    long long nNow
+        = static_cast<long long>(aSystemTime.Seconds) * 1000000 + aSystemTime.Nanosec / 1000;
+
+    // Generate a single "Complete Event" (type X)
+    TraceEvent::addRecording("{"
+                             "\"name\":\""
+                             + OUString(m_sProfileId, strlen(m_sProfileId), RTL_TEXTENCODING_UTF8)
+                             + "\","
+                               "\"ph\":\"X\","
+                               "\"ts\":"
+                             + OUString::number(m_nCreateTime)
+                             + ","
+                               "\"dur\":"
+                             + OUString::number(nNow - m_nCreateTime)
+                             + ","
+                               "\"pid\":"
+                             + OUString::number(m_nPid)
+                             + ","
+                               "\"tid\":"
+                             + OUString::number(osl_getThreadIdentifier(nullptr)) + "},");
+}
+
+css::uno::Sequence<OUString> ProfileZone::getRecordingAndClear()
+{
+    bool bRecording;
+    std::vector<OUString> aRecording;
+    {
+        ::osl::MutexGuard aGuard(g_aMutex);
+        bRecording = s_bRecording;
+        stopRecording();
+        aRecording.swap(g_aRecording);
+    }
+    // reset start time and nesting level
+    if (bRecording)
+        startRecording();
+    return ::comphelper::containerToSequence(aRecording);
+}
+
+void ProfileZone::startConsole() { m_nCreateTime = osl_getGlobalTimer(); }
+
+void ProfileZone::stopConsole()
+{
+    sal_uInt32 nEndTime = osl_getGlobalTimer();
+    std::cerr << "comphelper::ProfileZone: " << m_sProfileId << " finished in "
+              << nEndTime - m_nCreateTime << " ms" << std::endl;
+}
+
+} // namespace comphelper
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/profilezone.hxx b/include/comphelper/profilezone.hxx
index 9e05e8806e8e..8ed591852807 100644
--- a/include/comphelper/profilezone.hxx
+++ b/include/comphelper/profilezone.hxx
@@ -12,23 +12,14 @@
 
 #include <sal/config.h>
 
-#include <atomic>
-
-#include <osl/process.h>
-#include <osl/time.h>
-#include <com/sun/star/uno/Sequence.h>
-#include <comphelper/comphelperdllapi.h>
-#include <rtl/ustring.hxx>
+#include <comphelper/traceevent.hxx>
 
 // implementation of XToolkitExperimental profiling API
 
 namespace comphelper
 {
-class COMPHELPER_DLLPUBLIC ProfileZone
+class COMPHELPER_DLLPUBLIC ProfileZone : public TraceEvent
 {
-private:
-    static std::atomic<bool> s_bRecording; // true during recording
-    static int s_nNesting;
     const char *m_sProfileId;
     long long m_nCreateTime;
     bool m_bConsole;
diff --git a/include/comphelper/traceevent.hxx b/include/comphelper/traceevent.hxx
new file mode 100644
index 000000000000..5c922b281487
--- /dev/null
+++ b/include/comphelper/traceevent.hxx
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#ifndef INCLUDED_COMPHELPER_TRACEEVENT_HXX
+#define INCLUDED_COMPHELPER_TRACEEVENT_HXX
+
+#include <sal/config.h>
+
+#include <atomic>
+
+#include <osl/process.h>
+#include <osl/time.h>
+#include <com/sun/star/uno/Sequence.h>
+#include <comphelper/comphelperdllapi.h>
+#include <rtl/ustring.hxx>
+
+// implementation of XToolkitExperimental profiling API
+
+namespace comphelper
+{
+class COMPHELPER_DLLPUBLIC TraceEvent
+{
+protected:
+    static std::atomic<bool> s_bRecording; // true during recording
+    static int s_nNesting;
+
+    static void addRecording(const OUString& sObject);
+
+public:
+    static void addInstantEvent(const char* sProfileId);
+};
+
+} // namespace comphelper
+
+#endif // INCLUDED_COMPHELPER_TRACEEVENT_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list