Ejemplo n.º 1
0
static mrb_value Cache__shm_status(mrb_state *mrb, mrb_value self)
{
  mrb_value hash = mrb_hash_new(mrb);

  local_memcache_t *lmc = get_Cache(mrb, self);
  if (!lmc_lock_shm_region("shm_status", lmc))
    return mrb_nil_value();
  lmc_mem_status_t ms = lmc_status(lmc->base, "shm_status");
  if (!lmc_unlock_shm_region("shm_status", lmc))
    return mrb_nil_value();

  mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "free_bytes")), mrb_fixnum_value(ms.total_free_mem));
  mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "total_bytes")), mrb_fixnum_value(ms.total_shm_size));
  mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "used_bytes")),
               mrb_fixnum_value(ms.total_shm_size - ms.total_free_mem));
  mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "free_chunks")), mrb_fixnum_value(ms.free_chunks));
  mrb_hash_set(mrb, hash, mrb_symbol_value(mrb_intern_cstr(mrb, "largest_chunk")), mrb_fixnum_value(ms.largest_chunk));
  return hash;
}
Ejemplo n.º 2
0
/* 
 *  call-seq:
 *     lmc.shm_status -> hash
 *
 *  Some status information on the shared memory:
 *
 *    :total_bytes # the total size of the shm in bytes 
 *    :used_bytes  # how many bytes are used in this shm 
 *                 # For exmpty namespaces this will reflect the amount
 *                 # of memory used for the hash buckets and some other 
 *                 # administrative data structures.
 *    :free_bytes  # how many bytes are free 
 */
static VALUE LocalMemCache__shm_status(VALUE obj) {
  VALUE hash = rb_hash_new();
  
  local_memcache_t *lmc = get_LocalMemCache(obj);
  if (!lmc_lock_shm_region("shm_status", lmc)) return Qnil;
  lmc_mem_status_t ms = lmc_status(lmc->base, "shm_status");
  if (!lmc_unlock_shm_region("shm_status", lmc)) return Qnil;

  rb_hash_aset(hash, ID2SYM(rb_intern("free_bytes")), 
      rb_int2big(ms.total_free_mem));
  rb_hash_aset(hash, ID2SYM(rb_intern("total_bytes")), 
      rb_int2big(ms.total_shm_size));
  rb_hash_aset(hash, ID2SYM(rb_intern("used_bytes")), rb_int2big(
      ms.total_shm_size - ms.total_free_mem));
  rb_hash_aset(hash, ID2SYM(rb_intern("free_chunks")), rb_int2big(
      ms.free_chunks));
  rb_hash_aset(hash, ID2SYM(rb_intern("largest_chunk")), rb_int2big(
      ms.largest_chunk));
  return hash;
}