Skip to content

Commit

Permalink
Better tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed May 16, 2024
1 parent 975c497 commit 097b4ef
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion redGrapes/memory/chunked_bump_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion redGrapes/redGrapes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ 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<BindArgs<Callable, Args...>, Callable, Args...>;
// this is not set to nullptr. But it goes out of scope. Memory is managed by allocate
FunTask<Impl, RGTask>* task;
memory::Allocator alloc(worker_id);
memory::Block blk = alloc.allocate(sizeof(FunTask<Impl, RGTask>));
task = (FunTask<Impl, RGTask>*) blk.ptr;
SPDLOG_TRACE("Allocated Task of size {}", sizeof(FunTask<Impl, RGTask>));

if(!task)
throw std::bad_alloc();
Expand Down
2 changes: 1 addition & 1 deletion redGrapes/task/task_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion redGrapes/task/task_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -85,6 +85,7 @@ namespace redGrapes
// if(TaskCtx<TTask>::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();
}
Expand Down
2 changes: 2 additions & 0 deletions redGrapes/util/atomic_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include "redGrapes/memory/block.hpp"
#include "redGrapes/util/demangled_name.hpp"
#include "redGrapes/util/trace.hpp"

#include <fmt/format.h>
Expand Down Expand Up @@ -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<Item>(), n_bytes);
}

template<typename U>
Expand Down
2 changes: 2 additions & 0 deletions redGrapes/util/chunked_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <spdlog/spdlog.h>
Expand Down Expand Up @@ -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<T>(), sizeof(Item));
}

ChunkedList(ChunkedList&& other) = default;
Expand Down
47 changes: 47 additions & 0 deletions redGrapes/util/demangled_name.hpp
Original file line number Diff line number Diff line change
@@ -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 <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
# include <cxxabi.h>
#endif
#include <cstdlib>
#include <memory>
#include <string>

namespace redGrapes::util
{
/**
* Demangled type names from
* https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c
*/
template<class T>
std::string type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void (*)(void*)> 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<TR>::value)
r += " const";
if(std::is_volatile<TR>::value)
r += " volatile";
if(std::is_lvalue_reference<T>::value)
r += "&";
else if(std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}
} // namespace redGrapes::util

0 comments on commit 097b4ef

Please sign in to comment.