Exemplo n.º 1
0
static VALUE
rb_fairy_xmarshaled_queue_store(VALUE self, VALUE buffer)
{
  VALUE tmpbuf;
  VALUE io;
  fairy_xmarshaled_queue_t *mq;

  GetFairyXMarshaledQueuePtr(self, mq);

  if (mq->log_mstore_p) {
    rb_fairy_debug(self, "START M.STORE");
  }
  
  if (NIL_P(mq->buffer_dir)) {
    tmpbuf = rb_funcall(rb_cFairyFastTempfile, id_open, 1,
			rb_str_new2("port-buffer-"));
  }
  else {
    tmpbuf = rb_funcall(rb_cFairyFastTempfile, id_open, 2,
			rb_str_new2("port-buffer-"),
			mq->buffer_dir);
  }
 
  io = rb_funcall(tmpbuf, id_io, 0);
  rb_marshal_dump(buffer, io);
  rb_funcall(tmpbuf, id_close, 0);
  
  if (mq->log_mstore_p) {
    rb_fairy_debug(self, "FINISH M.STORE");
  }
  return tmpbuf;
}
Exemplo n.º 2
0
static VALUE
rb_queue_marshal_dump(VALUE self)
{
    Queue *queue;
    VALUE array;
    Data_Get_Struct(self, Queue, queue);

    array = array_from_list(&queue->values);
    rb_ary_unshift(array, ULONG2NUM(queue->capacity));
    return rb_marshal_dump(array, Qnil);
}
Exemplo n.º 3
0
static VALUE
stackprof_results(int argc, VALUE *argv, VALUE self)
{
    VALUE results, frames;

    if (!_stackprof.frames || _stackprof.running)
	return Qnil;

    results = rb_hash_new();
    rb_hash_aset(results, sym_version, DBL2NUM(1.1));
    rb_hash_aset(results, sym_mode, _stackprof.mode);
    rb_hash_aset(results, sym_interval, _stackprof.interval);
    rb_hash_aset(results, sym_samples, SIZET2NUM(_stackprof.overall_samples));
    rb_hash_aset(results, sym_gc_samples, SIZET2NUM(_stackprof.during_gc));
    rb_hash_aset(results, sym_missed_samples, SIZET2NUM(_stackprof.overall_signals - _stackprof.overall_samples));

    frames = rb_hash_new();
    rb_hash_aset(results, sym_frames, frames);
    st_foreach(_stackprof.frames, frame_i, (st_data_t)frames);

    st_free_table(_stackprof.frames);
    _stackprof.frames = NULL;

    if (_stackprof.raw && _stackprof.raw_samples_len) {
	size_t len, n, o;
	VALUE raw_samples = rb_ary_new_capa(_stackprof.raw_samples_len);

	for (n = 0; n < _stackprof.raw_samples_len; n++) {
	    len = (size_t)_stackprof.raw_samples[n];
	    rb_ary_push(raw_samples, SIZET2NUM(len));

	    for (o = 0, n++; o < len; n++, o++)
		rb_ary_push(raw_samples, rb_obj_id(_stackprof.raw_samples[n]));
	    rb_ary_push(raw_samples, SIZET2NUM((size_t)_stackprof.raw_samples[n]));
	}

	free(_stackprof.raw_samples);
	_stackprof.raw_samples = NULL;
	_stackprof.raw_samples_len = 0;
	_stackprof.raw_samples_capa = 0;
	_stackprof.raw_sample_index = 0;
	_stackprof.raw = 0;

	rb_hash_aset(results, sym_raw, raw_samples);
    }

    if (argc == 1)
	_stackprof.out = argv[0];

    if (RTEST(_stackprof.out)) {
	VALUE file;
	if (RB_TYPE_P(_stackprof.out, T_STRING)) {
	    file = rb_file_open_str(_stackprof.out, "w");
	} else {
	    file = rb_io_check_io(_stackprof.out);
	}
	rb_marshal_dump(results, file);
	rb_io_flush(file);
	_stackprof.out = Qnil;
	return file;
    } else {
	return results;
    }
}
Exemplo n.º 4
0
VALUE marshal_spec_rb_marshal_dump(VALUE self, VALUE obj, VALUE port) {
  return rb_marshal_dump(obj, port);
}