Started working on a custom profiler
This commit is contained in:
parent
4f9aaaf8b4
commit
137687e446
8 changed files with 158 additions and 28 deletions
32
src/GC/lib/event.cpp
Normal file
32
src/GC/lib/event.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
#include "chunk.hpp"
|
||||
#include "event.hpp"
|
||||
#include "heap.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace GC {
|
||||
|
||||
GCEventType GCEvent::getType() {
|
||||
return m_type;
|
||||
}
|
||||
|
||||
TimeStamp GCEvent::getTimeStamp() {
|
||||
return m_timestamp;
|
||||
}
|
||||
|
||||
Chunk *GCEvent::getChunk() {
|
||||
return m_chunk;
|
||||
}
|
||||
|
||||
void GCEvent::printShort() {
|
||||
assert(false && "TODO: unimplemented");
|
||||
}
|
||||
|
||||
void GCEvent::printFull() {
|
||||
assert(false && "TODO: unimplemented");
|
||||
}
|
||||
}
|
||||
|
|
@ -141,12 +141,7 @@ namespace GC {
|
|||
// get current stack
|
||||
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||
|
||||
// fix this block, it's nästy
|
||||
uintptr_t *stack_top;
|
||||
if (heap->m_stack_top != nullptr)
|
||||
stack_top = heap->m_stack_top;
|
||||
else
|
||||
stack_top = (uintptr_t *)0; // temporary
|
||||
uintptr_t *stack_top = heap->m_stack_top != nullptr ? heap->m_stack_top : (uintptr_t *)0;
|
||||
|
||||
auto work_list = heap->m_allocated_chunks;
|
||||
mark(stack_bottom, stack_top, work_list);
|
||||
|
|
|
|||
34
src/GC/lib/profiler.cpp
Normal file
34
src/GC/lib/profiler.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "chunk.hpp"
|
||||
#include "event.hpp"
|
||||
#include "heap.hpp"
|
||||
#include "profiler.hpp"
|
||||
|
||||
namespace GC {
|
||||
void Profiler::record(GCEventType type) {
|
||||
auto event = new GCEvent(type);
|
||||
auto profiler = Profiler::the();
|
||||
profiler->m_events.push_back(event);
|
||||
}
|
||||
|
||||
void Profiler::record(GCEventType type, Chunk *chunk) {
|
||||
auto event = new GCEvent(type, chunk);
|
||||
auto profiler = Profiler::the();
|
||||
profiler->m_events.push_back(event);
|
||||
}
|
||||
|
||||
void Profiler::printTrace(PrintTraceOptions opt) {
|
||||
auto profiler = Profiler::the();
|
||||
auto start = profiler->m_events.begin();
|
||||
auto end = profiler->m_events.end();
|
||||
while (start != end) {
|
||||
auto event = *start++;
|
||||
if (opt == Short)
|
||||
event->printShort();
|
||||
else
|
||||
event->printFull();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue