walltimer.h

Go to the documentation of this file.
00001 /*
00002  *  This file is part of libcxxsupport.
00003  *
00004  *  libcxxsupport is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  libcxxsupport is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with libcxxsupport; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 /*
00020  *  libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik
00021  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00022  *  (DLR).
00023  */
00024 
00025 /*! \file walltimer.h
00026  *  Functionality related to wall-clock timers
00027  *
00028  *  Copyright (C) 2010, 2011 Max-Planck-Society
00029  *  \author Martin Reinecke
00030  */
00031 
00032 #ifndef PLANCK_WALLTIMER_H
00033 #define PLANCK_WALLTIMER_H
00034 
00035 #include <string>
00036 #include <map>
00037 #include <vector>
00038 
00039 class wallTimer
00040   {
00041   private:
00042     double t_acc, t_started;
00043     bool running;
00044 
00045   public:
00046     wallTimer() : t_acc(0.), t_started(0.), running(false) {}
00047     void start(double wtime_now)
00048       { if (!running) { t_started=wtime_now; running=true; } }
00049     void start();
00050     void stop(double wtime_now)
00051       { if (running) { t_acc+=wtime_now-t_started; running=false; } }
00052     void stop();
00053     void reset() { t_acc=t_started=0.; running=false;}
00054     double acc(double wtime_now) const
00055       { return running ? t_acc+wtime_now-t_started : t_acc; }
00056     double acc() const;
00057   };
00058 
00059 class wallTimerSet
00060   {
00061   public:
00062     typedef std::map<std::string,int> maptype;
00063 
00064   private:
00065     maptype lut;
00066     std::vector<wallTimer> timer;
00067 
00068   public:
00069     int getIndex(const std::string &name);
00070     void start(int index);
00071     void stop(int index);
00072     void stopstart(int index1, int index2);
00073     void reset(int index);
00074     double acc(int index);
00075     void start(const std::string &name);
00076     void stop(const std::string &name);
00077     void stopstart(const std::string &name1, const std::string &name2);
00078     void reset(const std::string &name);
00079     double acc(const std::string &name);
00080 
00081     void report() const;
00082 
00083     const maptype &table() const { return lut; }
00084   };
00085 
00086 extern wallTimerSet wallTimers;
00087 
00088 void tstack_push(const std::string &name);
00089 void tstack_pop(const std::string &name);
00090 void tstack_pop();
00091 void tstack_replace(const std::string &name1, const std::string &name2);
00092 void tstack_replace(const std::string &name);
00093 void tstack_report(const std::string &stem);
00094 
00095 #endif

Generated on Thu Oct 8 14:48:51 2015 for LevelS C++ support library