/src/libreoffice/include/comphelper/profilezone.hxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
17 | | #include <comphelper/traceevent.hxx> |
18 | | |
19 | | // implementation of XToolkitExperimental profiling API |
20 | | |
21 | | namespace comphelper |
22 | | { |
23 | | class COMPHELPER_DLLPUBLIC ProfileZone : public NamedEvent |
24 | | { |
25 | | long long m_nCreateTime; |
26 | | int m_nNesting; |
27 | | |
28 | | void addRecording(); |
29 | | |
30 | | static void setNestingLevel(int nNestingLevel); |
31 | | static int getNestingLevel(); |
32 | | |
33 | | ProfileZone(const char* sName, const OUString& sArgs) |
34 | 810k | : NamedEvent(sName, sArgs) |
35 | 810k | , m_nNesting(-1) |
36 | 810k | { |
37 | 810k | if (s_bRecording) |
38 | 0 | { |
39 | 0 | m_nCreateTime = getNow(); |
40 | |
|
41 | 0 | m_nNesting = getNestingLevel(); |
42 | 0 | setNestingLevel(getNestingLevel() + 1); |
43 | 0 | } |
44 | 810k | else |
45 | 810k | m_nCreateTime = 0; |
46 | 810k | } |
47 | | |
48 | | public: |
49 | | /** |
50 | | * Starts measuring the cost of a C++ scope. |
51 | | * |
52 | | * Note that the char pointer is stored as such in the ProfileZone object and used in the |
53 | | * destructor, so be sure to pass a pointer that stays valid for the duration of the object's |
54 | | * lifetime. |
55 | | */ |
56 | | ProfileZone(const char* sName, const std::map<OUString, OUString>& aArgs) |
57 | | : ProfileZone(sName, createArgsString(aArgs)) |
58 | 0 | { |
59 | 0 | } |
60 | | |
61 | | ProfileZone(const char* sName) |
62 | 810k | : ProfileZone(sName, OUString()) |
63 | 810k | { |
64 | 810k | } |
65 | | |
66 | | ~ProfileZone() |
67 | 810k | { |
68 | 810k | if (m_nCreateTime > 0) |
69 | 0 | { |
70 | 0 | setNestingLevel(getNestingLevel() - 1); |
71 | |
|
72 | 0 | if (m_nNesting != getNestingLevel()) |
73 | 0 | { |
74 | 0 | SAL_WARN("comphelper.traceevent", "Incorrect ProfileZone nesting for " << m_sName); |
75 | 0 | } |
76 | 0 | else |
77 | 0 | { |
78 | 0 | if (s_bRecording) |
79 | 0 | addRecording(); |
80 | 0 | } |
81 | 0 | } |
82 | 810k | } |
83 | | |
84 | | ProfileZone(const ProfileZone&) = delete; |
85 | | void operator=(const ProfileZone&) = delete; |
86 | | }; |
87 | | |
88 | | } // namespace comphelper |
89 | | |
90 | | #endif // INCLUDED_COMPHELPER_PROFILEZONE_HXX |
91 | | |
92 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |