LevelS C++ support library  3.83
walltimer.h
Go to the documentation of this file.
1 /*
2  * This file is part of libcxxsupport.
3  *
4  * libcxxsupport is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * libcxxsupport is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with libcxxsupport; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
21  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
22  * (DLR).
23  */
24 
25 /*! \file walltimer.h
26  * Functionality related to wall-clock timers
27  *
28  * Copyright (C) 2010, 2011 Max-Planck-Society
29  * \author Martin Reinecke
30  */
31 
32 #ifndef PLANCK_WALLTIMER_H
33 #define PLANCK_WALLTIMER_H
34 
35 #include <string>
36 #include <map>
37 #include <vector>
38 
39 class wallTimer
40  {
41  private:
42  double t_acc, t_started;
43  bool running;
44 
45  public:
46  wallTimer() : t_acc(0.), t_started(0.), running(false) {}
47  void start(double wtime_now)
48  { if (!running) { t_started=wtime_now; running=true; } }
49  void start();
50  void stop(double wtime_now)
51  { if (running) { t_acc+=wtime_now-t_started; running=false; } }
52  void stop();
53  void reset() { t_acc=t_started=0.; running=false;}
54  double acc(double wtime_now) const
55  { return running ? t_acc+wtime_now-t_started : t_acc; }
56  double acc() const;
57  };
58 
59 class wallTimerSet
60  {
61  public:
62  typedef std::map<std::string,int> maptype;
63 
64  private:
65  maptype lut;
66  std::vector<wallTimer> timer;
67 
68  public:
69  int getIndex(const std::string &name);
70  void start(int index);
71  void stop(int index);
72  void stopstart(int index1, int index2);
73  void reset(int index);
74  double acc(int index);
75  void start(const std::string &name);
76  void stop(const std::string &name);
77  void stopstart(const std::string &name1, const std::string &name2);
78  void reset(const std::string &name);
79  double acc(const std::string &name);
80 
81  void report() const;
82 
83  const maptype &table() const { return lut; }
84  };
85 
86 extern wallTimerSet wallTimers;
87 
88 void tstack_push(const std::string &name);
89 void tstack_pop(const std::string &name);
90 void tstack_pop();
91 void tstack_replace(const std::string &name1, const std::string &name2);
92 void tstack_replace(const std::string &name);
93 void tstack_report(const std::string &stem);
94 
95 #endif

Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library