This commit is contained in:
Victor Olin 2023-03-21 17:35:33 +01:00
parent 7105c570d9
commit 87dc0fef2d
6 changed files with 135 additions and 5 deletions

View file

@ -7,27 +7,54 @@
namespace GC
{
/**
* @returns The type of the event
*/
GCEventType GCEvent::get_type()
{
return m_type;
}
/**
* @returns The time the event happened in
* the form of time_t.
*/
std::time_t GCEvent::get_time_stamp()
{
return m_timestamp;
}
/**
* If the event is related to a chunk, this
* function returns the chunk that it is
* related to. If the event is independent
* of a chunk, it returns the nullptr.
*
* @returns A chunk pointer or the nullptr.
*/
const Chunk *GCEvent::get_chunk()
{
return m_chunk;
}
/**
* If the event is an AllocStart event, this
* returns the size of the alloc() request.
* otherwise this returns 0.
*
* @returns A number representing the number
* of bytes requested to alloc()
* or 0 if the event is not an
* AllocStart event.
*/
size_t GCEvent::get_size()
{
return m_size;
}
/**
* @returns The string conversion of the event type.
*/
const char *GCEvent::type_to_string()
{
switch (m_type)

View file

@ -13,6 +13,11 @@
namespace GC
{
/**
* Records an event independent of a chunk.
*
* @param type The type of event to record.
*/
void Profiler::record(GCEventType type)
{
auto event = new GCEvent(type);
@ -20,6 +25,14 @@ namespace GC
profiler->m_events.push_back(event);
}
/**
* This overload is only used with an AllocStart
* event.
*
* @param type The type of event to record.
*
* @param size The size of requested to alloc().
*/
void Profiler::record(GCEventType type, size_t size)
{
auto event = new GCEvent(type, size);
@ -27,6 +40,14 @@ namespace GC
profiler->m_events.push_back(event);
}
/**
* Records an event related to a chunk.
*
* @param type The type of event to record.
*
* @param chunk The chunk the event is connected
* to.
*/
void Profiler::record(GCEventType type, Chunk *chunk)
{
// Create a copy of chunk to store in the profiler
@ -39,6 +60,10 @@ namespace GC
profiler->m_events.push_back(event);
}
/**
* Prints the history of the recorded events
* to a log file in the /tests/logs folder.
*/
void Profiler::dump_trace()
{
auto profiler = Profiler::the();
@ -85,6 +110,12 @@ namespace GC
fstr << "--------------------------------" << std::endl;
}
/**
* Deletes the profiler singleton and all
* the events recorded after recording
* the ProfilerDispose event and dumping
* the history to a log file.
*/
void Profiler::dispose()
{
Profiler::record(ProfilerDispose);
@ -93,6 +124,13 @@ namespace GC
delete profiler;
}
/**
* Creates a filestream for the future
* log file to print the history to in
* dump_trace().
*
* @returns The output stream to the file.
*/
std::ofstream Profiler::create_file_stream()
{
// get current time
@ -114,6 +152,15 @@ namespace GC
return fstr;
}
/**
* This function retrieves the current path of the
* executable to use for log files.
*
* @returns The path to the logs folder.
*
* @throws A runtime error if the call
* to readlink() fails.
*/
std::string Profiler::get_log_folder()
{
char buffer[1024];