Fixed ABS_PATH for profiler
This commit is contained in:
parent
fcae79ce0b
commit
ffdffc475d
6 changed files with 99 additions and 24 deletions
|
|
@ -60,6 +60,6 @@ namespace GC
|
||||||
GCEventType get_type();
|
GCEventType get_type();
|
||||||
std::time_t get_time_stamp();
|
std::time_t get_time_stamp();
|
||||||
Chunk *get_chunk();
|
Chunk *get_chunk();
|
||||||
const char *type_to_string();
|
const char *const type_to_string();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@ namespace GC {
|
||||||
std::vector<GCEvent *> m_events;
|
std::vector<GCEvent *> m_events;
|
||||||
|
|
||||||
std::ofstream create_file_stream();
|
std::ofstream create_file_stream();
|
||||||
|
std::string get_log_folder();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void record(GCEventType type);
|
static void record(GCEventType type);
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,12 @@ namespace GC
|
||||||
return m_chunk;
|
return m_chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to remove inline
|
const char *const GCEvent::type_to_string()
|
||||||
const char *GCEvent::type_to_string()
|
|
||||||
{
|
{
|
||||||
switch (m_type)
|
switch (m_type)
|
||||||
{
|
{
|
||||||
|
case HeapInit: return "HeapInit";
|
||||||
|
case AllocStart: return "AllocStart";
|
||||||
case CollectStart: return "CollectStart";
|
case CollectStart: return "CollectStart";
|
||||||
case MarkStart: return "MarkStart";
|
case MarkStart: return "MarkStart";
|
||||||
case ChunkMarked: return "ChunkMarked";
|
case ChunkMarked: return "ChunkMarked";
|
||||||
|
|
@ -36,6 +37,7 @@ namespace GC
|
||||||
case ChunkFreed: return "ChunkFreed";
|
case ChunkFreed: return "ChunkFreed";
|
||||||
case NewChunk: return "NewChunk";
|
case NewChunk: return "NewChunk";
|
||||||
case ReusedChunk: return "ReusedChunk";
|
case ReusedChunk: return "ReusedChunk";
|
||||||
|
case ProfilerDispose: return "ProfilerDispose";
|
||||||
default: return "[Unknown]";
|
default: return "[Unknown]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,9 @@ namespace GC
|
||||||
{
|
{
|
||||||
set_profiler(true);
|
set_profiler(true);
|
||||||
|
|
||||||
if (Heap::get_profiler_mode())
|
auto heap = Heap::the();
|
||||||
|
|
||||||
|
if (heap->profiler_enabled())
|
||||||
Profiler::record(CollectStart);
|
Profiler::record(CollectStart);
|
||||||
|
|
||||||
cout << "DEBUG COLLECT\nFLAGS: ";
|
cout << "DEBUG COLLECT\nFLAGS: ";
|
||||||
|
|
@ -434,8 +436,6 @@ namespace GC
|
||||||
cout << "\n - FREE";
|
cout << "\n - FREE";
|
||||||
cout << "\n";
|
cout << "\n";
|
||||||
|
|
||||||
auto heap = Heap::the();
|
|
||||||
|
|
||||||
// get the frame adress, whwere local variables and saved registers are located
|
// get the frame adress, whwere local variables and saved registers are located
|
||||||
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
auto stack_bottom = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
|
||||||
cout << "Stack bottom in collect:\t" << stack_bottom << "\n";
|
cout << "Stack bottom in collect:\t" << stack_bottom << "\n";
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "chunk.hpp"
|
#include "chunk.hpp"
|
||||||
#include "event.hpp"
|
#include "event.hpp"
|
||||||
|
|
@ -80,17 +82,46 @@ namespace GC
|
||||||
|
|
||||||
std::ofstream Profiler::create_file_stream()
|
std::ofstream Profiler::create_file_stream()
|
||||||
{
|
{
|
||||||
|
// get current time
|
||||||
std::time_t tt = std::time(NULL);
|
std::time_t tt = std::time(NULL);
|
||||||
std::tm *ptm = std::localtime(&tt);
|
std::tm *ptm = std::localtime(&tt);
|
||||||
|
|
||||||
|
// format to string
|
||||||
char buffer[32];
|
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);
|
std::string filename(buffer);
|
||||||
|
|
||||||
const std::string ABS_PATH = "/home/virre/dev/systemF/org/language/src/GC/";
|
// 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";
|
// // const std::string ABS_PATH = "/Users/valtermiari/Desktop/DV/Bachelors/code/language/src/GC";
|
||||||
std::string fullpath = ABS_PATH + filename;
|
// std::string fullpath = ABS_PATH + filename;
|
||||||
|
|
||||||
|
const std::string fullpath = get_log_folder() + filename;
|
||||||
|
|
||||||
std::ofstream fstr(fullpath);
|
std::ofstream fstr(fullpath);
|
||||||
return fstr;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,24 +3,66 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void time_string(char *buffer);
|
||||||
|
void print_log_file(const std::string TESTS_PATH);
|
||||||
|
void readlink_test();
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char buffer[31];
|
// char time_buffer[31];
|
||||||
|
// time_string(time_buffer);
|
||||||
|
|
||||||
|
// const std::string TESTS_PATH = "/home/virre/dev/systemF/org/language/src/GC/tests/";
|
||||||
|
// print_log_file(TESTS_PATH);
|
||||||
|
|
||||||
|
readlink_test();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void time_string(char *const buffer)
|
||||||
|
{
|
||||||
std::time_t tt = std::time(NULL);
|
std::time_t tt = std::time(NULL);
|
||||||
std::tm *ptm = std::localtime(&tt);
|
std::tm *ptm = std::localtime(&tt);
|
||||||
std::strftime(buffer, 31, "/logs/log_%a_%H_%M_%S.txt", ptm);
|
std::strftime(buffer, 31, "/logs/log_%a_%H_%M_%S.txt", ptm);
|
||||||
std::cout << buffer << std::endl;
|
std::cout << buffer << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string TESTS_PATH = "/home/virre/dev/systemF/org/language/src/GC/tests/";
|
void print_log_file(const std::string TESTS_PATH)
|
||||||
|
{
|
||||||
std::string path = TESTS_PATH + "/testlog.txt";
|
std::string path = TESTS_PATH + "/testlog.txt";
|
||||||
|
|
||||||
std::ofstream testF(path);
|
std::ofstream testF(path);
|
||||||
|
|
||||||
testF << "hellow yorld";
|
testF << "hellow york";
|
||||||
|
|
||||||
testF.close();
|
testF.close();
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
|
void readlink_test()
|
||||||
|
{
|
||||||
|
char buffer[1024];
|
||||||
|
ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer)-1);
|
||||||
|
if (len == -1)
|
||||||
|
{
|
||||||
|
std::cout << "readlink error" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[len] = '\0';
|
||||||
|
std::cout << "readlink:\n" << "'''" << buffer << "'''"; // << std::endl;
|
||||||
|
|
||||||
|
auto path = std::string(buffer);
|
||||||
|
std::cout << path << "\nlen: " << path.size() << "\ncap:" << path.capacity();
|
||||||
|
|
||||||
|
size_t last_slash = path.find_last_of('/');
|
||||||
|
std::string folder = path.substr(0, last_slash);
|
||||||
|
|
||||||
|
std::cout << "\n" << folder;
|
||||||
|
|
||||||
|
std::string log_path = folder + "/log_file_bla.txt";
|
||||||
|
std::cout << "\n" << log_path << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue