LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
traceUtils.cpp
Go to the documentation of this file.
1// Copyright 2002-2013 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6/************************************************************************
7 *
8 * @file traceUtils.cpp
9 * @author Besancon Romaric (besanconr@zoe.cea.fr)
10 * @date Fri Mar 5 2004
11 * @version $Id: traceUtils.cpp,v 1.3 2005/10/20 11:37:31 gael Exp $
12 * copyright Copyright (C) 2004-2012 by CEA LIST
13 *
14 ***********************************************************************/
15
16#include "traceUtils.h"
17#include <QDateTime>
18
19namespace Lima {
20
21//**********************************************************************
22//initialization of static members
23//**********************************************************************
24// uint64_t TimeUtils::currentTime={0,0};
25std::map<std::string , std::pair<uint64_t,uint64_t> > TimeUtils::m_cumulatedTime =
26 std::map<std::string , std::pair<uint64_t,uint64_t> >();
27QMutex TimeUtils::m_mutex;
28
29//**********************************************************************
30// member functions
31//**********************************************************************
33 return QDateTime::currentMSecsSinceEpoch();
34}
35
36void TimeUtils::updateCurrentTime( const std::string& taskCategory ) {
37 QMutexLocker locker(&m_mutex);
38 m_cumulatedTime[taskCategory].first = QDateTime::currentMSecsSinceEpoch();
39}
40
41// void TimeUtils::updateCurrentTime() {
42// boost::mutex::scoped_lock(m_mutex);
43// gettimeofday(&currentTime,0);
44// }
45
46void TimeUtils::setCurrentTime(uint64_t time, const std::string& taskCategory) {
47 QMutexLocker locker(&m_mutex);
48 m_cumulatedTime[taskCategory].first=time;
49}
50
51uint64_t TimeUtils::diffTime(const uint64_t& begin,
52 const uint64_t& end) {
53 return end - begin;
54}
55
56uint64_t TimeUtils::elapsedTime(const std::string& taskCategory) {
57 uint64_t newTime = QDateTime::currentMSecsSinceEpoch();
58 uint64_t delta = diffTime(m_cumulatedTime[taskCategory].first,newTime);
59 m_cumulatedTime[taskCategory].second += delta;
60 m_cumulatedTime[taskCategory].first = newTime;
61 return delta;
62}
63
67void TimeUtils::logElapsedTime(const std::string& mess,
68 const std::string& taskCategory) {
70 LINFO << mess << "(" << taskCategory << "): " << TimeUtils::elapsedTime(taskCategory) << " ms";
71}
72
76void TimeUtils::logCumulatedTime(const std::string& mess,
77 const std::string& taskCategory) {
79 LINFO << mess << ": " << m_cumulatedTime[taskCategory].second << " ms";
80}
81
82void TimeUtils::logAllCumulatedTime(const std::string& mess) {
84 LINFO << mess << ": ";
85 for( std::map<std::string , std::pair<uint64_t,uint64_t> >::const_iterator it = m_cumulatedTime.begin() ;
86 it != m_cumulatedTime.end() ; it++ ) {
87 LINFO << it->first << ":" << it->second.second << " ms" ;
88 }
89}
90
91
92} // end namespace
#define LINFO
Definition LimaCommon.h:158
static void setCurrentTime(uint64_t time, const std::string &taskCategory=std::string(""))
static void logAllCumulatedTime(const std::string &mess)
log the number of microseconds cumulated for all categories
static uint64_t diffTime(const uint64_t &begin, const uint64_t &end)
return the difference between two times in microseconds
static void logElapsedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds since last UpdateCurrentTime
static void updateCurrentTime(const std::string &taskCategory=std::string(""))
store current time for new elapsed time computation
static uint64_t elapsedTime(const std::string &taskCategory=std::string(""))
static uint64_t getCurrentTime()
get the current time (real current time, not last time stored)
static void logCumulatedTime(const std::string &mess, const std::string &taskCategory=std::string(""))
log the number of microseconds cumulated for the category sum of elapsed time between consecutive cal...
NAUTITIA.
#define TIMELOGINIT
Definition traceUtils.h:32