Fixed ABS_PATH for profiler

This commit is contained in:
Victor Olin 2023-03-20 13:24:14 +01:00
parent fcae79ce0b
commit ffdffc475d
6 changed files with 99 additions and 24 deletions

View file

@ -24,19 +24,21 @@ namespace GC
return m_chunk;
}
// Try to remove inline
const char *GCEvent::type_to_string()
const char *const GCEvent::type_to_string()
{
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]";
case HeapInit: return "HeapInit";
case AllocStart: return "AllocStart";
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";
case ProfilerDispose: return "ProfilerDispose";
default: return "[Unknown]";
}
}
}

View file

@ -422,7 +422,9 @@ namespace GC
{
set_profiler(true);
if (Heap::get_profiler_mode())
auto heap = Heap::the();
if (heap->profiler_enabled())
Profiler::record(CollectStart);
cout << "DEBUG COLLECT\nFLAGS: ";
@ -434,8 +436,6 @@ namespace GC
cout << "\n - FREE";
cout << "\n";
auto heap = Heap::the();
// get the frame adress, whwere local variables and saved registers are located
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
cout << "Stack bottom in collect:\t" << stack_bottom << "\n";

View file

@ -4,6 +4,8 @@
#include <fstream>
#include <time.h>
#include <vector>
#include <unistd.h>
#include <stdexcept>
#include "chunk.hpp"
#include "event.hpp"
@ -80,17 +82,46 @@ namespace GC
std::ofstream Profiler::create_file_stream()
{
// get current time
std::time_t tt = std::time(NULL);
std::tm *ptm = std::localtime(&tt);
// format to string
char buffer[32];
std::strftime(buffer, 32, "/profiler/log_%a_%H_%M_%S.txt", ptm);
std::strftime(buffer, 32, "/log_%a_%H_%M_%S.txt", ptm);
std::string filename(buffer);
const std::string ABS_PATH = "/home/virre/dev/systemF/org/language/src/GC/";
// const std::string ABS_PATH = "/Users/valtermiari/Desktop/DV/Bachelors/code/language/src/GC";
std::string fullpath = ABS_PATH + filename;
// const std::string ABS_PATH = "/home/virre/dev/systemF/org/language/src/GC/";
// // const std::string ABS_PATH = "/Users/valtermiari/Desktop/DV/Bachelors/code/language/src/GC";
// std::string fullpath = ABS_PATH + filename;
const std::string fullpath = get_log_folder() + filename;
std::ofstream fstr(fullpath);
return fstr;
}
std::string get_log_folder()
{
char buffer[1024];
// chars read from path
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer)-1);
// if readlink fails
if (len == -1)
{
throw std::runtime_error(std::string("Error: readlink failed on '/proc/self/exe/'"));
}
buffer[len] = '\0';
// convert to string for string operators
auto path = std::string(buffer);
// remove filename
size_t last_slash = path.find_last_of('/');
std::string folder = path.substr(0, last_slash);
return folder;
}
}