Module: GC::Tracer

Defined in:
lib/gc_tracer.rb,
lib/gc_tracer/version.rb,
ext/gc_tracer/gc_tracer.c

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.setup_logging_events(*args) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'ext/gc_tracer/gc_logging.c', line 415

static VALUE
gc_tracer_setup_logging_events(int argc, VALUE *argv, VALUE self)
{
    struct gc_logging *logging = &trace_logging;
    int i, n;
    int event_bits = 0;

    if (argc == 0) {
  /* deafult: start, end_mark, end_sweep */
  for (i=0; i<3; i++) {
      event_bits = 0x07; /* 0b0111 */
  }
    }
    else {
  int j;
  for (i=0; i<argc; i++) {
      for (j=0; j<MAX_HOOKS; j++) {
    if (tracer_acceptable_events[j] == argv[i]) {
        event_bits |= 0x01 << j;
        goto found;
    }
      }
      rb_raise(rb_eArgError, "unsupported GC trace event: %"PRIsVALUE, argv[i]);
    found:;
  }
    }

    for (n=0, i=0; i<MAX_HOOKS; i++) {
  if (event_bits & (0x01 << i)) {
      logging->enable_hooks[n++] = tracer_hooks[i];
  }
    }
    logging->enable_hooks_num = n;

    return self;
}

.setup_logging_gc_latest_gc_info=(b) ⇒ Object



497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'ext/gc_tracer/gc_logging.c', line 497

static VALUE
gc_tracer_setup_logging_gc_latest_gc_info(VALUE self, VALUE b)
{
    struct gc_logging *logging = &trace_logging;


    if (RTEST(b)) {
  logging->config.log_gc_latest_gc_info = Qtrue;
    }
    else {
  logging->config.log_gc_latest_gc_info = Qfalse;
    }

    return self;
}

.setup_logging_gc_stat=(b) ⇒ Object

unreachable



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'ext/gc_tracer/gc_logging.c', line 481

static VALUE
gc_tracer_setup_logging_gc_stat(VALUE self, VALUE b)
{
    struct gc_logging *logging = &trace_logging;


    if (RTEST(b)) {
  logging->config.log_gc_stat = Qtrue;
    }
    else {
  logging->config.log_gc_stat = Qfalse;
    }

    return self;
}

.setup_logging_out(filename) ⇒ Object

setup



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'ext/gc_tracer/gc_logging.c', line 391

static VALUE
gc_tracer_setup_logging_out(VALUE self, VALUE filename)
{
    struct gc_logging *logging = &trace_logging;

    if (NIL_P(filename)) {
  logging->out = stderr;
    }
    else {
  filename = rb_check_string_type(filename);
  {
      const char *fname = StringValueCStr(filename);
      FILE *out;

      if ((out = fopen(fname, "w")) == NULL) {
    rb_raise(rb_eRuntimeError, "can not open file: %s\n", fname);
      }
      logging->out = out;
  }
    }

    return self;
}

.setup_logging_rusage=(b) ⇒ Object



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# File 'ext/gc_tracer/gc_logging.c', line 513

static VALUE
gc_tracer_setup_logging_rusage(VALUE self, VALUE b)
{
    struct gc_logging *logging = &trace_logging;


    if (RTEST(b)) {
  logging->config.log_rusage = Qtrue;
    }
    else {
  logging->config.log_rusage = Qfalse;
    }

    return self;
}

.setup_logging_tick_type=(sym) ⇒ Object



452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'ext/gc_tracer/gc_logging.c', line 452

static VALUE
gc_tracer_setup_logging_tick_type(VALUE self, VALUE sym)
{
    struct gc_logging *logging = &trace_logging;
    static const char *names[] = {
  "none",
  "hw_counter",
  "time",
  "nano_time"
    };
    static const out_time_func_t funcs[] = {
  out_time_none,
  out_time_hw_counter,
  out_time_time,
  out_time_nano_time
    };
    int i;

    for (i=0; i<4; i++) {
  if (sym == ID2SYM(rb_intern(names[i]))) {
      logging->config.out_time_func = funcs[i];
      return self;
  }
    }

    rb_raise(rb_eArgError, "unknown tick type: %"PRIsVALUE, sym);
    return self; /* unreachable */
}

.start_logging(filename_opt = nil, filename: nil, events: %i(start end_mark end_sweep),, tick_type: :nano_time, gc_stat: true, gc_latest_gc_info: true, rusage: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gc_tracer.rb', line 6

def self.start_logging(filename_opt = nil,
                       filename: nil,
                       # event filter
                       events: i(start end_mark end_sweep),
                       # tick type (:hw_counter, :time, :user_time, :system_time)
                       tick_type: :nano_time,
                       # collect information
                       gc_stat: true,
                       gc_latest_gc_info: true,
                       rusage: false)
  # setup
  raise "do not specify two fienames" if filename && filename_opt
  setup_logging_out(filename_opt || filename)
  setup_logging_events(*events)

  self.setup_logging_gc_stat = gc_stat
  self.setup_logging_gc_latest_gc_info = gc_latest_gc_info
  self.setup_logging_rusage = rusage
  self.setup_logging_tick_type = tick_type

  if block_given?
    begin
      start_logging_
      yield
    ensure
      stop_logging
    end
  else
    start_logging_
  end
end

.start_logging_(*args) ⇒ Object



529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'ext/gc_tracer/gc_logging.c', line 529

static VALUE
gc_tracer_start_logging(int argc, VALUE *argv, VALUE self)
{
    struct gc_logging *logging = &trace_logging;

    if (logging->enabled == 0) {
  logging->enabled = 1;
  out_header(logging);
  enable_gc_hooks(logging);
    }

    return self;
}

.stop_loggingObject



543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'ext/gc_tracer/gc_logging.c', line 543

static VALUE
gc_tracer_stop_logging(VALUE self)
{
    struct gc_logging *logging = &trace_logging;

    if (logging->enabled) {
  close_output(logging->out);
  disable_gc_hooks(logging);
  logging->enabled = 0;
    }

    return self;
}