Skip to content

Commit

Permalink
Added a few more machine metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Apr 10, 2016
1 parent e7dcab3 commit f95ebcf
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 9 deletions.
6 changes: 6 additions & 0 deletions machine/builtin/code_db.cpp
Expand Up @@ -5,13 +5,16 @@
#include "on_stack.hpp"
#include "ontology.hpp"
#include "marshal.hpp"
#include "metrics.hpp"
#include "thread_phase.hpp"

#include "builtin/class.hpp"
#include "builtin/code_db.hpp"
#include "builtin/compiled_code.hpp"
#include "builtin/string.hpp"

#include "instruments/timing.hpp"

#include "util/thread.hpp"

#include <fcntl.h>
Expand Down Expand Up @@ -148,6 +151,9 @@ namespace rubinius {
CompiledCode* CodeDB::load(STATE, const char* m_id) {
MutexLockUnmanaged guard(state, state->shared().codedb_lock());

timer::StopWatch<timer::microseconds> timer(
state->vm()->metrics().codedb.load_us);

CodeDBMap::const_iterator index = codedb_index.find(std::string(m_id));

if(index == codedb_index.end()) {
Expand Down
3 changes: 3 additions & 0 deletions machine/builtin/compiled_code.cpp
Expand Up @@ -113,6 +113,9 @@ namespace rubinius {
}

MachineCode* CompiledCode::internalize(STATE) {
timer::StopWatch<timer::microseconds> timer(
state->vm()->metrics().machine.bytecode_internalizer_us);

MachineCode* mcode = machine_code();

atomic::memory_barrier();
Expand Down
2 changes: 1 addition & 1 deletion machine/builtin/system.cpp
Expand Up @@ -142,7 +142,7 @@ namespace rubinius {
return Primitives::failure();
}

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
if(cf->magic != "!RBIX") {
delete cf;
return Primitives::failure();
Expand Down
3 changes: 3 additions & 0 deletions machine/bytecode_verifier.cpp
Expand Up @@ -98,6 +98,9 @@ namespace rubinius {
}

void BytecodeVerifier::verify(STATE) {
timer::StopWatch<timer::microseconds> timer(
state->vm()->metrics().machine.bytecode_verifier_us);

// Do this setup here instead of the constructor so we can do
// some validation of the CompiledCode's fields we read them.

Expand Down
8 changes: 7 additions & 1 deletion machine/compiled_file.cpp
Expand Up @@ -17,8 +17,14 @@
#include "memory.hpp"
#include "object_utils.hpp"

#include "instruments/timing.hpp"


namespace rubinius {
CompiledFile* CompiledFile::load(std::istream& stream) {
CompiledFile* CompiledFile::load(STATE, std::istream& stream) {
timer::StopWatch<timer::microseconds> timer(
state->vm()->metrics().machine.bytecode_load_us);

std::string magic;
uint64_t signature;
int version;
Expand Down
2 changes: 1 addition & 1 deletion machine/compiled_file.hpp
Expand Up @@ -29,7 +29,7 @@ namespace rubinius {
, stream(stream)
{}

static CompiledFile* load(std::istream& stream);
static CompiledFile* load(STATE, std::istream& stream);
Object* body(STATE);
bool execute(STATE);
};
Expand Down
2 changes: 1 addition & 1 deletion machine/drivers/compile.cpp
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char** argv) {

ifstream stream(input.c_str());

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(env.state, stream);
if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");

CompiledCode* meth = as<CompiledCode>(cf->body(env.state));
Expand Down
2 changes: 1 addition & 1 deletion machine/drivers/jit-test.cpp
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char **argv) {
return 1;
}

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
if(cf->magic != "!RBIX") {
cout << "Invalid file.\n";
}
Expand Down
2 changes: 1 addition & 1 deletion machine/environment.cpp
Expand Up @@ -528,7 +528,7 @@ namespace rubinius {
throw std::runtime_error(msg);
}

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
if(cf->magic != "!RBIX") {
std::ostringstream msg;
msg << "attempted to open a bytecode file with invalid magic identifier"
Expand Down
6 changes: 6 additions & 0 deletions machine/metrics.cpp
Expand Up @@ -362,6 +362,12 @@ namespace rubinius {
"machine.methods.invoked", metrics_data_.machine.methods_invoked));
metrics_map_.push_back(new MetricsItem(
"machine.blocks.invoked", metrics_data_.machine.blocks_invoked));
metrics_map_.push_back(new MetricsItem(
"machine.bytecode.load.us", metrics_data_.machine.bytecode_load_us));
metrics_map_.push_back(new MetricsItem(
"machine.bytecode.verifier.us", metrics_data_.machine.bytecode_verifier_us));
metrics_map_.push_back(new MetricsItem(
"machine.bytecode.internalizer.us", metrics_data_.machine.bytecode_internalizer_us));

// Memory metrics
metrics_map_.push_back(new MetricsItem(
Expand Down
9 changes: 9 additions & 0 deletions machine/metrics.hpp
Expand Up @@ -167,6 +167,9 @@ namespace rubinius {
metric backtrace_us;
metric methods_invoked;
metric blocks_invoked;
metric bytecode_load_us;
metric bytecode_verifier_us;
metric bytecode_internalizer_us;

MachineMetrics() {
checkpoints = 0;
Expand All @@ -176,6 +179,9 @@ namespace rubinius {
backtrace_us = 0;
methods_invoked = 0;
blocks_invoked = 0;
bytecode_load_us = 0;
bytecode_verifier_us = 0;
bytecode_internalizer_us = 0;
}

void add(MachineMetrics& data) {
Expand All @@ -186,6 +192,9 @@ namespace rubinius {
backtrace_us += data.backtrace_us;
methods_invoked += data.methods_invoked;
blocks_invoked += data.blocks_invoked;
bytecode_load_us += data.bytecode_load_us;
bytecode_verifier_us += data.bytecode_verifier_us;
bytecode_internalizer_us += data.bytecode_internalizer_us;
}
};

Expand Down
6 changes: 3 additions & 3 deletions machine/test/test_compiled_file.hpp
Expand Up @@ -30,7 +30,7 @@ class TestCompiledFile : public CxxTest::TestSuite, public VMTest {
std::istringstream stream;
stream.str("!RBIX\n1\n42\nt");

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
TS_ASSERT_EQUALS(cf->magic, std::string("!RBIX"));
TS_ASSERT_EQUALS(cf->signature, 1ULL);
TS_ASSERT_EQUALS(cf->version, 42);
Expand All @@ -41,15 +41,15 @@ class TestCompiledFile : public CxxTest::TestSuite, public VMTest {
std::istringstream stream;
stream.str("!RBIX\n1\n42\nt");

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
TS_ASSERT_EQUALS(cf->body(state), cTrue);
}

void test_load_file() {
std::fstream stream("machine/test/fixture.rbc_");
TS_ASSERT(!!stream);

CompiledFile* cf = CompiledFile::load(stream);
CompiledFile* cf = CompiledFile::load(state, stream);
TS_ASSERT_EQUALS(cf->magic, "!RBIX");

CompiledCode* code = try_as<CompiledCode>(cf->body(state));
Expand Down

0 comments on commit f95ebcf

Please sign in to comment.