Work on the profiler

This commit is contained in:
Victor Olin 2023-03-10 09:24:32 +01:00
parent cdc802476d
commit 51765f4d0c
6 changed files with 101 additions and 49 deletions

View file

@ -1,4 +1,8 @@
#include <ctime>
#include <cstring>
#include <iostream>
#include <fstream>
#include <time.h>
#include <vector>
#include "chunk.hpp"
@ -6,26 +10,49 @@
#include "heap.hpp"
#include "profiler.hpp"
namespace GC {
void Profiler::record(GCEventType type) {
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) {
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() {
void Profiler::dumpTrace()
{
auto profiler = Profiler::the();
auto start = profiler->m_events.begin();
auto end = profiler->m_events.end();
while (start != end) {
std::ofstream fstr = profiler->createFileStream();
while (start != end)
{
auto event = *start++;
event->print(std::cout);
fstr << "--------------------------------"
<< event->TypeToString()
<< event->getTimeStamp
}
}
std::ofstream createFileStream()
{
std::time_t tt = std::time(NULL);
std::tm *ptm = std::localtime(&tt);
char buffer[32];
std::strftime(buffer, 32, "/profiler/log_%a_%H_%M_%S.txt", ptm);
std::ofstream fstr(buffer);
return fstr;
}
}