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 <sal/log.hxx>
16 
18 
19 // implementation of XToolkitExperimental profiling API
20 
21 namespace comphelper
22 {
23 class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent
24 {
25  static int s_nNesting; // level of nested zones.
26 
27  long long m_nCreateTime;
28  bool m_bConsole;
29  void stopConsole();
30  int m_nPid;
32 
33  void addRecording();
34 
35 public:
51  ProfileZone(const char* sName, bool bConsole = false)
52  : NamedEvent(sName)
53  , m_bConsole(bConsole)
54  , m_nPid(-1)
55  , m_nNesting(-1)
56  {
57  if (s_bRecording || m_bConsole)
58  {
59  TimeValue systemTime;
60  osl_getSystemTime(&systemTime);
61  m_nCreateTime
62  = static_cast<long long>(systemTime.Seconds) * 1000000 + systemTime.Nanosec / 1000;
63 
64  m_nPid = getPid();
65 
66  m_nNesting = s_nNesting++;
67  }
68  else
69  m_nCreateTime = 0;
70  }
71 
73  {
74  if (m_nCreateTime > 0)
75  {
76  s_nNesting--;
77 
78  if (m_nNesting != s_nNesting)
79  {
80  SAL_WARN("comphelper.traceevent", "Incorrect ProfileZone nesting for " << m_sName);
81  }
82  else
83  {
84  if (s_bRecording)
85  addRecording();
86  }
87 
88  if (m_bConsole)
89  stopConsole();
90  }
91  }
92 
93  ProfileZone(const ProfileZone&) = delete;
94  void operator=(const ProfileZone&) = delete;
95 };
96 
97 } // namespace comphelper
98 
99 #endif // INCLUDED_COMPHELPER_PROFILEZONE_HXX
100 
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString m_sName
ProfileZone(const char *sName, bool bConsole=false)
Starts measuring the cost of a C++ scope.
Definition: profilezone.hxx:51
#define COMPHELPER_DLLPUBLIC
#define SAL_WARN(area, stream)