Class: Timer

Inherits:
Object
  • Object
show all
Defined in:
ext/stats/stats-ruby.c

Instance Method Summary collapse

Instance Method Details

#enterObject



551
552
553
554
555
556
557
558
559
560
561
# File 'ext/stats/stats-ruby.c', line 551

VALUE rbtmr_enter(VALUE self)
{
    struct timer_data *td;

    Data_Get_Struct(self, struct timer_data, td);
    if (td->start_time == 0)
        td->start_time = current_time();
    td->depth++;

    return self;
}

#exitObject



563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'ext/stats/stats-ruby.c', line 563

VALUE rbtmr_exit(VALUE self)
{
    struct timer_data *td;

    Data_Get_Struct(self, struct timer_data, td);
    if (td->depth > 0)
        td->depth--;
    if (td->start_time > 0 && td->depth == 0)
    {
        counter_increment_by(td->counter,TIME_DELTA_TO_NANOS(td->start_time,current_time()) / 1000ll);
        td->start_time = 0;
    }
    return self;
}

#timeObject



578
579
580
581
582
583
584
585
586
587
588
589
# File 'ext/stats/stats-ruby.c', line 578

VALUE rbtmr_time(VALUE self)
{
    struct timer_data *td;
    long long start_time;
    VALUE ret;

    Data_Get_Struct(self, struct timer_data, td);
    start_time = current_time();
    ret = rb_yield(self);
    counter_increment_by(td->counter,TIME_DELTA_TO_NANOS(start_time,current_time()) / 1000ll);
    return ret;
}