profiler now fixed in wrapper also

This commit is contained in:
Victor Olin 2023-05-01 15:58:20 +02:00
parent bf3d91cdf1
commit ec3aa3cd60
6 changed files with 41 additions and 15 deletions

View file

@ -7,7 +7,7 @@
extern "C" { extern "C" {
#endif #endif
// #define WRAPPER_DEBUG #define WRAPPER_DEBUG
#ifdef WRAPPER_DEBUG #ifdef WRAPPER_DEBUG
typedef struct cheap typedef struct cheap
@ -19,11 +19,15 @@ struct cheap;
typedef struct cheap cheap_t; typedef struct cheap cheap_t;
#endif #endif
#define FuncCallsOnly 0x1E
#define ChunkOpsOnly 0x3E0
cheap_t *cheap_the(); cheap_t *cheap_the();
void cheap_init(); void cheap_init();
void cheap_dispose(); void cheap_dispose();
void *cheap_alloc(unsigned long size); void *cheap_alloc(unsigned long size);
void cheap_set_profiler(cheap_t *cheap, bool mode); void cheap_set_profiler(cheap_t *cheap, bool mode);
void cheap_profiler_log_options(cheap_t *cheap, unsigned long flag);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -83,6 +83,7 @@ namespace GC
static void dispose(); static void dispose();
static void *alloc(size_t size); static void *alloc(size_t size);
void set_profiler(bool mode); void set_profiler(bool mode);
void set_profiler_log_options(RecordOption flags);
// Stop the compiler from generating copy-methods // Stop the compiler from generating copy-methods
Heap(Heap const&) = delete; Heap(Heap const&) = delete;

View file

@ -16,7 +16,7 @@ namespace GC {
{ {
FunctionCalls = (GC::AllocStart | GC::CollectStart | GC::MarkStart | GC::SweepStart), FunctionCalls = (GC::AllocStart | GC::CollectStart | GC::MarkStart | GC::SweepStart),
ChunkOps = (GC::ChunkMarked | GC::ChunkSwept | GC::ChunkFreed | GC::NewChunk | GC::ReusedChunk), ChunkOps = (GC::ChunkMarked | GC::ChunkSwept | GC::ChunkFreed | GC::NewChunk | GC::ReusedChunk),
AllOps = ~0 AllOps = 0xFFFFFF
}; };
struct ProfilerEvent struct ProfilerEvent

View file

@ -45,4 +45,19 @@ void cheap_set_profiler(cheap_t *cheap, bool mode)
GC::Heap *heap = static_cast<GC::Heap *>(cheap->obj); GC::Heap *heap = static_cast<GC::Heap *>(cheap->obj);
heap->set_profiler(mode); heap->set_profiler(mode);
}
void cheap_profiler_log_options(cheap_t *cheap, unsigned long flags)
{
GC::Heap *heap = static_cast<GC::Heap *>(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);
} }

View file

@ -43,6 +43,11 @@ namespace GC
heap.m_heap_top = heap.m_heap; 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 * Disposes the heap and the profiler at program exit
* which also triggers a heap log file dumped if the * which also triggers a heap log file dumped if the

View file

@ -21,23 +21,23 @@ void test_init()
/* Uncomment ONLY if run with DEBUG defined in cheap.h */ /* Uncomment ONLY if run with DEBUG defined in cheap.h */
// cheap_t *test_the() cheap_t *test_the()
// { {
// printf("----- IN TEST_THE -----------------------------\n"); 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); free(snd_heap);
// return fst_heap; return fst_heap;
// } }
void test_profiler(cheap_t *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, false);
cheap_set_profiler(heap, true); cheap_set_profiler(heap, true);
cheap_profiler_log_options(heap, FuncCallsOnly);
printf("----- EXIT TEST_PROFILER ----------------------\n"); printf("----- EXIT TEST_PROFILER ----------------------\n");
} }
@ -79,8 +80,8 @@ int main()
test_init(); test_init();
/* Uncomment ONLY if run with DEBUG defined in cheap.h */ /* Uncomment ONLY if run with DEBUG defined in cheap.h */
// cheap_t *heap = test_the(); cheap_t *heap = test_the();
// test_profiler(heap); test_profiler(heap);
Object *o = test_alloc(); Object *o = test_alloc();
printf("Object size: %lu\n", sizeof(Object)); printf("Object size: %lu\n", sizeof(Object));