From 07462950139eea868bdf74e4f0b660f623ef35cd Mon Sep 17 00:00:00 2001 From: tobid7 Date: Tue, 1 Sep 2026 10:02:54 +0200 Subject: [PATCH] time trace is back --- include/pd/core/timetrace.hpp | 12 +++++++++--- source/core/timetrace.cpp | 23 +++++++++++++++++++---- source/drivers/os.cpp | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/include/pd/core/timetrace.hpp b/include/pd/core/timetrace.hpp index 4196813..a3c4ddd 100644 --- a/include/pd/core/timetrace.hpp +++ b/include/pd/core/timetrace.hpp @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include namespace PD { @@ -143,6 +144,8 @@ class TimeStats { * Timatrace Functions */ namespace TT { +class Res; +using TraceMap = std::map; /** * Data Structure for a TimeTrace Result */ @@ -202,11 +205,11 @@ class Res { /** Trace ID */ std::string id; /** Start time */ - u64 start; + u64 start = 0; /** End Time */ - u64 end; + u64 end = 0; /** Last Diff */ - u64 diff; + u64 diff = 0; /** Protocol */ TimeStats protocol; }; @@ -220,6 +223,9 @@ PD_API void Beg(const std::string& id); * @param id Name of the Trace */ PD_API void End(const std::string& id); +PD_API TraceMap& GetTraceMap(); +PD_API TT::Res& GetTraceRef(const std::string& id); +PD_API bool TraceExist(const std::string& id); /** * Collect Start end end of the trace by tracking * when the Scope object goes out of scope diff --git a/source/core/timetrace.cpp b/source/core/timetrace.cpp index 8d4952b..11422e6 100755 --- a/source/core/timetrace.cpp +++ b/source/core/timetrace.cpp @@ -22,15 +22,30 @@ SOFTWARE. */ #include +#include namespace PD::TT { +static TraceMap pTraces; + +PD_API TraceMap& GetTraceMap() { return pTraces; } + +PD_API TT::Res& GetTraceRef(const std::string& id) { + if (!pTraces.count(id)) { + pTraces[id] = TT::Res(); + pTraces[id].SetID(id); + } + return pTraces[id]; +} + +PD_API bool TraceExist(const std::string& id) { return pTraces.count(id); } + PD_API void Beg(const std::string& id) { - /*auto trace = os.GetTraceRef(id); - trace->SetStart(os.GetNanoTime());*/ + auto& trace = GetTraceRef(id); + trace.SetStart(PD::Os::GetTimeNano()); } PD_API void End(const std::string& id) { - /*auto trace = os.GetTraceRef(id); - trace->SetEnd(os.GetNanoTime());*/ + auto& trace = GetTraceRef(id); + trace.SetEnd(PD::Os::GetTimeNano()); } } // namespace PD::TT \ No newline at end of file diff --git a/source/drivers/os.cpp b/source/drivers/os.cpp index 5fc2d7f..f5d2ae8 100755 --- a/source/drivers/os.cpp +++ b/source/drivers/os.cpp @@ -1,7 +1,7 @@ #include namespace PD { -PD_API std::unique_ptr Os::driver; +PD_API std::unique_ptr Os::driver = std::make_unique(); PD_API u64 OsDriver::GetTime() const { return std::chrono::duration_cast(