LibreOffice Module comphelper (master)  1
profilezone.hxx
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 
10 #ifndef INCLUDED_COMPHELPER_PROFILEZONE_HXX
11 #define INCLUDED_COMPHELPER_PROFILEZONE_HXX
12 
13 #include <sal/config.h>
14 
15 #include <atomic>
16 
17 #include <com/sun/star/uno/Sequence.h>
19 #include <rtl/ustring.hxx>
20 
21 // implementation of XToolkitExperimental profiling API
22 
23 namespace comphelper
24 {
25 
26 namespace ProfileRecording
27 {
28 
29 COMPHELPER_DLLPUBLIC void startRecording(bool bRecording);
30 
31 COMPHELPER_DLLPUBLIC long long addRecording(const char * aProfileId, long long aCreateTime);
32 
33 COMPHELPER_DLLPUBLIC css::uno::Sequence<OUString> getRecordingAndClear();
34 
35 } // namespace ProfileRecording
36 
37 class COMPHELPER_DLLPUBLIC ProfileZone
38 {
39 private:
40  const char * m_sProfileId;
41  long long m_aCreateTime;
42  bool m_bConsole;
43  void startConsole();
44  void stopConsole();
45 public:
46  static std::atomic<bool> g_bRecording; // true during recording
47 
63  ProfileZone(const char *sProfileId, bool bConsole = false)
64  : m_sProfileId(sProfileId),
65  m_aCreateTime(g_bRecording ? ProfileRecording::addRecording(sProfileId, 0) : 0),
66  m_bConsole(bConsole)
67  {
68  if (m_bConsole)
69  {
70  startConsole();
71  }
72  }
74  {
75  if (g_bRecording)
76  ProfileRecording::addRecording(m_sProfileId, m_aCreateTime);
77  if (m_bConsole)
78  {
79  stopConsole();
80  }
81  }
82 };
83 
84 } // namespace comphelper
85 
86 
87 #endif // INCLUDED_COMPHELPER_PROFILEZONE_HXX
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Sequence< OUString > getRecordingAndClear()
Definition: profilezone.cxx:83
ProfileZone(const char *sProfileId, bool bConsole=false)
Starts measuring the cost of a C++ scope.
Definition: profilezone.hxx:63
const char * m_sProfileId
Definition: profilezone.hxx:40
long long addRecording(const char *aProfileId, long long aCreateTime)
Definition: profilezone.cxx:47
void startRecording(bool bStartRecording)
Definition: profilezone.cxx:34
static std::atomic< bool > g_bRecording
Definition: profilezone.hxx:46
#define COMPHELPER_DLLPUBLIC