From 50e10586f1c876987de5f242361cf160f6176053 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Mon, 8 May 2023 11:00:07 +0200 Subject: [PATCH] short profiler logs --- src/GC/include/heap.hpp | 5 +++ src/GC/include/profiler.hpp | 5 +-- src/GC/lib/heap.cpp | 18 +--------- src/GC/lib/profiler.cpp | 13 ++++--- src/GC/tests/linkedlist.cpp | 68 ++----------------------------------- 5 files changed, 21 insertions(+), 88 deletions(-) diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index d08d0d7..6052966 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -9,6 +9,7 @@ #include "chunk.hpp" #include "profiler.hpp" +<<<<<<< HEAD <<<<<<< HEAD <<<<<<< HEAD #define HEAP_SIZE 320//65536 @@ -17,6 +18,10 @@ #define HEAP_SIZE 16000//65536 #define FREE_THRESH (uint) 100 >>>>>>> c09da8a (now it works ok???) +======= +#define HEAP_SIZE 160000//65536 +#define FREE_THRESH (uint) 5 +>>>>>>> 5056624 (short profiler logs) // #define HEAP_DEBUG ======= #define HEAP_SIZE 2097152 //256 //65536 //2097152 diff --git a/src/GC/include/profiler.hpp b/src/GC/include/profiler.hpp index 1c44ef6..56acf7b 100644 --- a/src/GC/include/profiler.hpp +++ b/src/GC/include/profiler.hpp @@ -14,6 +14,7 @@ namespace GC { enum RecordOption { + TimingInfo = 0, FunctionCalls = (GC::AllocStart | GC::CollectStart | GC::MarkStart | GC::SweepStart | GC::FreeStart), ChunkOps = (GC::ChunkMarked | GC::ChunkSwept | GC::ChunkFreed | GC::NewChunk | GC::ReusedChunk), AllOps = 0xFFFFFF @@ -41,7 +42,7 @@ namespace GC { std::vector m_events; ProfilerEvent *m_last_prof_event {new ProfilerEvent(HeapInit)}; std::vector m_prof_events; - RecordOption flags; + RecordOption flags {AllOps}; std::chrono::microseconds alloc_time {0}; // size_t alloc_counts {0}; @@ -52,7 +53,7 @@ namespace GC { std::ofstream create_file_stream(); std::string get_log_folder(); static void dump_trace(); - static void dump_prof_trace(); + static void dump_prof_trace(bool timing_only); static void dump_chunk_trace(); // static void dump_trace_short(); // static void dump_trace_full(); diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index b0fc18e..cc393b1 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -288,23 +288,7 @@ namespace GC stack_bottom++; } } - - /** - * Iterates through the stack, if an element on the stack points to a chunk, - * called a root chunk, that chunk is marked (i.e. reachable). - * Then it recursively follows all chunks which are possibly reachable from - * the root chunk and mark those chunks. - * If a chunk is marked it is removed from the worklist, since it's no longer of - * concern for this method. - * - * Time complexity: 0(N^2 * log(N)) as upper bound. - * Where N is either the size of the worklist or the size of - * the stack frame, depending on which is the largest. - * - * @param start Pointer to the start of the stack frame. - * @param end Pointer to the end of the stack frame. - * @param worklist The currently allocated chunks, which haven't been marked. - */ + void Heap::mark(vector &roots) { bool prof_enabled = m_profiler_enable; diff --git a/src/GC/lib/profiler.cpp b/src/GC/lib/profiler.cpp index ae31f0d..690da39 100644 --- a/src/GC/lib/profiler.cpp +++ b/src/GC/lib/profiler.cpp @@ -83,8 +83,10 @@ namespace GC void Profiler::dump_trace() { Profiler &prof = Profiler::the(); - if (prof.flags & FunctionCalls) - dump_prof_trace(); + if (prof.flags == TimingInfo) + dump_prof_trace(true); + else if (prof.flags & FunctionCalls) + dump_prof_trace(false); else dump_chunk_trace(); } @@ -127,7 +129,7 @@ namespace GC } } - void Profiler::dump_prof_trace() + void Profiler::dump_prof_trace(bool timing_only) { Profiler &prof = Profiler::the(); prof.m_prof_events.push_back(prof.m_last_prof_event); @@ -147,9 +149,12 @@ namespace GC else if (event->m_type == CollectStart) collects += event->m_n; - fstr << "\n--------------------------------\n" + if (!timing_only) + { + fstr << "\n--------------------------------\n" << Profiler::type_to_string(event->m_type) << " " << event->m_n << " times:"; + } } fstr << "\n--------------------------------"; diff --git a/src/GC/tests/linkedlist.cpp b/src/GC/tests/linkedlist.cpp index ada55bd..474e9b3 100644 --- a/src/GC/tests/linkedlist.cpp +++ b/src/GC/tests/linkedlist.cpp @@ -32,83 +32,21 @@ Node *create_list(size_t length) return head; } -void print_list(Node* head) -{ - cout << "\nPrinting list...\n"; - while (head != nullptr) - { - cout << head->value << " "; - head = head->next; - } - cout << endl; -} - -void clear_list(Node *head) -{ - while (head != nullptr) - { - Node *tmp = head->next; - head->next = nullptr; - head = tmp; - } -} - #define LIST_SIZE 1000 void list_test1() { Node *list_1 = create_list(LIST_SIZE); - // print_list(list_1); } -/* -void list_test2() -{ - Node *list_2 = create_list(LIST_SIZE); - // print_list(list_2); -} - -void list_test3() -{ - Node *list_3 = create_list(LIST_SIZE); - // print_list(list_3); -} - -void list_test4() -{ - Node *list_4 = create_list(LIST_SIZE); - // print_list(list_4); -} - -void list_test5() -{ - Node *list_5 = create_list(LIST_SIZE); - // print_list(list_5); -} - -void list_test6() -{ - Node *list_6 = create_list(LIST_SIZE); - // print_list(list_6); -} - -void make_test() { - list_test1(); - list_test2(); - list_test3(); - list_test4(); - list_test5(); - list_test6(); -} -*/ - int main() { GC::Heap::init(); GC::Heap &heap = GC::Heap::the(); heap.set_profiler(true); - GC::Profiler::set_log_options(GC::FunctionCalls); - //GC::Profiler::set_log_options(GC::AllOps); + // GC::Profiler::set_log_options(GC::FunctionCalls); + // GC::Profiler::set_log_options(GC::ChunkOps); + GC::Profiler::set_log_options(GC::TimingInfo); // make_test(); for (int i = 0; i < 1000; i++)