| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
|---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*
|
|---|
| 9 | * Chronos.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: Mar 14, 2011
|
|---|
| 12 | * Author: heber
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | #include "MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include <iostream>
|
|---|
| 23 |
|
|---|
| 24 | #include "Chronos.hpp"
|
|---|
| 25 |
|
|---|
| 26 | #include "Singleton_impl.hpp"
|
|---|
| 27 |
|
|---|
| 28 | Chronos::Chronos()
|
|---|
| 29 | {}
|
|---|
| 30 |
|
|---|
| 31 | Chronos::~Chronos()
|
|---|
| 32 | {}
|
|---|
| 33 |
|
|---|
| 34 | int Chronos::getTime(const std::string _name) const
|
|---|
| 35 | {
|
|---|
| 36 | // only those functions have a time that have run already
|
|---|
| 37 | if (IsTimeRunning.count(_name)) {
|
|---|
| 38 | // return -1 if function is currently running
|
|---|
| 39 | if (!IsTimeRunning.count(_name))
|
|---|
| 40 | return AccountedTime.at(_name);
|
|---|
| 41 | else
|
|---|
| 42 | return -1;
|
|---|
| 43 | }
|
|---|
| 44 | return 0;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void Chronos::resetTime(const std::string _name)
|
|---|
| 48 | {
|
|---|
| 49 | if (IsTimeRunning.count(_name)) {
|
|---|
| 50 | AccountedTime[_name] = 0;
|
|---|
| 51 | }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | void Chronos::startTiming(const std::string _name)
|
|---|
| 55 | {
|
|---|
| 56 | // start time keeping
|
|---|
| 57 | IsTimeRunning[_name] = true;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | void Chronos::endTiming(const std::string _name)
|
|---|
| 61 | {
|
|---|
| 62 | // finish time keeping if present
|
|---|
| 63 | ASSERT(IsTimeRunning.count(_name), "Chronos::endTiming() - no timer under "+_name+" running.");
|
|---|
| 64 | IsTimeRunning[_name] = false;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | int Chronos::SumUpTotalTime() const
|
|---|
| 68 | {
|
|---|
| 69 | int sum = 0;
|
|---|
| 70 | for (TimekeepingMap::const_iterator iter = AccountedTime.begin();
|
|---|
| 71 | iter != AccountedTime.end();
|
|---|
| 72 | ++iter) {
|
|---|
| 73 | sum += iter->second;
|
|---|
| 74 | }
|
|---|
| 75 | return sum;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | size_t Chronos::SumUpTotalFunctions() const
|
|---|
| 79 | {
|
|---|
| 80 | return IsTimeRunning.size();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | std::ostream& operator<<(std::ostream &ost, const Chronos &_time)
|
|---|
| 84 | {
|
|---|
| 85 | int sum = _time.SumUpTotalTime();
|
|---|
| 86 | ost << "Total time passed: " << sum << std::endl;
|
|---|
| 87 | ost << "Total functions: " << _time.SumUpTotalFunctions() << std::endl;
|
|---|
| 88 |
|
|---|
| 89 | return ost;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | CONSTRUCT_SINGLETON(Chronos)
|
|---|