Skip to content

Commit

Permalink
A bit more diagnostics cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed May 5, 2016
1 parent 8de5626 commit e6eb8c4
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 166 deletions.
26 changes: 13 additions & 13 deletions machine/capi/handles.cpp
Expand Up @@ -11,10 +11,7 @@

namespace rubinius {
namespace capi {
void Handles::Diagnostics::log() {
logger::write("C-API handles: diagnostics: " \
"objects: %ld, bytes: %ld, collections: %ld\n",
objects_, bytes_, collections_);
void Handles::Diagnostics::update() {
}

Handle* Handles::allocate(STATE, Object* obj) {
Expand All @@ -23,7 +20,7 @@ namespace rubinius {
handle->set_object(obj);
handle->validate();
if(needs_gc) {
diagnostics_.collections_++;
diagnostics()->collections_++;
state->memory()->schedule_full_collection(
"CAPI handles",
state->vm()->metrics().gc.handles_set);
Expand All @@ -44,7 +41,7 @@ namespace rubinius {
handle->set_object(obj);
handle->validate();
if(needs_gc) {
diagnostics_.collections_++;
diagnostics()->collections_++;
state->memory()->schedule_full_collection(
"CAPI handles",
state->vm()->metrics().gc.handles_set);
Expand All @@ -69,15 +66,18 @@ namespace rubinius {
}
}
}

delete allocator_;

if(diagnostics()) delete diagnostics();
}

void Handles::deallocate_handles(std::list<Handle*>* cached,
unsigned int mark, /* BakerGC */ void* young)
{
std::vector<bool> chunk_marks(allocator_->chunks_.size(), false);

diagnostics_.objects_ = 0;
diagnostics()->objects_ = 0;

for(std::vector<int>::size_type i = 0; i < allocator_->chunks_.size(); ++i) {
Handle* chunk = allocator_->chunks_[i];
Expand All @@ -94,7 +94,7 @@ namespace rubinius {
// Strong references will already have been updated.
if(!handle->weak_p()) {
chunk_marks[i] = true;
diagnostics_.objects_++;
diagnostics()->objects_++;
continue;
}

Expand All @@ -107,12 +107,12 @@ namespace rubinius {
// a collection. In this state, valid objects are only in current.
if(young->in_current_p(obj)) {
chunk_marks[i] = true;
diagnostics_.objects_++;
diagnostics()->objects_++;
// A weakref pointing to a forwarded young object
} else if(obj->forwarded_p()) {
handle->set_object(obj->forward());
chunk_marks[i] = true;
diagnostics_.objects_++;
diagnostics()->objects_++;
// A weakref pointing to a dead young object
} else {
handle->clear();
Expand All @@ -121,7 +121,7 @@ namespace rubinius {
// Not a young object, so won't be GC'd so mark
// chunk as still active
chunk_marks[i] = true;
diagnostics_.objects_++;
diagnostics()->objects_++;
}
*/

Expand All @@ -130,7 +130,7 @@ namespace rubinius {
handle->clear();
} else {
chunk_marks[i] = true;
diagnostics_.objects_++;
diagnostics()->objects_++;
}
}
}
Expand All @@ -148,7 +148,7 @@ namespace rubinius {

allocator_->rebuild_freelist(&chunk_marks);

diagnostics_.bytes_ = allocator_->in_use_ * sizeof(Handle);
diagnostics()->bytes_ = allocator_->in_use_ * sizeof(Handle);
}
}
}
8 changes: 4 additions & 4 deletions machine/capi/handles.hpp
Expand Up @@ -24,19 +24,19 @@ namespace rubinius {
, collections_(0)
{ }

void log();
void update();
};

private:
memory::Allocator<Handle>* allocator_;

Diagnostics diagnostics_;
Diagnostics* diagnostics_;

public:

Handles()
: allocator_(new memory::Allocator<Handle>())
, diagnostics_(Diagnostics())
, diagnostics_(new Diagnostics())
{}

~Handles();
Expand All @@ -63,7 +63,7 @@ namespace rubinius {
return allocator_->in_use_;
}

Diagnostics& diagnostics() {
Diagnostics* diagnostics() {
return diagnostics_;
}
};
Expand Down
42 changes: 39 additions & 3 deletions machine/diagnostics.cpp
Expand Up @@ -11,16 +11,47 @@

namespace rubinius {
namespace diagnostics {
DiagnosticsData::DiagnosticsData()
: document_(new rapidjson::Document())
{
/*
document_->SetObject();
document_->AddMember("diagnostic_type",
rapidjson::Value("DiagnosticsData"), document_->GetAllocator());
*/
}

DiagnosticsData::~DiagnosticsData() {
if(document_) delete document_;
}

void DiagnosticsData::to_string(rapidjson::StringBuffer buffer) {
void DiagnosticsData::set_type(const char* type) {
(*document_)["diagnostic_type"].SetString(type, document_->GetAllocator());
}

void DiagnosticsData::to_string(rapidjson::StringBuffer& buffer) {
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);

document_->Accept(writer);
}

MemoryDiagnostics::MemoryDiagnostics()
: DiagnosticsData()
, objects_(0)
, bytes_(0)
{
/*
set_type("MemoryDiagnostics");
document()->AddMember("objects",
rapidjson::Value(objects_), document()->GetAllocator());
document()->AddMember("bytes",
rapidjson::Value(bytes_), document()->GetAllocator());
*/
}

FileEmitter::FileEmitter(STATE, std::string path)
: DiagnosticsEmitter()
, path_(path)
Expand All @@ -38,6 +69,9 @@ namespace rubinius {

void FileEmitter::send_diagnostics(DiagnosticsData* data) {
rapidjson::StringBuffer buffer;

data->to_string(buffer);

size_t size = buffer.GetSize();

if(::write(fd_, buffer.GetString(), size) < size) {
Expand All @@ -52,7 +86,9 @@ namespace rubinius {
, diagnostics_lock_()
, diagnostics_condition_()
{
if(state->shared().config.system_diagnostics_target.value.compare("none")) {
// TODO: socket target
if(false /*state->shared().config.system_diagnostics_target.value.compare("none")*/) {
} else {
emitter_ = new FileEmitter(state,
state->shared().config.system_diagnostics_target.value);
}
Expand Down Expand Up @@ -100,7 +136,7 @@ namespace rubinius {
}

// Emit data
if(emitter_) emitter_->send_diagnostics(data);
if(data) emitter_->send_diagnostics(data);
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions machine/diagnostics.hpp
Expand Up @@ -17,24 +17,26 @@ namespace rubinius {
rapidjson::Document* document_;

public:
DiagnosticsData()
: document_(NULL)
{ }
DiagnosticsData();
virtual ~DiagnosticsData();

void to_string(rapidjson::StringBuffer buffer);
rapidjson::Document* document() {
return document_;
}

virtual void update() { }

void set_type(const char* type);
void to_string(rapidjson::StringBuffer& buffer);
};

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

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

MemoryDiagnostics();
virtual ~MemoryDiagnostics() { }
};

class DiagnosticsEmitter {
Expand Down
4 changes: 0 additions & 4 deletions machine/environment.cpp
Expand Up @@ -216,9 +216,6 @@ namespace rubinius {
finalizer_thread_->start(state);
}

void Environment::start_diagnostics(STATE) {
}

void Environment::start_logging(STATE) {
logger::logger_level level = logger::eWarn;

Expand Down Expand Up @@ -803,7 +800,6 @@ namespace rubinius {

state->vm()->bootstrap_ontology(state);

start_diagnostics(state);
start_finalizer(state);

load_argv(argc_, argv_);
Expand Down
10 changes: 0 additions & 10 deletions machine/environment.hpp
Expand Up @@ -15,9 +15,6 @@

namespace rubinius {

namespace diagnostics {
}

namespace memory {
class FinalizerThread;
}
Expand Down Expand Up @@ -75,8 +72,6 @@ namespace rubinius {

memory::TypedRoot<Object*>* loader_;

diagnostics::Diagnostics* diagnostics_;

public:
SharedState* shared;
VM* root_vm;
Expand Down Expand Up @@ -117,10 +112,6 @@ namespace rubinius {
return loader_->get();
}

diagnostics::Diagnostics* diagnostics() {
return diagnostics_;
}

void set_root_vm(VM* vm) {
root_vm = vm;
state->set_vm(vm);
Expand Down Expand Up @@ -158,7 +149,6 @@ namespace rubinius {
void atexit();

void start_finalizer(STATE);
void start_diagnostics(STATE);

void start_logging(STATE);
void stop_logging(STATE);
Expand Down
9 changes: 0 additions & 9 deletions machine/memory.cpp
Expand Up @@ -77,7 +77,6 @@ namespace rubinius {
, collect_young_flag_(false)
, collect_full_flag_(false)
, shared_(vm->shared)
, diagnostics_(NULL)
, vm_(vm)
, last_object_id(1)
, last_snapshot_id(0)
Expand Down Expand Up @@ -563,20 +562,12 @@ namespace rubinius {
collect_full(state);
}
}

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

void Memory::collect_young(STATE, memory::GCData* data) {
timer::StopWatch<timer::milliseconds> timerx(
state->vm()->metrics().gc.young_ms);

if(state->shared().config.memory_collection_log.value) {
logger::write("memory: young collection");
}

/*
young_->collect(data);
Expand Down
10 changes: 0 additions & 10 deletions machine/memory.hpp
Expand Up @@ -5,7 +5,6 @@
#include "type_info.hpp"
#include "object_position.hpp"
#include "oop.hpp"
#include "diagnostics.hpp"
#include "metrics.hpp"
#include "configuration.hpp"

Expand Down Expand Up @@ -42,9 +41,6 @@ namespace rubinius {
class Slab;
}

namespace diagnostics {
}

namespace capi {
class Handle;
class Handles;
Expand Down Expand Up @@ -137,8 +133,6 @@ namespace rubinius {

SharedState& shared_;

diagnostics::Diagnostics* diagnostics_;

public:
VM* vm_;
/// Counter used for issuing object ids when #object_id is called on a
Expand Down Expand Up @@ -575,10 +569,6 @@ namespace rubinius {
mature_gc_in_progress_ = false;
}

diagnostics::Diagnostics* diagnostics() {
return diagnostics_;
}

memory::MarkStack& mature_mark_stack();

void set_interrupt() {
Expand Down

0 comments on commit e6eb8c4

Please sign in to comment.