diff options
author | Tor Lillqvist <tml@collabora.com> | 2021-05-11 13:58:38 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-06-09 13:49:31 +0200 |
commit | 6038c9125bcb9f6d5dc2b998f2bef476ba1b1f98 (patch) | |
tree | be725a15fd8d484ee2f0c25702a9f638dafeaa01 /include | |
parent | e4f5705b91ecacdfc84e564e116dfe812fd96b61 (diff) |
Add the possibility to include a set of arguments in Trace Events
Change-Id: I55720baf64bd9b719026c94e4373b6368a1a7106
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116847
Tested-by: Tor Lillqvist <tml@collabora.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/profilezone.hxx | 9 | ||||
-rw-r--r-- | include/comphelper/traceevent.hxx | 82 |
2 files changed, 63 insertions, 28 deletions
diff --git a/include/comphelper/profilezone.hxx b/include/comphelper/profilezone.hxx index 3431c20efcea..babd11f5b93b 100644 --- a/include/comphelper/profilezone.hxx +++ b/include/comphelper/profilezone.hxx @@ -27,7 +27,6 @@ class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent long long m_nCreateTime; bool m_bConsole; void stopConsole(); - int m_nPid; int m_nNesting; void addRecording(); @@ -48,10 +47,10 @@ public: * Similar to the DEBUG macro in sal/log.hxx, don't forget to remove these lines before * committing. */ - ProfileZone(const char* sName, bool bConsole = false) - : NamedEvent(sName) + ProfileZone(const char* sName, bool bConsole = false, + const std::map<OUString, OUString>& args = std::map<OUString, OUString>()) + : NamedEvent(sName, args) , m_bConsole(bConsole) - , m_nPid(-1) , m_nNesting(-1) { if (s_bRecording || m_bConsole) @@ -61,8 +60,6 @@ public: m_nCreateTime = static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec / 1000; - m_nPid = getPid(); - m_nNesting = s_nNesting++; } else diff --git a/include/comphelper/traceevent.hxx b/include/comphelper/traceevent.hxx index 44805d21a6df..73c87e3767ac 100644 --- a/include/comphelper/traceevent.hxx +++ b/include/comphelper/traceevent.hxx @@ -14,6 +14,7 @@ #include <algorithm> #include <atomic> +#include <map> #include <memory> #include <vector> @@ -22,6 +23,7 @@ #include <osl/time.h> #include <com/sun/star/uno/Sequence.h> #include <comphelper/comphelperdllapi.h> +#include <rtl/ustrbuf.hxx> #include <rtl/ustring.hxx> // implementation of XToolkitExperimental profiling API @@ -30,6 +32,17 @@ namespace comphelper { class COMPHELPER_DLLPUBLIC TraceEvent { +private: + static int getPid() + { + oslProcessInfo aProcessInfo; + aProcessInfo.Size = sizeof(oslProcessInfo); + if (osl_getProcessInfo(nullptr, osl_Process_IDENTIFIER, &aProcessInfo) + == osl_Process_E_None) + return aProcessInfo.Ident; + return -1; + } + protected: static std::atomic<bool> s_bRecording; // true during recording @@ -42,18 +55,42 @@ protected: return static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec / 1000; } - static int getPid() + static OUString createArgsString(const std::map<OUString, OUString>& args) + { + if (args.size() == 0) + return ""; + + OUStringBuffer sResult; + sResult.append(",\"args\":{"); + bool first = true; + for (auto& i : args) + { + if (!first) + sResult.append(','); + sResult.append('"'); + sResult.append(i.first); + sResult.append("\",\""); + sResult.append(i.second); + sResult.append('"'); + first = false; + } + sResult.append('}'); + + return sResult.makeStringAndClear(); + } + + const int m_nPid; + const OUString m_sArgs; + + TraceEvent(std::map<OUString, OUString> args) + : m_nPid(getPid()) + , m_sArgs(createArgsString(args)) { - oslProcessInfo aProcessInfo; - aProcessInfo.Size = sizeof(oslProcessInfo); - if (osl_getProcessInfo(nullptr, osl_Process_IDENTIFIER, &aProcessInfo) - == osl_Process_E_None) - return aProcessInfo.Ident; - return -1; } public: - static void addInstantEvent(const char* sName); + static void addInstantEvent(const char* sName, const std::map<OUString, OUString>& args + = std::map<OUString, OUString>()); static void startRecording(); static void stopRecording(); @@ -68,8 +105,10 @@ class COMPHELPER_DLLPUBLIC NamedEvent : public TraceEvent protected: const char* m_sName; - NamedEvent(const char* sName) - : m_sName(sName ? sName : "(null)") + NamedEvent(const char* sName, + const std::map<OUString, OUString>& args = std::map<OUString, OUString>()) + : TraceEvent(args) + , m_sName(sName ? sName : "(null)") { } }; @@ -99,13 +138,12 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, { static int s_nIdCounter; int m_nId; - int m_nPid; std::vector<std::shared_ptr<AsyncEvent>> m_aChildren; std::weak_ptr<AsyncEvent> m_pParent; bool m_bBeginRecorded; - AsyncEvent(const char* sName, int nId) - : NamedEvent(sName) + AsyncEvent(const char* sName, int nId, const std::map<OUString, OUString>& args) + : NamedEvent(sName, args) , m_nId(nId) , m_bBeginRecorded(false) { @@ -113,8 +151,6 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, { long long nNow = getNow(); - m_nPid = getPid(); - // Generate a "Begin " (type b) event TraceEvent::addRecording("{" "\"name\":\"" @@ -123,7 +159,7 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, "\"ph\":\"b\"" "," "\"id\":" - + OUString::number(m_nId) + + OUString::number(m_nId) + m_sArgs + "," "\"ts\":" + OUString::number(nNow) @@ -160,7 +196,7 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, "\"ph\":\"e\"" "," "\"id\":" - + OUString::number(m_nId) + + OUString::number(m_nId) + m_sArgs + "," "\"ts\":" + OUString::number(nNow) @@ -174,21 +210,23 @@ class COMPHELPER_DLLPUBLIC AsyncEvent : public NamedEvent, } public: - AsyncEvent(const char* sName) - : AsyncEvent(sName, s_nIdCounter++) + AsyncEvent(const char* sName, + const std::map<OUString, OUString>& args = std::map<OUString, OUString>()) + : AsyncEvent(sName, s_nIdCounter++, args) { } ~AsyncEvent() { generateEnd(); } - static std::weak_ptr<AsyncEvent> createWithParent(const char* sName, - std::shared_ptr<AsyncEvent> pParent) + static std::weak_ptr<AsyncEvent> + createWithParent(const char* sName, std::shared_ptr<AsyncEvent> pParent, + const std::map<OUString, OUString>& args = std::map<OUString, OUString>()) { std::shared_ptr<AsyncEvent> pResult; if (s_bRecording && pParent->m_bBeginRecorded) { - pResult.reset(new AsyncEvent(sName, pParent->m_nId)); + pResult.reset(new AsyncEvent(sName, pParent->m_nId, args)); pParent->m_aChildren.push_back(pResult); pResult->m_pParent = pParent; } |