Skip to content

Commit

Permalink
Added Diagnostics thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed May 2, 2016
1 parent 19e5f98 commit b048f88
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 16 deletions.
2 changes: 1 addition & 1 deletion machine/capi/handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace rubinius {
void Handles::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("C-API handles: diagnostics: " \
"objects: %ld, bytes: %ld, collections: %ld\n",
Expand Down
50 changes: 50 additions & 0 deletions machine/diagnostics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "vm.hpp"
#include "state.hpp"
#include "diagnostics.hpp"

namespace rubinius {
namespace diagnostics {
Diagnostics::Diagnostics(STATE)
: InternalThread(state, "rbx.diagnostics", InternalThread::eSmall)
, list_()
, diagnostics_lock_()
, diagnostics_condition_()
{
}

void Diagnostics::initialize(STATE) {
InternalThread::initialize(state);

diagnostics_lock_.init();
}

void Diagnostics::wakeup(STATE) {
InternalThread::wakeup(state);
}

void Diagnostics::after_fork_child(STATE) {
InternalThread::after_fork_child(state);
}

void Diagnostics::run(STATE) {
state->vm()->become_unmanaged();

while(!thread_exit_) {
DiagnosticsData* data = 0;

{
utilities::thread::Mutex::LockGuard guard(diagnostics_lock_);

if(list_.empty()) {
diagnostics_condition_.wait(diagnostics_lock_);
} else {
data = list_.back();
list_.pop_back();
}
}

// Emit data
}
}
}
}
39 changes: 30 additions & 9 deletions machine/diagnostics.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef RBX_DIAGNOSTICS_HPP
#define RBX_DIAGNOSTICS_HPP

#include "internal_threads.hpp"

#include "util/thread.hpp"

#include <stdint.h>
#include <list>

namespace rubinius {
namespace diagnostics {
class Diagnostics {
class DiagnosticsData {
bool modified_;

public:
Diagnostics() : modified_(false) { }
virtual ~Diagnostics() { }

virtual void log() {
modified_ = false;
}
DiagnosticsData() : modified_(false) { }

bool modified_p() {
return modified_;
Expand All @@ -23,19 +23,40 @@ namespace rubinius {
void modify() {
modified_ = true;
}

void log() {
}
};

class MemoryDiagnostics : public Diagnostics {
class MemoryDiagnostics : public DiagnosticsData {
public:
int64_t objects_;
int64_t bytes_;

MemoryDiagnostics()
: Diagnostics()
: DiagnosticsData()
, objects_(0)
, bytes_(0)
{ }
};

typedef std::list<DiagnosticsData*> DiagnosticsList;

class Diagnostics : public InternalThread {
DiagnosticsList list_;

utilities::thread::Mutex diagnostics_lock_;
utilities::thread::Condition diagnostics_condition_;

public:
Diagnostics(STATE);
virtual ~Diagnostics() { }

void initialize(STATE);
void run(STATE);
void wakeup(STATE);
void after_fork_child(STATE);
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion machine/memory/code_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace memory {
void CodeManager::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("code manager: diagnostics: " \
"collections: %ld, chunks: %ld, objects: %ld, bytes: %ld",
Expand Down
2 changes: 1 addition & 1 deletion machine/memory/immix_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace memory {
void ImmixGC::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("immix: diagnostics: " \
"collections: %ld, " \
Expand Down
3 changes: 2 additions & 1 deletion machine/memory/immix_marker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace memory {
state->memory()->collect_full_restart(state, data_);

if(state->shared().config.memory_collection_log.value) {
state->shared().env()->diagnostics()->log();
// TODO: diagnostics
// state->shared().env()->diagnostics()->log();
}

continue;
Expand Down
2 changes: 1 addition & 1 deletion machine/memory/inflated_headers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace memory {
void InflatedHeaders::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("inflated headers: diagnostics: " \
"objects: %ld, bytes: %ld, collections: %ld\n",
Expand Down
2 changes: 1 addition & 1 deletion machine/memory/mark_sweep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace memory {
void MarkSweepGC::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("large objects: diagnostics: objects: %ld, bytes: %ld",
objects_, bytes_);
Expand Down
2 changes: 1 addition & 1 deletion machine/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace rubinius {
void SymbolTable::Diagnostics::log() {
if(!modified_p()) return;

diagnostics::Diagnostics::log();
diagnostics::DiagnosticsData::log();

logger::write("symbol table: diagnostics: symbols: %ld, bytes: %ld",
objects_, bytes_);
Expand Down

0 comments on commit b048f88

Please sign in to comment.