-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added experimental allocation tracer.
This currently segfaults Rbx for string types (at least whenever the traced object is referenced). It's also a giant hack, but that's why I'm calling it experimental.
Yorick Peterse
committed
Oct 18, 2014
1 parent
808e0f3
commit 613ca11
Showing
10 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Rubinius | ||
## | ||
# | ||
module AllocationTracer | ||
@lock = Mutex.new | ||
|
||
def self.tracers | ||
return @tracers ||= [] | ||
end | ||
|
||
def self.add_tracer(&block) | ||
@lock.synchronize { tracers << block } | ||
end | ||
|
||
def self.trace(object) | ||
@lock.synchronize do | ||
tracers.each do |tracer| | ||
tracer.call(object) | ||
end | ||
end | ||
end | ||
end # AllocationTracer | ||
end # Rubinius |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ ffi.rbc | |
ruby_constants.rbc | ||
pack.rbc | ||
metrics.rbc | ||
allocation_tracer.rbc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "builtin/class.hpp" | ||
#include "builtin/array.hpp" | ||
#include "builtin/string.hpp" | ||
#include "builtin/native_method.hpp" | ||
#include "builtin/allocation_tracer.hpp" | ||
|
||
#include "ontology.hpp" | ||
#include "object_utils.hpp" | ||
|
||
namespace rubinius { | ||
void AllocationTracer::init(STATE) { | ||
GO(allocation_tracer).set(ontology::new_module(state, "AllocationTracer", G(rubinius))); | ||
} | ||
|
||
Object* AllocationTracer::trace(STATE, CallFrame* call_frame, Object *object) { | ||
Module* mod = G(allocation_tracer); | ||
Symbol* sym_trace = state->symbol("trace"); | ||
Array* args; | ||
|
||
// We'll use the method once its defined in Ruby, saving us quite some C++ | ||
// code. | ||
if(CBOOL(mod->respond_to(state, sym_trace, cFalse))) { | ||
args = Array::create(state, 1); | ||
|
||
args->set(state, 0, object); | ||
|
||
mod->send(state, call_frame, sym_trace, args); | ||
} | ||
|
||
return cNil; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef RBX_ALLOCATION_TRACER_HPP | ||
#define RBX_ALLOCATION_TRACER_HPP | ||
|
||
#include "builtin/object.hpp" | ||
|
||
namespace rubinius { | ||
class AllocationTracer : public Object { | ||
public: | ||
static void init(STATE); | ||
|
||
static Object* trace(STATE, CallFrame* call_frame, Object *object); | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters