Class: Majo::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/majo/result.rb,
ext/majo/result.c

Instance Method Summary collapse

Instance Method Details

#allocationsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'ext/majo/result.c', line 76

static VALUE
majo_result_allocations(VALUE self) {
  majo_result *res = majo_check_result(self);
  VALUE ary = rb_ary_new_capa(rb_darray_size(res->olds));

  majo_allocation_info *info_ptr;
  rb_darray_foreach(res->olds, i, info_ptr) {
    VALUE v = majo_new_allocation_info(info_ptr);
    rb_ary_push(ary, v);
  }

  return ary;
}

#report(out: $stdout, formatter: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/majo/result.rb', line 3

def report(out: $stdout, formatter: nil)
  fmt =
    case formatter
    when :color
      Formatter::Color
    when :csv
      Formatter::CSV
    when :monochrome
      Formatter::Monochrome
    when nil
      if out.respond_to?(:tty?) && out.tty?
        Formatter::Color
      else
        Formatter::Monochrome
      end
    else
      raise "unknown formatter: #{formatter.inspect}"
    end

  with_output(out) do |io|
    io.puts fmt.new(self).call
  end
end

#retainedObject



90
91
92
93
94
# File 'ext/majo/result.c', line 90

static VALUE
majo_result_retained(VALUE self) {
  majo_result *res = majo_check_result(self);
  return res->retained;
}

#store_retained_object(obj) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'ext/majo/result.c', line 96

static VALUE
majo_result_store_retained_object(VALUE self, VALUE obj) {
  majo_result *res = majo_check_result(self);

  st_data_t value;
  if (st_lookup(res->object_table, (st_data_t)obj, &value)) {
    majo_allocation_info *info = (majo_allocation_info *)value;
    int lifetime = (int)(rb_gc_count() - info->alloc_generation - 1);
    if (NIL_P(res->upper_lifetime) || lifetime <= NUM2INT(res->upper_lifetime)) {
      info->memsize = rb_obj_memsize_of(obj);

      VALUE info_r = majo_new_allocation_info(info);
      rb_ary_push(res->retained, info_r);
    }
  }

  return Qnil;
}