[DEBUG] log in time

This commit is contained in:
Edouard DUPIN 2015-03-03 21:28:07 +01:00
parent cae4fd92b9
commit d570c54136
2 changed files with 62 additions and 74 deletions

View File

@ -224,62 +224,52 @@ static std::map<uint32_t, std::string>& getThreadList() {
}
std::string etk::log::getThreadName() {
#if __CPP_VERSION__ >= 2011
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadID();
std::string out;
static std11::mutex g_lock;
g_lock.lock();
auto it = list.find(threadID);
if (it != list.end()) {
out = it->second;
}
g_lock.unlock();
return out;
#else
return "";
#endif
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadID();
std::string out;
static std11::mutex g_lock;
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it != list.end()) {
out = it->second;
}
g_lock.unlock();
return out;
}
void etk::log::setThreadName(const std::string& _name) {
#if __CPP_VERSION__ >= 2011
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadID();
static std11::mutex g_lock;
g_lock.lock();
auto it = list.find(threadID);
if (it == list.end()) {
list.insert(std::pair<uint32_t, std::string>(threadID,_name));
} else {
it->second = _name;
}
g_lock.unlock();
#endif
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadID();
static std11::mutex g_lock;
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it == list.end()) {
list.insert(std::pair<uint32_t, std::string>(threadID,_name));
} else {
it->second = _name;
}
g_lock.unlock();
}
uint32_t etk::log::getThreadID() {
#if __CPP_VERSION__ >= 2011
uint32_t out = 0;
std::thread::id this_id = std::this_thread::get_id();
uint64_t iddd = std::hash<std::thread::id>()(this_id);
static std11::mutex g_lock;
g_lock.lock();
static std::map<uint64_t, uint32_t> g_list;
auto it = g_list.find(iddd);
if (it == g_list.end()) {
// attribute new ID :
static uint32_t tmpId = 0;
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
out = tmpId;
tmpId++;
} else {
out = it->second;
}
g_lock.unlock();
return out;
#else
return 0;
#endif
uint32_t out = 0;
std11::thread::id this_id = std11::this_thread::get_id();
uint64_t iddd = std11::hash<std11::thread::id>()(this_id);
static std11::mutex g_lock;
g_lock.lock();
static std::map<uint64_t, uint32_t> g_list;
std::map<uint64_t, uint32_t>::iterator it = g_list.find(iddd);
if (it == g_list.end()) {
// attribute new ID :
static uint32_t tmpId = 0;
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
out = tmpId;
tmpId++;
} else {
out = it->second;
}
g_lock.unlock();
return out;
}
static void getDisplayTime(char* data) {
@ -403,32 +393,30 @@ void etk::log::logChar(int32_t _id, int32_t _level, int32_t _ligne, const char*
*pointer++ = ' ';
*pointer = '\0';
}
#if __CPP_VERSION__ >= 2011
if(getThreadId() == true) {
// display thread ID
uint32_t iddd = etk::log::getThreadID();
sprintf(pointer, "%3d", iddd);
pointer = handle+strlen(handle);
*pointer++ = ' ';
*pointer++ = '|';
if(getThreadId() == true) {
// display thread ID
uint32_t iddd = etk::log::getThreadID();
sprintf(pointer, "%3d", iddd);
pointer = handle+strlen(handle);
*pointer++ = ' ';
*pointer++ = '|';
*pointer++ = ' ';
*pointer = '\0';
}
if(getThreadNameEnable() == true) {
// display thread ID
std::string name = etk::log::getThreadName();
int32_t len = strlen(handle);
snprintf(pointer, 20, "%s", name.c_str());
pointer = handle+strlen(handle);
while (strlen(handle) - len < 20) {
*pointer++ = ' ';
*pointer = '\0';
}
if(getThreadNameEnable() == true) {
// display thread ID
std::string name = etk::log::getThreadName();
int32_t len = strlen(handle);
snprintf(pointer, 20, "%s", name.c_str());
pointer = handle+strlen(handle);
while (strlen(handle) - len < 20) {
*pointer++ = ' ';
*pointer = '\0';
}
*pointer++ = '|';
*pointer++ = ' ';
*pointer = '\0';
}
#endif
*pointer++ = '|';
*pointer++ = ' ';
*pointer = '\0';
}
if(getLine() == true) {
if (_ligne >= 0) {
sprintf(pointer, "(l=%5d)", _ligne);

View File

@ -1392,7 +1392,7 @@ namespace std {
int32_t hour = (totalSecond/3600)%24;
int32_t day = (totalSecond/(24*3600))%365;
int32_t year = totalSecond/(24*3600*365);
_os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns";
_os << year << "y " << day << "d " << hour << "h" << minute << ":"<< second << "s " << millisecond << "ms " << microsecond << "µs " << nanosecond << "ns";
return _os;
}
}