Sha256: fb95ccf0e5c13fc8dea8012b1f31196f09694405f05a648a31cd6c734ecc52f2

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

/* Copyright (C) 2005-2011 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)
#define TOGGLE_GC_STATS 1
#define MEASURE_GC_TIME_ENABLED Qtrue

static double
measure_memory()
{
#if defined(HAVE_LONG_LONG)
    return NUM2LL(rb_gc_allocated_size() / 1024);
#else
    return NUM2ULONG(rb_gc_allocated_size() / 1024);
#endif
}

#elif defined(HAVE_RB_GC_MALLOC_ALLOCATED_SIZE)

#define MEASURE_MEMORY_ENABLED Qtrue

static double
measure_memory()
{
    return rb_gc_malloc_allocated_size() / 1024;
}


#elif defined(HAVE_RB_HEAP_TOTAL_MEM)

#define MEASURE_MEMORY_ENABLED Qtrue

static double
measure_memory()
{
    return rb_heap_total_mem() / 1024;
}

#else

#define MEASURE_MEMORY_ENABLED Qfalse

static double
measure_memory()
{
    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

4 entries across 4 versions & 1 rubygems

Version Path
ruby-prof-0.11.0.rc3-x86-mingw32 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.11.0.rc3 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.11.0.rc2-x86-mingw32 ext/ruby_prof/rp_measure_memory.c
ruby-prof-0.11.0.rc2 ext/ruby_prof/rp_measure_memory.c