forked from aymara/lima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraceUtils.cpp
105 lines (87 loc) · 3.6 KB
/
traceUtils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright 2002-2013 CEA LIST
This file is part of LIMA.
LIMA is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LIMA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with LIMA. If not, see <http://www.gnu.org/licenses/>
*/
/************************************************************************
*
* @file traceUtils.cpp
* @author Besancon Romaric ([email protected])
* @date Fri Mar 5 2004
* @version $Id: traceUtils.cpp,v 1.3 2005/10/20 11:37:31 gael Exp $
* copyright Copyright (C) 2004-2012 by CEA LIST
*
***********************************************************************/
#include "traceUtils.h"
#include <QDateTime>
namespace Lima {
//**********************************************************************
//initialization of static members
//**********************************************************************
// uint64_t TimeUtils::currentTime={0,0};
std::map<std::string , std::pair<uint64_t,uint64_t> > TimeUtils::m_cumulatedTime =
std::map<std::string , std::pair<uint64_t,uint64_t> >();
QMutex TimeUtils::m_mutex;
//**********************************************************************
// member functions
//**********************************************************************
uint64_t TimeUtils::getCurrentTime() {
return QDateTime::currentMSecsSinceEpoch();
}
void TimeUtils::updateCurrentTime( const std::string& taskCategory ) {
QMutexLocker locker(&m_mutex);
m_cumulatedTime[taskCategory].first = QDateTime::currentMSecsSinceEpoch();
}
// void TimeUtils::updateCurrentTime() {
// boost::mutex::scoped_lock(m_mutex);
// gettimeofday(¤tTime,0);
// }
void TimeUtils::setCurrentTime(uint64_t time, const std::string& taskCategory) {
QMutexLocker locker(&m_mutex);
m_cumulatedTime[taskCategory].first=time;
}
uint64_t TimeUtils::diffTime(const uint64_t& begin,
const uint64_t& end) {
return end - begin;
}
uint64_t TimeUtils::elapsedTime(const std::string& taskCategory) {
uint64_t newTime = QDateTime::currentMSecsSinceEpoch();
uint64_t delta = diffTime(m_cumulatedTime[taskCategory].first,newTime);
m_cumulatedTime[taskCategory].second += delta;
m_cumulatedTime[taskCategory].first = newTime;
return delta;
}
/**
* log the number of microseconds since last UpdateCurrentTime
*/
void TimeUtils::logElapsedTime(const std::string& mess,
const std::string& taskCategory) {
TIMELOGINIT;
LINFO << mess << "(" << taskCategory << "): " << TimeUtils::elapsedTime(taskCategory) << " ms";
}
/**
* log the number of microseconds since last UpdateCurrentTime
*/
void TimeUtils::logCumulatedTime(const std::string& mess,
const std::string& taskCategory) {
TIMELOGINIT;
LINFO << mess << ": " << m_cumulatedTime[taskCategory].second << " ms";
}
void TimeUtils::logAllCumulatedTime(const std::string& mess) {
TIMELOGINIT;
LINFO << mess << ": ";
for( std::map<std::string , std::pair<uint64_t,uint64_t> >::const_iterator it = m_cumulatedTime.begin() ;
it != m_cumulatedTime.end() ; it++ ) {
LINFO << it->first << ":" << it->second.second << " ms" ;
}
}
} // end namespace