Module: HeapDump

Defined in:
lib/heap_dump.rb,
lib/heap_dump/version.rb,
ext/heap_dump/heap_dump.c

Constant Summary collapse

VERSION =
"0.0.33"

Class Method Summary collapse

Class Method Details

.count_objects(namespaces_array = [], gc = false) ⇒ Object

provides an object count - like ObjectSpace.count_objects, but also for user classes



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/heap_dump.rb', line 14

def self.count_objects namespaces_array=[], gc=false
  unless namespaces_array.is_a?(Array) && namespaces_array.all?{|v|v.respond_to? :to_s}
    if namespaces_array.respond_to? :to_s
      namespaces_array = [namespaces_array.to_s]
    else
      #TODO: actually, better way is to accept anything convertable, even module itself
      raise ArgumentError.new("namespaces_array must be a symbol/string or array of strings/symbols")
    end
  end
  prefixes_array = namespaces_array.map{|c| c.to_s}
  return count_objects_ext(prefixes_array, !!gc)
end

.count_objects_ext(string_prefixes, do_gc) ⇒ Object



1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
# File 'ext/heap_dump/heap_dump.c', line 1797

static VALUE
rb_heapdump_count_objects(VALUE self, VALUE string_prefixes, VALUE do_gc){
  yajl_gen_config cfg;
  yajl_gen yajl;
  const unsigned char* buf;
  unsigned int len;

  rb_check_array_type(string_prefixes);

  memset(&cfg, 0, sizeof(cfg));
  cfg.beautify = true;
  cfg.htmlSafe = true;
  cfg.indentString = "    ";
  yajl = yajl_gen_alloc(&cfg,NULL);

  heapdump_count_objects_core(yajl, string_prefixes, RTEST(do_gc));

  //flush yajl:
  if(yajl_gen_get_buf(yajl, &buf, &len) == yajl_gen_status_ok){
    //fwrite(buf, len, 1, ctx->file);
    VALUE res = rb_str_new((char*)buf, len);
    yajl_gen_clear(yajl);
    yajl_gen_free(yajl);
    return res;
  } else {
    return Qnil;
  }
}

.dump(filename = 'dump.json', gc_before_dump = true) ⇒ Object

Dumps ruby object space to file



8
9
10
11
# File 'lib/heap_dump.rb', line 8

def self.dump filename='dump.json', gc_before_dump=true
  GC.start if gc_before_dump
  return dump_ext(filename)
end

.dump_ext(filename) ⇒ Object



1700
1701
1702
1703
1704
1705
1706
# File 'ext/heap_dump/heap_dump.c', line 1700

static VALUE
rb_heapdump_dump(VALUE self, VALUE filename)
{
  Check_Type(filename, T_STRING);
  heapdump_dump(RSTRING_PTR(filename));
  return Qnil;
}

.int3Object



1883
1884
1885
1886
# File 'ext/heap_dump/heap_dump.c', line 1883

static VALUE rb_heapdump_trigger_int_3(VALUE self){
  __asm__("int $0x3;");
  return Qnil;
}

.verboseObject



1606
1607
1608
# File 'ext/heap_dump/heap_dump.c', line 1606

static VALUE heapdump_verbose(VALUE self){
  return g_verbose ? Qtrue : Qfalse;
}

.verbose=(verbose) ⇒ Object



1610
1611
1612
1613
# File 'ext/heap_dump/heap_dump.c', line 1610

static VALUE heapdump_verbose_setter(VALUE self, VALUE verbose){
  g_verbose = RTEST(verbose);
  return heapdump_verbose(self);
}