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

@ -6,21 +6,36 @@
#include "event.hpp"
#include "heap.hpp"
namespace GC {
GCEventType GCEvent::getType() {
namespace GC
{
GCEventType GCEvent::getType()
{
return m_type;
}
TimeStamp GCEvent::getTimeStamp() {
std::time_t GCEvent::getTimeStamp()
{
return m_timestamp;
}
Chunk *GCEvent::getChunk() {
Chunk *GCEvent::getChunk()
{
return m_chunk;
}
void GCEvent::print(std::ostream &out) {
assert(false && "TODO: unimplemented");
inline const char *GCEvent::TypeToString()
{
switch (m_type)
{
case CollectStart: return "CollectStart";
case MarkStart: return "MarkStart";
case ChunkMarked: return "ChunkMarked";
case ChunkSwept: return "ChunkSwept";
case ChunkFreed: return "ChunkFreed";
case NewChunk: return "NewChunk";
case ReusedChunk: return "ReusedChunk";
default: return "[Unknown]";
}
}
}

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;
}
}