// CpuTimerTuple.hpp // Maintains a clock and series of subclocks which are reset after every // event. The call start(int event) starte and event and stop() ends the // event. Subclocks only run when started. They may be started and stopped // with alternating calls to start(name) and stop(name). #ifndef CpuTimerTuple_H #define CpuTimerTuple_H #include #include "timekeep/CpuTimer.hpp" #include "Tuple.h" class CpuTimerTuple { private: // typedefs typedef std::map > TimerMap; typedef std::map > FlagMap; typedef std::map > TimeMap; private: // attributes // The time. CpuTimer _timer; // The tuple. Tuple& _tup; // Flag indicating the clock has // The current event. int _event; // Flag indicating the clock has been started. bool _is_running; // Map of subtimers indexed by name. TimerMap _timers; // Map of flags indicating whether each timer is running. FlagMap _runflags; // Map of total times for the event. TimeMap _times; public: // non-const methods // Constructor CpuTimerTuple(std::string tuple_name); // Destructor ~CpuTimerTuple(); // Register a subclock. // The new clock is zeroed and stopped. int add_subclock(std::string name); // Add an entry. // Start the clock for an event. // Returns nonzero if clock is aready started but still resets. int start(int event); // Stop the clock and record the time for the current event. // All subclocks are stopped. // Does nothing and returns nonzero if clock is not running. int stop(); // Start one of the subclocks. // Nonzero if start is successful. // Clock must be stopped. int start(std::string name); // Stop one of the subclocks. // Nonzero if start is successful. // Subclock must be started. // The time is added to the sum. int stop(std::string name); public: // const methods // Return if the clock is running. bool is_running() const; // Return if a subclock is defined. bool is_defined(std::string name) const; // Return if a subclock is running. bool is_running(std::string name) const; }; #endif