profilingTrigger.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2009-2016 Bernhard Gschaider
9  Copyright (C) 2016-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::profilingTrigger
29 
30 Description
31  Triggers for starting/stopping code profiling.
32 
33 SourceFiles
34  profilingTrigger.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_profilingTrigger_H
39 #define Foam_profilingTrigger_H
40 
41 #include "word.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward Declarations
49 class profilingInformation;
50 
51 /*---------------------------------------------------------------------------*\
52  Class profilingTrigger Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class profilingTrigger
56 {
57  // Private Data Members
58 
59  //- The profiling information
61 
62 public:
63 
64  // Generated Methods
65 
66  //- No copy construct
67  profilingTrigger(const profilingTrigger&) = delete;
68 
69  //- No copy assignment
70  void operator=(const profilingTrigger&) = delete;
71 
72 
73  // Constructors
74 
75  //- Default construct, no profiling trigger
77 
78  //- Construct profiling with given description.
79  // Descriptions beginning with 'application::' are reserved for
80  // internal use.
81  explicit profilingTrigger(const char* name);
82 
83  //- Construct profiling with given description.
84  // Descriptions beginning with 'application::' are reserved for
85  // internal use.
86  explicit profilingTrigger(const std::string& name);
87 
88 
89  //- Destructor
91 
92 
93  // Member Functions
94 
95  //- True if the triggered profiling is active
96  bool running() const noexcept;
97 
98  //- Stop triggered profiling
99  void stop();
100 };
101 
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 } // End namespace Foam
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 // Macros
110 
111 //- Define profiling trigger with specified name and description string
112 // \sa endProfiling
113 #define addProfiling(Name,Descr) \
114  ::Foam::profilingTrigger profilingTriggerFor##Name(Descr)
115 
116 //- Remove profiling with specified name
117 // \sa addProfiling
118 #define endProfiling(Name) profilingTriggerFor##Name.stop()
119 
120 //- Define profiling trigger with specified name and description
121 //- corresponding to the compiler-defined function name string
122 // \sa addProfiling
123 #ifdef __GNUC__
124 #define addProfilingInFunction(Name) addProfiling(Name, __PRETTY_FUNCTION__)
125 #else
126 #define addProfilingInFunction(Name) addProfiling(Name, __func__)
127 #endif
128 
129 
130 #endif
132 // ************************************************************************* //
bool running() const noexcept
True if the triggered profiling is active.
~profilingTrigger()
Destructor.
Triggers for starting/stopping code profiling.
void operator=(const profilingTrigger &)=delete
No copy assignment.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void stop()
Stop triggered profiling.
const direction noexcept
Definition: Scalar.H:258
profilingTrigger() noexcept
Default construct, no profiling trigger.
Code profiling information in terms of time spent, number of calls etc.
Namespace for OpenFOAM.