Class: RubyProf::Measurement

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-prof/measurement.rb,
ext/ruby_prof/rp_measurement.c

Overview

The Measurement class is a helper class used by RubyProf::MethodInfo to store information about the method. You cannot create a CallTree object directly, they are generated while running a profile.

Instance Method Summary collapse

Constructor Details

#new(total_time, self_time, wait_time, called) ⇒ Measurement

Creates a new measuremen instance.



59
60
61
62
63
64
65
66
67
68
69
# File 'ext/ruby_prof/rp_measurement.c', line 59

static VALUE prof_measurement_initialize(VALUE self, VALUE total_time, VALUE self_time, VALUE wait_time, VALUE called)
{
  prof_measurement_t* result = prof_get_measurement(self);

  result->total_time = NUM2DBL(total_time);
  result->self_time = NUM2DBL(self_time);
  result->wait_time = NUM2DBL(wait_time);
  result->called = NUM2INT(called);
  result->object = self;
  return self;
}

Instance Method Details

#_dump_dataObject

:nodoc:



309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'ext/ruby_prof/rp_measurement.c', line 309

static VALUE prof_measurement_dump(VALUE self)
{
    prof_measurement_t* measurement_data = prof_get_measurement(self);
    VALUE result = rb_hash_new();

    rb_hash_aset(result, ID2SYM(rb_intern("owner")), INT2FIX(measurement_data->owner));
    rb_hash_aset(result, ID2SYM(rb_intern("total_time")), rb_float_new(measurement_data->total_time));
    rb_hash_aset(result, ID2SYM(rb_intern("self_time")), rb_float_new(measurement_data->self_time));
    rb_hash_aset(result, ID2SYM(rb_intern("wait_time")), rb_float_new(measurement_data->wait_time));
    rb_hash_aset(result, ID2SYM(rb_intern("called")), INT2FIX(measurement_data->called));

    return result;
}

#_load_data(data) ⇒ Object

:nodoc:



324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'ext/ruby_prof/rp_measurement.c', line 324

static VALUE
prof_measurement_load(VALUE self, VALUE data)
{
    prof_measurement_t* measurement = prof_get_measurement(self);
    measurement->object = self;

    measurement->owner = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("owner"))));
    measurement->total_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("total_time"))));
    measurement->self_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("self_time"))));
    measurement->wait_time = rb_num2dbl(rb_hash_aref(data, ID2SYM(rb_intern("wait_time"))));
    measurement->called = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("called"))));

    return data;
}

#calledInteger

Returns the total amount of times this method was called.

Returns:

  • (Integer)


270
271
272
273
274
# File 'ext/ruby_prof/rp_measurement.c', line 270

static VALUE prof_measurement_called(VALUE self)
{
    prof_measurement_t* result = prof_get_measurement(self);
    return INT2NUM(result->called);
}

#called=Object

Sets the call count to value.



280
281
282
283
284
285
# File 'ext/ruby_prof/rp_measurement.c', line 280

static VALUE prof_measurement_set_called(VALUE self, VALUE value)
{
  prof_measurement_t* result = prof_get_measurement(self);
  result->called = NUM2INT(value);
  return value;
}

#children_timeObject



5
6
7
# File 'lib/ruby-prof/measurement.rb', line 5

def children_time
  self.total_time - self.self_time - self.wait_time
end

#initialize_copy(other) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'ext/ruby_prof/rp_measurement.c', line 82

static VALUE prof_measurement_initialize_copy(VALUE self, VALUE other)
{
  // This object was created by Ruby either via Measurment#clone or Measurement#dup 
  // and thus prof_measurement_allocate was called so the object is owned by Ruby

  if (self == other)
    return self;

  prof_measurement_t* self_ptr = prof_get_measurement(self);
  prof_measurement_t* other_ptr = prof_get_measurement(other);

  self_ptr->called = other_ptr->called;
  self_ptr->total_time = other_ptr->total_time;
  self_ptr->self_time = other_ptr->self_time;
  self_ptr->wait_time = other_ptr->wait_time;

  return self;
}

#inspectObject



13
14
15
# File 'lib/ruby-prof/measurement.rb', line 13

def inspect
  super + "(#{self.to_s})"
end

#merge(other) ⇒ Object

Adds the content of other measurement to this measurement



300
301
302
303
304
305
306
# File 'ext/ruby_prof/rp_measurement.c', line 300

VALUE prof_measurement_merge(VALUE self, VALUE other)
{
  prof_measurement_t* self_ptr = prof_get_measurement(self);
  prof_measurement_t* other_ptr = prof_get_measurement(other);
  prof_measurement_merge_internal(self_ptr, other_ptr);
  return self;
}

#self_timeFloat

Returns the total amount of time spent in this method.

Returns:

  • (Float)


225
226
227
228
229
230
231
# File 'ext/ruby_prof/rp_measurement.c', line 225

static VALUE
prof_measurement_self_time(VALUE self)
{
    prof_measurement_t* result = prof_get_measurement(self);

    return rb_float_new(result->self_time);
}

#self_time=Object

Sets the call count to value.



237
238
239
240
241
242
# File 'ext/ruby_prof/rp_measurement.c', line 237

static VALUE prof_measurement_set_self_time(VALUE self, VALUE value)
{
  prof_measurement_t* result = prof_get_measurement(self);
  result->self_time = NUM2DBL(value);
  return value;
}

#to_sObject



9
10
11
# File 'lib/ruby-prof/measurement.rb', line 9

def to_s
  "c: #{called}, tt: #{total_time}, st: #{self_time}"
end

#total_timeFloat

Returns the total amount of time spent in this method and its children.

Returns:

  • (Float)


204
205
206
207
208
# File 'ext/ruby_prof/rp_measurement.c', line 204

static VALUE prof_measurement_total_time(VALUE self)
{
    prof_measurement_t* result = prof_get_measurement(self);
    return rb_float_new(result->total_time);
}

#total_time=Object

Sets the call count to n.



214
215
216
217
218
219
# File 'ext/ruby_prof/rp_measurement.c', line 214

static VALUE prof_measurement_set_total_time(VALUE self, VALUE value)
{
  prof_measurement_t* result = prof_get_measurement(self);
  result->total_time = NUM2DBL(value);
  return value;
}

#wait_timeFloat

Returns the total amount of time this method waited for other threads.

Returns:

  • (Float)


248
249
250
251
252
253
# File 'ext/ruby_prof/rp_measurement.c', line 248

static VALUE prof_measurement_wait_time(VALUE self)
{
    prof_measurement_t* result = prof_get_measurement(self);

    return rb_float_new(result->wait_time);
}

#wait_time=Object

Sets the wait time to value.



259
260
261
262
263
264
# File 'ext/ruby_prof/rp_measurement.c', line 259

static VALUE prof_measurement_set_wait_time(VALUE self, VALUE value)
{
  prof_measurement_t* result = prof_get_measurement(self);
  result->wait_time = NUM2DBL(value);
  return value;
}