Work on the profiler
This commit is contained in:
parent
cdc802476d
commit
51765f4d0c
6 changed files with 101 additions and 49 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <time.h>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
|
||||
|
|
@ -20,34 +20,31 @@ namespace GC
|
|||
ReusedChunk
|
||||
};
|
||||
|
||||
using TimeStamp = std::chrono::_V2::system_clock::time_point;
|
||||
|
||||
class GCEvent
|
||||
{
|
||||
private:
|
||||
// make const
|
||||
GCEventType m_type;
|
||||
TimeStamp m_timestamp;
|
||||
std::time_t m_timestamp;
|
||||
Chunk *m_chunk;
|
||||
|
||||
public:
|
||||
GCEvent(GCEventType type)
|
||||
{
|
||||
m_type = type;
|
||||
m_timestamp = std::chrono::system_clock::now();
|
||||
m_timestamp = std::time(NULL);
|
||||
}
|
||||
|
||||
GCEvent(GCEventType type, Chunk *chunk)
|
||||
{
|
||||
m_type = type;
|
||||
m_timestamp = std::chrono::system_clock::now();
|
||||
m_timestamp = std::time(NULL);
|
||||
m_chunk = chunk;
|
||||
}
|
||||
|
||||
GCEventType getType();
|
||||
TimeStamp getTimeStamp();
|
||||
std::time_t getTimeStamp();
|
||||
Chunk *getChunk();
|
||||
|
||||
void print(std::ostream &out);
|
||||
const char *TypeToString();
|
||||
};
|
||||
}
|
||||
|
|
@ -24,7 +24,6 @@ namespace GC
|
|||
{
|
||||
|
||||
private:
|
||||
// Private constructor according to the singleton pattern
|
||||
Heap()
|
||||
{
|
||||
m_heap = static_cast<char *>(malloc(HEAP_SIZE));
|
||||
|
|
@ -32,14 +31,13 @@ namespace GC
|
|||
m_allocated_size = 0;
|
||||
}
|
||||
|
||||
// BEWARE only for testing, this should be adressed
|
||||
~Heap()
|
||||
{
|
||||
std::free((char *)m_heap);
|
||||
}
|
||||
|
||||
inline static Heap *the()
|
||||
{ // TODO: make private
|
||||
{
|
||||
if (m_instance) // if m_instance is not a nullptr
|
||||
return m_instance;
|
||||
m_instance = new Heap();
|
||||
|
|
@ -71,7 +69,6 @@ namespace GC
|
|||
uintptr_t *m_stack_top = nullptr;
|
||||
bool m_profiler_enable = false;
|
||||
|
||||
// maybe change to std::list
|
||||
std::vector<Chunk *> m_allocated_chunks;
|
||||
std::vector<Chunk *> m_freed_chunks;
|
||||
|
||||
|
|
@ -89,7 +86,7 @@ namespace GC
|
|||
|
||||
// DEBUG ONLY
|
||||
static inline Heap *debug_the()
|
||||
{ // TODO: make private
|
||||
{
|
||||
if (m_instance) // if m_instance is not a nullptr
|
||||
return m_instance;
|
||||
m_instance = new Heap();
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ namespace GC {
|
|||
inline static Profiler *m_instance = nullptr;
|
||||
std::vector<GCEvent *> m_events;
|
||||
|
||||
std::ofstream createFileStream();
|
||||
|
||||
public:
|
||||
static void record(GCEventType type);
|
||||
static void record(GCEventType type, Chunk *chunk);
|
||||
static void printTrace();
|
||||
static void dumpTrace();
|
||||
};
|
||||
}
|
||||
|
|
@ -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]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +1,48 @@
|
|||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
list<char> l;
|
||||
char c = 'a';
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
l.push_back(c++);
|
||||
}
|
||||
// list<char> l;
|
||||
// char c = 'a';
|
||||
// for (int i = 1; i <= 5; i++) {
|
||||
// l.push_back(c++);
|
||||
// }
|
||||
|
||||
auto iter = l.begin();
|
||||
auto stop = l.end();
|
||||
// auto iter = l.begin();
|
||||
// auto stop = l.end();
|
||||
|
||||
while (iter != stop) {
|
||||
cout << *iter << " ";
|
||||
// while (iter != stop) {
|
||||
// cout << *iter << " ";
|
||||
|
||||
iter++;
|
||||
}
|
||||
cout << endl;
|
||||
iter = l.begin();
|
||||
while (*iter != *stop) {
|
||||
cout << *iter << " ";
|
||||
iter++;
|
||||
}
|
||||
cout << endl;
|
||||
// iter++;
|
||||
// }
|
||||
// cout << endl;
|
||||
// iter = l.begin();
|
||||
// while (*iter != *stop) {
|
||||
// cout << *iter << " ";
|
||||
// iter++;
|
||||
// }
|
||||
// cout << endl;
|
||||
|
||||
cout << "rebased" << endl;
|
||||
// cout << "rebased" << endl;
|
||||
// cout << "iter: " << *iter << "\nstop: " << *stop << endl;
|
||||
|
||||
// TimeStamp ts = std::chrono::system_clock::now();
|
||||
// std::time_t tt = std::chrono::system_clock::to_time_t(ts);
|
||||
// std::string tstr = std::ctime(&tt);
|
||||
// tstr.resize(tstr.size()-1);
|
||||
// std::cout << tstr << std::endl;
|
||||
|
||||
char buffer[31];
|
||||
std::time_t tt = std::time(NULL);
|
||||
std::tm *ptm = std::localtime(&tt);
|
||||
std::strftime(buffer, 31, "/profiler/log_%a_%H_%M_%S.txt", ptm);
|
||||
std::cout << buffer << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue