From d7553a42bd66ec7e99938d07211bd35382bd668e Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 11 Nov 2018 07:33:21 +0000 Subject: [PATCH] Core: TIMING improvements, usecs (microseconds precision time), ide: Debugger now underlines main thread git-svn-id: svn://ultimatepp.org/upp/trunk@12499 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Core.h | 2 ++ uppsrc/Core/Debug.cpp | 25 ++++++++----------------- uppsrc/Core/Util.cpp | 12 +++++++++++- uppsrc/Core/Util.h | 3 ++- uppsrc/ide/Debuggers/Code.cpp | 4 +++- uppsrc/ide/Debuggers/Gdb.cpp | 12 ++++++++++-- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/uppsrc/Core/Core.h b/uppsrc/Core/Core.h index 4a437dc15..4fa3771c1 100644 --- a/uppsrc/Core/Core.h +++ b/uppsrc/Core/Core.h @@ -177,6 +177,7 @@ #include #include #include + #include #define byte win32_byte_ // RpcNdr defines byte -> class with Upp::byte #define CY win32_CY_ #include @@ -238,6 +239,7 @@ typedef int SOCKET; #include #include #include +#include // fix MSC8 beta problem.... #ifdef COMPILER_MSC diff --git a/uppsrc/Core/Debug.cpp b/uppsrc/Core/Debug.cpp index 6560f2ccb..08a5126dc 100644 --- a/uppsrc/Core/Debug.cpp +++ b/uppsrc/Core/Debug.cpp @@ -42,23 +42,9 @@ inline int tmGetTime() { } #endif -static TimingInspector& s_zero() -{ - static TimingInspector *s_zero = NULL; - static bool init = false; - if(!init) { - init = true; - static TimingInspector s_zero_; - s_zero = &s_zero_; - int w = GetTickCount(); - while(GetTickCount() - w < 200) - TimingInspector::Routine __(*s_zero); - } - return *s_zero; -} +static TimingInspector s_zero; // time of Start / End without actual body to measure TimingInspector::TimingInspector(const char *_name) { - s_zero(); //!! atexit name = _name ? _name : ""; start_time = 0; all_count = call_count = max_nesting = nesting_depth = min_time = max_time = total_time = 0; @@ -73,7 +59,7 @@ TimingInspector::TimingInspector(const char *_name) { TimingInspector::~TimingInspector() { Mutex::Lock __(mutex); - if(this == &s_zero()) return; + if(this == &s_zero) return; StdLog() << Dump() << "\r\n"; } @@ -109,8 +95,13 @@ String TimingInspector::Dump() { String s = Sprintf("TIMING %-15s: ", name); if(call_count == 0) return s + "No active hit"; + ONCELOCK { + int w = GetTickCount(); + while(GetTickCount() - w < 200) + TimingInspector::Routine __(s_zero); + } double tm = max(0.0, double(total_time) / call_count / 1000 - - double(s_zero().total_time) / s_zero().call_count / 1000); + double(s_zero.total_time) / s_zero.call_count / 1000); return s + timeFormat(tm * call_count) + " - " + timeFormat(tm) diff --git a/uppsrc/Core/Util.cpp b/uppsrc/Core/Util.cpp index e983bcb1c..2a637ba0a 100644 --- a/uppsrc/Core/Util.cpp +++ b/uppsrc/Core/Util.cpp @@ -187,7 +187,17 @@ dword GetTickCount() { } #endif -int msecs(int from) { return GetTickCount() - (dword)from; } +int64 usecs(int64 prev) +{ + auto p2 = std::chrono::high_resolution_clock::now(); + return std::chrono::duration_cast(p2.time_since_epoch()).count() - prev; +} + +int msecs(int prev) +{ + auto p2 = std::chrono::high_resolution_clock::now(); + return (int)std::chrono::duration_cast(p2.time_since_epoch()).count() - prev; +} void TimeStop::Reset() { diff --git a/uppsrc/Core/Util.h b/uppsrc/Core/Util.h index a2a9166e2..9fd8399c3 100644 --- a/uppsrc/Core/Util.h +++ b/uppsrc/Core/Util.h @@ -9,7 +9,8 @@ static const int _MAX_PATH = PATH_MAX; dword GetTickCount(); #endif -int msecs(int from = 0); +int64 usecs(int64 prev = 0); +int msecs(int prev = 0); class TimeStop : Moveable { dword starttime; diff --git a/uppsrc/ide/Debuggers/Code.cpp b/uppsrc/ide/Debuggers/Code.cpp index 98e732828..1815b40c8 100644 --- a/uppsrc/ide/Debuggers/Code.cpp +++ b/uppsrc/ide/Debuggers/Code.cpp @@ -60,8 +60,10 @@ void Pdb::Sync() for(int i = 0; i < threads.GetCount(); i++) { int thid = threads.GetKey(i); AttrText x(Format("0x%x", thid)); + if(thid == mainThreadId) + x.Underline(); if(thid == debug_threadid) - x.font = StdFont().Bold(); + x.Bold(); threadlist.Add(thid, x); } threadlist <<= (int)debug_threadid; diff --git a/uppsrc/ide/Debuggers/Gdb.cpp b/uppsrc/ide/Debuggers/Gdb.cpp index 21f3ddd22..cc9c3f8a5 100644 --- a/uppsrc/ide/Debuggers/Gdb.cpp +++ b/uppsrc/ide/Debuggers/Gdb.cpp @@ -287,6 +287,7 @@ String Gdb::ObtainThreadsInfo() String output = FastCmd("info threads"); StringStream ss(output); int active_thread = -1; + bool main = true; while(!ss.IsEof()) { String s = ss.GetLine(); CParser p(s); @@ -294,9 +295,16 @@ String Gdb::ObtainThreadsInfo() bool active = p.Char('*'); if(p.IsNumber()) { int id = p.ReadInt(); - threads.Add(id, String().Cat() << "Thread " << id); - if(active) + AttrText text = String() << "Thread " << id; + if(active) { active_thread = id; + text.Bold(); + } + if(main) { + text.Underline(); + main = false; + } + threads.Add(id, text); } threads.GoBegin(); }