[DEBUG] log in time
This commit is contained in:
parent
cae4fd92b9
commit
d570c54136
134
etk/log.cpp
134
etk/log.cpp
@ -224,62 +224,52 @@ static std::map<uint32_t, std::string>& getThreadList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string etk::log::getThreadName() {
|
std::string etk::log::getThreadName() {
|
||||||
#if __CPP_VERSION__ >= 2011
|
std::map<uint32_t,std::string>& list = getThreadList();
|
||||||
std::map<uint32_t,std::string>& list = getThreadList();
|
uint32_t threadID = getThreadID();
|
||||||
uint32_t threadID = getThreadID();
|
std::string out;
|
||||||
std::string out;
|
static std11::mutex g_lock;
|
||||||
static std11::mutex g_lock;
|
g_lock.lock();
|
||||||
g_lock.lock();
|
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
|
||||||
auto it = list.find(threadID);
|
if (it != list.end()) {
|
||||||
if (it != list.end()) {
|
out = it->second;
|
||||||
out = it->second;
|
}
|
||||||
}
|
g_lock.unlock();
|
||||||
g_lock.unlock();
|
return out;
|
||||||
return out;
|
|
||||||
#else
|
|
||||||
return "";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void etk::log::setThreadName(const std::string& _name) {
|
void etk::log::setThreadName(const std::string& _name) {
|
||||||
#if __CPP_VERSION__ >= 2011
|
std::map<uint32_t,std::string>& list = getThreadList();
|
||||||
std::map<uint32_t,std::string>& list = getThreadList();
|
uint32_t threadID = getThreadID();
|
||||||
uint32_t threadID = getThreadID();
|
static std11::mutex g_lock;
|
||||||
static std11::mutex g_lock;
|
g_lock.lock();
|
||||||
g_lock.lock();
|
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
|
||||||
auto it = list.find(threadID);
|
if (it == list.end()) {
|
||||||
if (it == list.end()) {
|
list.insert(std::pair<uint32_t, std::string>(threadID,_name));
|
||||||
list.insert(std::pair<uint32_t, std::string>(threadID,_name));
|
} else {
|
||||||
} else {
|
it->second = _name;
|
||||||
it->second = _name;
|
}
|
||||||
}
|
g_lock.unlock();
|
||||||
g_lock.unlock();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t etk::log::getThreadID() {
|
uint32_t etk::log::getThreadID() {
|
||||||
#if __CPP_VERSION__ >= 2011
|
uint32_t out = 0;
|
||||||
uint32_t out = 0;
|
std11::thread::id this_id = std11::this_thread::get_id();
|
||||||
std::thread::id this_id = std::this_thread::get_id();
|
uint64_t iddd = std11::hash<std11::thread::id>()(this_id);
|
||||||
uint64_t iddd = std::hash<std::thread::id>()(this_id);
|
static std11::mutex g_lock;
|
||||||
static std11::mutex g_lock;
|
g_lock.lock();
|
||||||
g_lock.lock();
|
static std::map<uint64_t, uint32_t> g_list;
|
||||||
static std::map<uint64_t, uint32_t> g_list;
|
std::map<uint64_t, uint32_t>::iterator it = g_list.find(iddd);
|
||||||
auto it = g_list.find(iddd);
|
if (it == g_list.end()) {
|
||||||
if (it == g_list.end()) {
|
// attribute new ID :
|
||||||
// attribute new ID :
|
static uint32_t tmpId = 0;
|
||||||
static uint32_t tmpId = 0;
|
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
|
||||||
g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
|
out = tmpId;
|
||||||
out = tmpId;
|
tmpId++;
|
||||||
tmpId++;
|
} else {
|
||||||
} else {
|
out = it->second;
|
||||||
out = it->second;
|
}
|
||||||
}
|
g_lock.unlock();
|
||||||
g_lock.unlock();
|
return out;
|
||||||
return out;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getDisplayTime(char* data) {
|
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++ = ' ';
|
||||||
*pointer = '\0';
|
*pointer = '\0';
|
||||||
}
|
}
|
||||||
#if __CPP_VERSION__ >= 2011
|
if(getThreadId() == true) {
|
||||||
if(getThreadId() == true) {
|
// display thread ID
|
||||||
// display thread ID
|
uint32_t iddd = etk::log::getThreadID();
|
||||||
uint32_t iddd = etk::log::getThreadID();
|
sprintf(pointer, "%3d", iddd);
|
||||||
sprintf(pointer, "%3d", iddd);
|
pointer = handle+strlen(handle);
|
||||||
pointer = handle+strlen(handle);
|
*pointer++ = ' ';
|
||||||
*pointer++ = ' ';
|
*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++ = ' ';
|
||||||
*pointer = '\0';
|
*pointer = '\0';
|
||||||
}
|
}
|
||||||
if(getThreadNameEnable() == true) {
|
*pointer++ = '|';
|
||||||
// display thread ID
|
*pointer++ = ' ';
|
||||||
std::string name = etk::log::getThreadName();
|
*pointer = '\0';
|
||||||
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
|
|
||||||
if(getLine() == true) {
|
if(getLine() == true) {
|
||||||
if (_ligne >= 0) {
|
if (_ligne >= 0) {
|
||||||
sprintf(pointer, "(l=%5d)", _ligne);
|
sprintf(pointer, "(l=%5d)", _ligne);
|
||||||
|
@ -1392,7 +1392,7 @@ namespace std {
|
|||||||
int32_t hour = (totalSecond/3600)%24;
|
int32_t hour = (totalSecond/3600)%24;
|
||||||
int32_t day = (totalSecond/(24*3600))%365;
|
int32_t day = (totalSecond/(24*3600))%365;
|
||||||
int32_t year = 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;
|
return _os;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user