From ec3aa3cd606d0fd23e1455edf896c3d9c056a470 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Mon, 1 May 2023 15:58:20 +0200 Subject: [PATCH] profiler now fixed in wrapper also --- src/GC/include/cheap.h | 6 +++++- src/GC/include/heap.hpp | 1 + src/GC/include/profiler.hpp | 2 +- src/GC/lib/cheap.cpp | 15 +++++++++++++++ src/GC/lib/heap.cpp | 5 +++++ src/GC/tests/wrapper.c | 27 ++++++++++++++------------- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/GC/include/cheap.h b/src/GC/include/cheap.h index f4cd03c..7d803a8 100644 --- a/src/GC/include/cheap.h +++ b/src/GC/include/cheap.h @@ -7,7 +7,7 @@ extern "C" { #endif -// #define WRAPPER_DEBUG +#define WRAPPER_DEBUG #ifdef WRAPPER_DEBUG typedef struct cheap @@ -19,11 +19,15 @@ struct cheap; typedef struct cheap cheap_t; #endif +#define FuncCallsOnly 0x1E +#define ChunkOpsOnly 0x3E0 + cheap_t *cheap_the(); void cheap_init(); void cheap_dispose(); void *cheap_alloc(unsigned long size); void cheap_set_profiler(cheap_t *cheap, bool mode); +void cheap_profiler_log_options(cheap_t *cheap, unsigned long flag); #ifdef __cplusplus } diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index cebf89d..eb161c0 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -83,6 +83,7 @@ namespace GC static void dispose(); static void *alloc(size_t size); void set_profiler(bool mode); + void set_profiler_log_options(RecordOption flags); // Stop the compiler from generating copy-methods Heap(Heap const&) = delete; diff --git a/src/GC/include/profiler.hpp b/src/GC/include/profiler.hpp index b8661ad..f70ca3b 100644 --- a/src/GC/include/profiler.hpp +++ b/src/GC/include/profiler.hpp @@ -16,7 +16,7 @@ namespace GC { { FunctionCalls = (GC::AllocStart | GC::CollectStart | GC::MarkStart | GC::SweepStart), ChunkOps = (GC::ChunkMarked | GC::ChunkSwept | GC::ChunkFreed | GC::NewChunk | GC::ReusedChunk), - AllOps = ~0 + AllOps = 0xFFFFFF }; struct ProfilerEvent diff --git a/src/GC/lib/cheap.cpp b/src/GC/lib/cheap.cpp index f6c24a9..42179b6 100644 --- a/src/GC/lib/cheap.cpp +++ b/src/GC/lib/cheap.cpp @@ -45,4 +45,19 @@ void cheap_set_profiler(cheap_t *cheap, bool mode) GC::Heap *heap = static_cast(cheap->obj); heap->set_profiler(mode); +} + +void cheap_profiler_log_options(cheap_t *cheap, unsigned long flags) +{ + GC::Heap *heap = static_cast(cheap->obj); + + GC::RecordOption cast_flag; + if (flags == FuncCallsOnly) + cast_flag = GC::FunctionCalls; + else if (flags == ChunkOpsOnly) + cast_flag = GC::ChunkOps; + else + cast_flag = GC::AllOps; + + heap->set_profiler_log_options(cast_flag); } \ No newline at end of file diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 2060b93..fade27a 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -43,6 +43,11 @@ namespace GC heap.m_heap_top = heap.m_heap; } + void Heap::set_profiler_log_options(RecordOption flags) + { + Profiler::set_log_options(flags); + } + /** * Disposes the heap and the profiler at program exit * which also triggers a heap log file dumped if the diff --git a/src/GC/tests/wrapper.c b/src/GC/tests/wrapper.c index bcd4859..d6f042c 100644 --- a/src/GC/tests/wrapper.c +++ b/src/GC/tests/wrapper.c @@ -21,23 +21,23 @@ void test_init() /* Uncomment ONLY if run with DEBUG defined in cheap.h */ -// cheap_t *test_the() -// { -// printf("----- IN TEST_THE -----------------------------\n"); +cheap_t *test_the() +{ + printf("----- IN TEST_THE -----------------------------\n"); -// cheap_t *fst_heap = cheap_the(); + cheap_t *fst_heap = cheap_the(); -// printf("Heap 1:\t%p\n", fst_heap->obj); + printf("Heap 1:\t%p\n", fst_heap->obj); -// cheap_t *snd_heap = cheap_the(); + cheap_t *snd_heap = cheap_the(); -// printf("Heap 2:\t%p\n", snd_heap->obj); + printf("Heap 2:\t%p\n", snd_heap->obj); -// printf("----- EXIT TEST_THE ---------------------------\n"); + printf("----- EXIT TEST_THE ---------------------------\n"); -// free(snd_heap); -// return fst_heap; -// } + free(snd_heap); + return fst_heap; +} void test_profiler(cheap_t *heap) { @@ -45,6 +45,7 @@ void test_profiler(cheap_t *heap) cheap_set_profiler(heap, false); cheap_set_profiler(heap, true); + cheap_profiler_log_options(heap, FuncCallsOnly); printf("----- EXIT TEST_PROFILER ----------------------\n"); } @@ -79,8 +80,8 @@ int main() test_init(); /* Uncomment ONLY if run with DEBUG defined in cheap.h */ - // cheap_t *heap = test_the(); - // test_profiler(heap); + cheap_t *heap = test_the(); + test_profiler(heap); Object *o = test_alloc(); printf("Object size: %lu\n", sizeof(Object));