named_timer.h Source File

CPP API: named_timer.h Source File
named_timer.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Rene Schmieding
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_TIMER_NAMED_TIMER_H
21 #define MIO_TIMER_NAMED_TIMER_H
22 
23 #include "memilio/utils/mioomp.h"
27 
28 #include <string>
29 
30 namespace mio
31 {
32 namespace timing
33 {
34 
36 template <StringLiteral Name, StringLiteral Scope = "">
37 class NamedTimer : public BasicTimer
38 {
39 public:
41  NamedTimer(NamedTimer&) = delete;
42  NamedTimer(NamedTimer&&) = delete;
43 
45  static std::string name()
46  {
47  return std::string(Name);
48  }
49 
51  static std::string scope()
52  {
53  return std::string(Scope);
54  }
55 
64  {
65  // create and return a timer
66  // the constructor is only called the first time this function is used (for each thread)
67  thread_local static NamedTimer t;
68  return t;
69  }
70 
71 private:
79  {
81  }
82 };
83 
84 } // namespace timing
85 } // namespace mio
86 
87 #endif // MIO_TIMER_NAMED_TIMER_H
A minimal timer class.
Definition: basic_timer.h:36
Thread local singleton timer, identified by its name. Best used via AutoTimer.
Definition: named_timer.h:38
static std::string name()
Get the timer's name as a runtime string.
Definition: named_timer.h:45
static std::string scope()
Get the timer's scope as a runtime string.
Definition: named_timer.h:51
NamedTimer(NamedTimer &)=delete
Do not allow construction other than through get_instance and the default constructor.
NamedTimer(NamedTimer &&)=delete
NamedTimer()
Create a NamedTimer and register it.
Definition: named_timer.h:78
static NamedTimer & get_instance()
Get a thread local instance of this timer.
Definition: named_timer.h:63
void add_timer(TimerRegistration &&registration)
Add a new timer to the TimerRegistrar.
Definition: timer_registrar.h:72
static TimerRegistrar & get_instance()
Access the TimerRegistrar.
Definition: timer_registrar.h:56
int get_thread_id()
Get an id for the current OpenMP thread. When OpenMP is disabled, this is always 0.
Definition: mioomp.cpp:27
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
StringLiteral(const char(&string)[Size]) -> StringLiteral< Size - 1 >