source: src/CodePatterns/Chronos.hpp@ 084729c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 084729c was 084729c, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/CodePatterns/' content from commit c1e1041

git-subtree-dir: ThirdParty/CodePatterns
git-subtree-split: c1e10418c454f98be2f43d93167642b0008428fc

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[084729c]1/*
2 * Chronos.hpp
3 *
4 * Created on: Mar 14, 2011
5 * Author: heber
6 */
7
8#ifndef CHRONOS_HPP_
9#define CHRONOS_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <iosfwd>
17#include <map>
18#include <string>
19
20#include "CodePatterns/Singleton.hpp"
21
22class ChronosTest;
23
24class Chronos : public Singleton<Chronos>{
25 //!> Singleton pattern needs private access
26 friend class Singleton<Chronos>;
27 //!> unit tests needs access to private members
28 friend class ChronosTest;
29 //!> operator needs to access some internals
30 friend std::ostream& operator<<(std::ostream &ost, const Chronos &_time);
31public :
32 //!> typedef for the map storing times per token
33 typedef std::map<const std::string, double> TimekeepingMap;
34
35 /** Returns current kept time of function \a _name.
36 *
37 * @param _name name of function
38 * @return current amount of time passed for this function, 0 if unknown, -1 if currently running
39 */
40 double getTime(const std::string &_name) const;
41
42 /** Resets time counter for this function \a _name to zero.
43 *
44 * @param _name name of function
45 */
46 void resetTime(const std::string &_name);
47
48 /** Starts Timing for this function \a _name.
49 *
50 * @param _name name of function
51 */
52 void startTiming(const std::string &_name);
53
54 /** Finishes Timing for this function \a _name.
55 *
56 * @param _name name of function
57 */
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;
65
66 /** Sums up total time accounted for.
67 *
68 * @return total time in seconds
69 */
70 double SumUpTotalTime() const;
71
72 /** Sums up all functions accounted.
73 *
74 * @return number of functions
75 */
76 size_t SumUpTotalFunctions() const;
77
78protected:
79 /** Do not call this constructor directly, use getInstance() instead. */
80 Chronos();
81 /** Do not call this destructor directly, use purgeInstance() instead. */
82 ~Chronos();
83
84private:
85 /** Returns the current timer in seconds.
86 *
87 * This function is present to allow for changing of time measurements
88 * without the other functions noticing.
89 *
90 * \note We convert clock() by CLOCKS_PER_SEC.
91 * \note We convert struct tms::tms_utime by _SC_CLK_TCK via sysconf().
92 *
93 * @return current time in unit of seconds
94 */
95 double getCurrentTime() const;
96
97 typedef std::pair<size_t, size_t> sec_ncsec_t;
98
99 /** Returns the correct difference between split tuples (sec, nsec).
100 *
101 * \param _time1 first tuple
102 * \param _time2 second tuple
103 */
104 static
105 double calculateCorrectTimeDifference(
106 const sec_ncsec_t &_time1,
107 const sec_ncsec_t &_time2);
108
109 //!> typedef for the map storing status of time keeping per token
110 typedef std::map<const std::string, double> TimerMap;
111
112 //!> typedef for the map storing number of recursive calls to this token
113 typedef std::map<const std::string, size_t> TimerRecursionMap;
114
115 //!> map storing times per token
116 TimekeepingMap AccountedTime;
117 //!> map storing time keeping status per token
118 TimerMap StartingTime;
119 //!> map storing level of recursion per token
120 TimerRecursionMap RecursionMap;
121
122#ifdef HAVE_TIME_H
123 timespec basetime;
124#else
125#ifdef HAVE_SYS_TIME_H
126 struct timezone basetime;
127#else
128#ifdef HAVE_SYS_TIMES_H
129 struct tms *basetime;
130#endif
131#endif
132#endif
133};
134
135/** Output for Chronos.
136 *
137 * @param ost output stream
138 * @param _time Chronos to print
139 * @return reference to given output stream for concatenation
140 */
141std::ostream& operator<<(std::ostream &ost, const Chronos &_time);
142
143// inline functions
144
145inline
146const Chronos::TimekeepingMap& Chronos::getTimekeepingMap() const
147{
148 return AccountedTime;
149}
150
151#endif /* CHRONOS_HPP_ */
Note: See TracBrowser for help on using the repository browser.