Skip to content

Commit

Permalink
Added dtrace probe for tracing object allocations.
Browse files Browse the repository at this point in the history
This currently only traces classes allocated in the Ruby side of things. String,
Array and other allocations are not yet tracked.
  • Loading branch information
Yorick Peterse committed Nov 6, 2014
1 parent 9fec1fd commit f99c365
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions vm/builtin/class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "object_utils.hpp"
#include "object_memory.hpp"
#include "on_stack.hpp"
#include "call_frame.hpp"
#include "dtrace/dtrace.h"

namespace rubinius {

Expand Down Expand Up @@ -139,6 +141,9 @@ namespace rubinius {
#ifdef RBX_GC_STRESS
state->shared().gc_soon();
#endif

RUBINIUS_OBJECT_ALLOCATE_HOOK(state, new_obj, calling_environment);

return new_obj;
} else if(!type_info_->allow_user_allocate || kind_of<SingletonClass>(this)) {
std::ostringstream msg;
Expand All @@ -165,6 +170,9 @@ namespace rubinius {
#ifdef RBX_GC_STRESS
state->shared().gc_soon();
#endif

RUBINIUS_OBJECT_ALLOCATE_HOOK(state, new_obj, calling_environment);

return new_obj;
} else {
// type_info_->type is neither PackedObject nor Object, so use the
Expand All @@ -179,6 +187,9 @@ namespace rubinius {
#ifdef RBX_GC_STRESS
state->shared().gc_soon();
#endif

RUBINIUS_OBJECT_ALLOCATE_HOOK(state, new_obj, calling_environment);

return new_obj;
}
}
Expand Down
20 changes: 20 additions & 0 deletions vm/dtrace/dtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@
} \
} \

#define RUBINIUS_OBJECT_ALLOCATE_HOOK(state, obj, frame) \
{ \
if(RUBINIUS_OBJECT_ALLOCATE_ENABLED()) { \
Class* mod = obj->direct_class(state); \
RBX_DTRACE_CONST char* module_name = \
const_cast<RBX_DTRACE_CONST char*>(mod->debug_str(state).c_str()); \
RBX_DTRACE_CONST char* file_name = \
const_cast<RBX_DTRACE_CONST char *>("<unknown>"); \
int line = 0; \
if(frame) { \
Symbol* file = frame->file(state); \
if(!file->nil_p()) { \
file_name = const_cast<RBX_DTRACE_CONST char*>(file->debug_str(state).c_str()); \
} \
line = frame->line(state); \
} \
RUBINIUS_OBJECT_ALLOCATE(module_name, file_name, line); \
} \
} \

#else
#include "dtrace/probes_dummy.h"
#define RUBINIUS_METHOD_HOOK(probe, state, mod, method, previous) do { } while(0)
Expand Down
11 changes: 11 additions & 0 deletions vm/dtrace/probes.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ provider rubinius {
*/
probe gc__end(int full);

/*
rubinius::object-allocate(classname, filename, lineno)
Fired when a new object is allocated
* `classname` the name of the class/module that was allocated
* `filename` the path to the file where the object was allocated
* `lineno` the line number of the allocation
*/
probe object__allocate(const char *, const char *, int);

/*
rubinius:::thread-start(thread_id);
Expand Down
2 changes: 2 additions & 0 deletions vm/dtrace/probes_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern "C" {
#define RUBINIUS_THREAD_STOP_ENABLED() 0
#define RUBINIUS_THREAD_STOP(arg0, arg1, arg2) do { } while(0)

#define RUBINIUS_OBJECT_ALLOCATE_ENABLED() 0
#define RUBINIUS_OBJECT_ALLOCATE(arg0, arg1. arg2) do { } while(0)

#define RUBINIUS_JIT_FUNCTION_BEGIN_ENABLED() 0
#define RUBINIUS_JIT_FUNCTION_BEGIN(arg0, arg1, arg2, arg3) do { } while(0)
Expand Down

0 comments on commit f99c365

Please sign in to comment.