diff options
-rw-r--r-- | comphelper/source/misc/profilezone.cxx | 9 | ||||
-rw-r--r-- | include/comphelper/profilezone.hxx | 36 | ||||
-rw-r--r-- | writerfilter/source/filter/RtfFilter.cxx | 4 |
3 files changed, 39 insertions, 10 deletions
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&) { |