Sha256: 3d3a783a0d59bbb266292f6e9eb5d9578a8e97503a8775e88f19cab4075511b9

Contents?: true

Size: 1.76 KB

Versions: 10

Compression:

Stored size: 1.76 KB

Contents

/* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
   Please see the LICENSE file for copyright and distribution information */

/* :nodoc: */

#include "ruby_prof.h"

static VALUE cMeasureMemory;


#if defined(HAVE_RB_GC_ALLOCATED_SIZE)
  VALUE rb_gc_allocated_size();
#endif

#if defined(HAVE_RB_GC_MALLOC_ALLOCATED_SIZE)
  size_t rb_gc_malloc_allocated_size();
#endif

#if defined(HAVE_RB_HEAP_TOTAL_MEM)
  //FIXME: did not find the patch to check prototype, assuming it to return size_t
  size_t rb_heap_total_mem();
#endif

static double
measure_memory()
{
#if defined(HAVE_RB_GC_ALLOCATED_SIZE)
#define MEASURE_MEMORY_ENABLED Qtrue
#if defined(HAVE_LONG_LONG)
    return NUM2LL(rb_gc_allocated_size()) / 1024.0;
#else
    return NUM2ULONG(rb_gc_allocated_size()) / 1024.0;
#endif

#elif defined(HAVE_RB_GC_MALLOC_ALLOCATED_SIZE)
#define MEASURE_MEMORY_ENABLED Qtrue
    return rb_gc_malloc_allocated_size() / 1024.0;

#elif defined(HAVE_RB_HEAP_TOTAL_MEM)
#define MEASURE_MEMORY_ENABLED Qtrue
    return rb_heap_total_mem() / 1024.0;

#else
#define MEASURE_MEMORY_ENABLED Qfalse
    return 0;
#endif
}

prof_measurer_t* prof_measurer_memory()
{
  prof_measurer_t* measure = ALLOC(prof_measurer_t);
  measure->measure = measure_memory;
  return measure;
}

/* call-seq:
   measure_process_time -> float

Returns the process time.*/
static VALUE
prof_measure_memory(VALUE self)
{
    return rb_float_new(measure_memory());
}

void rp_init_measure_memory()
{
    rb_define_const(mProf, "MEMORY", INT2NUM(MEASURE_MEMORY));
    rb_define_const(mProf, "MEMORY_ENABLED", MEASURE_MEMORY_ENABLED);

    cMeasureMemory = rb_define_class_under(mMeasure, "Memory", rb_cObject);
    rb_define_singleton_method(cMeasureMemory, "measure", prof_measure_memory, 0);
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-prof-0.15.3 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.15.2 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.15.1 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.15.0 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.14.2 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.14.1 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.14.0 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.13.1 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.13.0 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.12.2 ext/ruby_prof/rp_measure_memory.c