So many changes. Broken.
[invirt/third/libt4.git] / debug.cc
similarity index 71%
rename from threaded_log.cc
rename to debug.cc
index 3218e33..784a054 100644 (file)
+++ b/debug.cc
@@ -1,6 +1,6 @@
-#include "t4.h"
-#include "types.h"
-#include "threaded_log.h"
+#include "include/t4.h"
+#include "include/types.h"
+#include "include/debug.h"
 
 using namespace std::chrono;
 
@@ -9,8 +9,7 @@ locked_ostream && _log_prefix(locked_ostream && f, const string & file, const st
     int tid = global->thread_name_map[thread];
     if (tid==0)
         tid = global->thread_name_map[thread] = ++global->next_thread_num;
-    auto utime = duration_cast<microseconds>(
-            system_clock::now().time_since_epoch()).count() % 1000000000;
+    auto utime = (system_clock::now().time_since_epoch() / 1us) % 1000000000;
     f << std::setfill('0') << std::dec << std::left << std::setw(9) << utime << " ";
     f << std::setfill(' ') << global->log_thread_prefix << std::left << std::setw(2) << tid;
     f << " " << std::setw(20) << file << " " << std::setw(18) << func;
@@ -32,3 +31,12 @@ int _log_debug_level() {
 lock _log_lock() {
     return lock(global->log_mutex);
 }
+
+string hex_string(const string & s) {
+    string bytes;
+    for (char ch : s) {
+        bytes.push_back("0123456789abcdef"[(uint8_t)ch >> 4]);
+        bytes.push_back("0123456789abcdef"[(uint8_t)ch & 15]);
+    }
+    return bytes;
+}