Module: Majo

Defined in:
lib/majo.rb,
lib/majo/result.rb,
lib/majo/version.rb,
lib/majo/colorize.rb,
lib/majo/formatter.rb,
lib/majo/formatter/csv.rb,
lib/majo/allocation_info.rb,
lib/majo/formatter/color.rb,
lib/majo/formatter/monochrome.rb,
ext/majo/majo.c

Defined Under Namespace

Modules: Colorize, Formatter Classes: AllocationInfo, Error, Result

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.__start(upper_lifetime, lower_lifetime) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'ext/majo/majo.c', line 118

static VALUE
start(VALUE self, VALUE upper_lifetime, VALUE lower_lifetime) {
  VALUE res = majo_new_result();
  majo_result *arg = majo_check_result(res);
  arg->upper_lifetime = upper_lifetime;
  arg->lower_lifetime = lower_lifetime;

  VALUE stack = rb_ivar_get(rb_mMajo, running_tracer_stack);
  rb_ary_push(stack, res);

  arg->newobj_trace = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, newobj_i, (void *)res);
  arg->freeobj_trace = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_FREEOBJ, freeobj_i, arg);

  rb_tracepoint_enable(arg->newobj_trace);
  rb_tracepoint_enable(arg->freeobj_trace);

  return res;
}

.__stopObject



137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/majo/majo.c', line 137

static VALUE
stop(VALUE self)
{
  VALUE stack = rb_ivar_get(rb_mMajo, running_tracer_stack);
  VALUE res = rb_ary_pop(stack);
  majo_result *arg = majo_check_result(res);

  rb_tracepoint_disable(arg->newobj_trace);
  rb_tracepoint_disable(arg->freeobj_trace);

  return res;
}

.run(upper_lifetime: nil, lower_lifetime: 1) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/majo.rb', line 32

def self.run(upper_lifetime: nil, lower_lifetime: 1)
  r = start(upper_lifetime:, lower_lifetime:)
  yield
  r
ensure
  stop
end

.start(upper_lifetime: nil, lower_lifetime: 1) ⇒ Object



13
14
15
16
17
18
# File 'lib/majo.rb', line 13

def self.start(upper_lifetime: nil, lower_lifetime: 1)
  GC.start
  GC.start
  GC.start
  __start(upper_lifetime, lower_lifetime)
end

.stopObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/majo.rb', line 20

def self.stop
  GC.start
  GC.start
  GC.start
  res = __stop

  # Collect retained objcects
  ObjectSpace.each_object do |obj|
    res.store_retained_object(obj)
  end
end