From 097b4efd7f2354537fef5af92c403646c78dc056 Mon Sep 17 00:00:00 2001 From: Tapish Date: Thu, 16 May 2024 14:37:57 +0200 Subject: [PATCH] Better tracing --- redGrapes/memory/chunked_bump_alloc.hpp | 2 +- redGrapes/redGrapes.hpp | 3 +- redGrapes/task/task_builder.hpp | 2 +- redGrapes/task/task_space.hpp | 3 +- redGrapes/util/atomic_list.hpp | 2 ++ redGrapes/util/chunked_list.hpp | 2 ++ redGrapes/util/demangled_name.hpp | 47 +++++++++++++++++++++++++ 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 redGrapes/util/demangled_name.hpp diff --git a/redGrapes/memory/chunked_bump_alloc.hpp b/redGrapes/memory/chunked_bump_alloc.hpp index 3ca8a606..9e7beba1 100644 --- a/redGrapes/memory/chunked_bump_alloc.hpp +++ b/redGrapes/memory/chunked_bump_alloc.hpp @@ -115,7 +115,7 @@ namespace redGrapes void deallocate(Block blk) { TRACE_EVENT("Allocator", "ChunkedBumpAlloc::deallocate()"); - SPDLOG_TRACE("ChunkedBumpAlloc[{}]: free {} ", (void*) this, (uintptr_t) blk.ptr); + SPDLOG_TRACE("ChunkedBumpAlloc[{}]: free {} {} ", (void*) this, (uintptr_t) blk.ptr, blk.len); /* find the chunk that contains `ptr` and deallocate there. * Additionally, delete the chunk if possible. diff --git a/redGrapes/redGrapes.hpp b/redGrapes/redGrapes.hpp index 7c29c80b..658e4db0 100644 --- a/redGrapes/redGrapes.hpp +++ b/redGrapes/redGrapes.hpp @@ -145,7 +145,7 @@ namespace redGrapes { WorkerId worker_id = scheduler_map[TSchedTag{}]->getNextWorkerID(); - SPDLOG_TRACE("emplace task to worker {} next_worker={}", worker_id, TaskFreeCtx::next_worker); + SPDLOG_TRACE("emplace task to worker {}", worker_id); using Impl = typename std::invoke_result_t, Callable, Args...>; // this is not set to nullptr. But it goes out of scope. Memory is managed by allocate @@ -153,6 +153,7 @@ namespace redGrapes memory::Allocator alloc(worker_id); memory::Block blk = alloc.allocate(sizeof(FunTask)); task = (FunTask*) blk.ptr; + SPDLOG_TRACE("Allocated Task of size {}", sizeof(FunTask)); if(!task) throw std::bad_alloc(); diff --git a/redGrapes/task/task_builder.hpp b/redGrapes/task/task_builder.hpp index 7781ab66..f303b6d8 100644 --- a/redGrapes/task/task_builder.hpp +++ b/redGrapes/task/task_builder.hpp @@ -99,7 +99,7 @@ namespace redGrapes TTask* t = task; task = nullptr; - SPDLOG_TRACE("submit task {}", (TTask::TaskProperties const&) *t); + SPDLOG_TRACE("submit task {}", (typename TTask::TaskProperties const&) *t); space->submit(t); t->scheduler_p->emplace_task(*t); diff --git a/redGrapes/task/task_space.hpp b/redGrapes/task/task_space.hpp index 2ae4bfae..8df01c60 100644 --- a/redGrapes/task/task_space.hpp +++ b/redGrapes/task/task_space.hpp @@ -70,7 +70,7 @@ namespace redGrapes unsigned count = task_count.fetch_sub(1) - 1; unsigned worker_id = task->worker_id; - task->~TTask(); // TODO check if this is really required + task->~TTask(); // FIXME: len of the Block is not correct since FunTask object is bigger than sizeof(Task) TaskFreeCtx::worker_alloc_pool->get_alloc(worker_id).deallocate( @@ -85,6 +85,7 @@ namespace redGrapes // if(TaskCtx::root_space->empty()) cant be written because TaskCtx include root space if(count == 0 && depth == 0) { + SPDLOG_TRACE("Wake up parser due to free task and no more tasks"); // TODO should i wake up workers also? that was the old behaviour TaskFreeCtx::cv.notify(); } diff --git a/redGrapes/util/atomic_list.hpp b/redGrapes/util/atomic_list.hpp index 92f22687..0ff7b4b7 100644 --- a/redGrapes/util/atomic_list.hpp +++ b/redGrapes/util/atomic_list.hpp @@ -8,6 +8,7 @@ #pragma once #include "redGrapes/memory/block.hpp" +#include "redGrapes/util/demangled_name.hpp" #include "redGrapes/util/trace.hpp" #include @@ -106,6 +107,7 @@ namespace redGrapes StaticAlloc(Allocator alloc, size_t n_bytes) : alloc(alloc), ptr((T*) alloc.allocate(n_bytes)) { + SPDLOG_TRACE(" object: {} , bytes : {}", util::type_name(), n_bytes); } template diff --git a/redGrapes/util/chunked_list.hpp b/redGrapes/util/chunked_list.hpp index 6b1ab579..89d22c39 100644 --- a/redGrapes/util/chunked_list.hpp +++ b/redGrapes/util/chunked_list.hpp @@ -13,6 +13,7 @@ #include "redGrapes/memory/allocator.hpp" #include "redGrapes/util/atomic_list.hpp" +#include "redGrapes/util/demangled_name.hpp" #include "redGrapes/util/trace.hpp" #include @@ -496,6 +497,7 @@ namespace redGrapes public: ChunkedList(Allocator&& alloc) : chunks(std::move(alloc), T_chunk_size * sizeof(Item) + sizeof(Chunk)) { + SPDLOG_TRACE("Chunked List - object: {} , size : {}", util::type_name(), sizeof(Item)); } ChunkedList(ChunkedList&& other) = default; diff --git a/redGrapes/util/demangled_name.hpp b/redGrapes/util/demangled_name.hpp new file mode 100644 index 00000000..d4a2d5dc --- /dev/null +++ b/redGrapes/util/demangled_name.hpp @@ -0,0 +1,47 @@ +/* Copyright 2024 Tapish Narwal + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include +#include +#ifndef _MSC_VER +# include +#endif +#include +#include +#include + +namespace redGrapes::util +{ + /** + * Demangled type names from + * https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c + */ + template + std::string type_name() + { + typedef typename std::remove_reference::type TR; + std::unique_ptr own( +#ifndef _MSC_VER + abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr), +#else + nullptr, +#endif + std::free); + std::string r = own != nullptr ? own.get() : typeid(TR).name(); + if(std::is_const::value) + r += " const"; + if(std::is_volatile::value) + r += " volatile"; + if(std::is_lvalue_reference::value) + r += "&"; + else if(std::is_rvalue_reference::value) + r += "&&"; + return r; + } +} // namespace redGrapes::util