Yoinked over the garbage collector.

This commit is contained in:
Samuel Hammersberg 2023-03-28 14:15:22 +02:00
parent 2aff7a7743
commit 85f31b129b
33 changed files with 2417 additions and 0 deletions

View file

@ -0,0 +1,49 @@
#pragma once
#include <vector>
#include "chunk.hpp"
#include "event.hpp"
namespace GC {
class Profiler {
private:
Profiler() {}
~Profiler()
{
for (GCEvent *c : m_events)
delete c;
}
/**
* Returns the instance of the Profiler singleton.
* If m_instance is the nullptr and the profiler
* is not initialized yet, initialize it and return
* the pointer to it. Otherwise return the previously
* initialized pointer.
*
* @returns The pointer to the profiler singleton.
*/
static Profiler *the()
{
if (m_instance)
return m_instance;
m_instance = new Profiler();
return m_instance;
}
inline static Profiler *m_instance {nullptr};
std::vector<GCEvent *> m_events;
std::ofstream create_file_stream();
std::string get_log_folder();
static void dump_trace();
public:
static void record(GCEventType type);
static void record(GCEventType type, size_t size);
static void record(GCEventType type, Chunk *chunk);
static void dispose();
};
}