Changeset 3f06bb for src/CodePatterns


Ignore:
Timestamp:
Mar 2, 2013, 10:45:46 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
b9273a
Parents:
8f60da
git-author:
Frederik Heber <heber@…> (03/01/13 13:41:05)
git-committer:
Frederik Heber <heber@…> (03/02/13 22:45:46)
Message:

Enhanced Chronos for more accurate timekeeping.

  • Chronos is now safe to use w.r.t. recursive function calls.
  • Chronos now gets const ref of token name in each function.
  • TESTFIX: dummyTest() now checks on recursive function.
  • Chronos now offers its internal timekeeping via const ref to outside.
  • Chronos also now has up to nanoseconds precision when either time.h or sys/time.h is present.
  • librt required from clock_gettime().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodePatterns/Chronos.hpp

    r8f60da r3f06bb  
    1616#include <iosfwd>
    1717#include <map>
     18#include <string>
    1819
    1920#include "CodePatterns/Singleton.hpp"
     
    2930  friend std::ostream& operator<<(std::ostream &ost, const Chronos &_time);
    3031public :
     32  //!> typedef for the map storing times per token
     33  typedef std::map<const std::string, double> TimekeepingMap;
    3134
    3235  /** Returns current kept time of function \a _name.
     
    3538   * @return current amount of time passed for this function, 0 if unknown, -1 if currently running
    3639   */
    37   double getTime(const std::string _name) const;
     40  double getTime(const std::string &_name) const;
    3841
    3942  /** Resets time counter for this function \a _name to zero.
     
    4144   * @param _name name of function
    4245   */
    43   void resetTime(const std::string _name);
     46  void resetTime(const std::string &_name);
    4447
    4548  /** Starts Timing for this function \a _name.
     
    4750   * @param _name name of function
    4851   */
    49   void startTiming(const std::string _name);
     52  void startTiming(const std::string &_name);
    5053
    5154  /** Finishes Timing for this function \a _name.
     
    5356   * @param _name name of function
    5457   */
    55   void endTiming(const std::string _name);
     58  void endTiming(const std::string &_name);
     59
     60  /** Returns const reference to time keeping map.
     61   *
     62   * \return const ref to timekeeping map
     63   */
     64  const TimekeepingMap& getTimekeepingMap() const;
    5665
    5766  /** Sums up total time accounted for.
     
    8695  double getCurrentTime() const;
    8796
     97  //!> typedef for the map storing status of time keeping per token
     98  typedef std::map<const std::string, double> TimerMap;
    8899
    89   typedef std::map<const std::string, double> TimekeepingMap;
    90   typedef std::map<const std::string, double> TimerStatusMap;
     100  //!> typedef for the map storing number of recursive calls to this token
     101  typedef std::map<const std::string, size_t> TimerRecursionMap;
    91102
     103  //!> map storing times per token
    92104  TimekeepingMap AccountedTime;
    93   TimerStatusMap TimeRunning;
     105  //!> map storing time keeping status per token
     106  TimerMap StartingTime;
     107  //!> map storing level of recursion per token
     108  TimerRecursionMap RecursionMap;
     109
     110#ifdef HAVE_TIME_H
     111  timespec basetime;
     112#else
     113#ifdef HAVE_SYS_TIME_H
     114  struct timezone basetime;
     115#else
     116#ifdef HAVE_SYS_TIMES_H
     117  struct tms *basetime;
     118#endif
     119#endif
     120#endif
    94121};
    95122
     
    102129std::ostream& operator<<(std::ostream &ost, const Chronos &_time);
    103130
     131// inline functions
     132
     133inline
     134const Chronos::TimekeepingMap& Chronos::getTimekeepingMap() const
     135{
     136  return AccountedTime;
     137}
     138
    104139#endif /* CHRONOS_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.