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.4.0"
Class Method Summary collapse
-
.custom_event_logging(event_str) ⇒ Object
custom event.
- .custom_field_decrement(name) ⇒ Object
- .custom_field_get(name) ⇒ Object
- .custom_field_increment(name) ⇒ Object
- .custom_field_set(name, val) ⇒ Object
- .env_logging_filename ⇒ Object
- .flush_logging ⇒ Object
- .setup_logging_events(*args) ⇒ Object
- .setup_logging_gc_latest_gc_info=(b) ⇒ Object
-
.setup_logging_gc_stat=(b) ⇒ Object
unreachable.
-
.setup_logging_out(filename) ⇒ Object
setup.
- .setup_logging_rusage=(b) ⇒ Object
- .setup_logging_tick_type=(sym) ⇒ Object
-
.setup_looging_custom_fields=(b) ⇒ Object
custom fields.
- .start_logging(filename_opt = nil, filename: nil, events: %i(start end_mark end_sweep),, tick_type: :time, gc_stat: true, gc_latest_gc_info: true, rusage: false, custom_fields: nil) ⇒ Object
- .start_logging_(*args) ⇒ Object
- .stop_logging ⇒ Object
Class Method Details
.custom_event_logging(event_str) ⇒ Object
custom event
706 707 708 709 710 711 712 713 714 715 716 717 718 719 |
# File 'ext/gc_tracer/gc_logging.c', line 706
static VALUE
gc_tracer_custom_event_logging(VALUE self, VALUE event_str)
{
struct gc_logging *logging = &trace_logging;
const char *str = StringValueCStr(event_str);
if (logging->enabled) {
out_stat(logging, str);
}
else {
rb_raise(rb_eRuntimeError, "GC tracer is not enabled.");
}
return self;
}
|
.custom_field_decrement(name) ⇒ Object
640 641 642 643 644 645 646 |
# File 'ext/gc_tracer/gc_logging.c', line 640
static VALUE
gc_tracer_custom_field_decrement(VALUE self, VALUE name)
{
long *valp = custom_field_value_place(name);
(*valp)--;
return self;
}
|
.custom_field_get(name) ⇒ Object
648 649 650 651 652 653 |
# File 'ext/gc_tracer/gc_logging.c', line 648
static VALUE
gc_tracer_custom_field_get(VALUE self, VALUE name)
{
long *valp = custom_field_value_place(name);
return LONG2NUM(*valp);
}
|
.custom_field_increment(name) ⇒ Object
632 633 634 635 636 637 638 |
# File 'ext/gc_tracer/gc_logging.c', line 632
static VALUE
gc_tracer_custom_field_increment(VALUE self, VALUE name)
{
long *valp = custom_field_value_place(name);
(*valp)++;
return self;
}
|
.custom_field_set(name, val) ⇒ Object
655 656 657 658 659 660 661 662 |
# File 'ext/gc_tracer/gc_logging.c', line 655
static VALUE
gc_tracer_custom_field_set(VALUE self, VALUE name, VALUE val)
{
long *valp = custom_field_value_place(name);
long lval = NUM2LONG(val);
*valp = lval;
return val;
}
|
.env_logging_filename ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/gc_tracer.rb', line 6 def self.env_logging_filename if fn = ENV['GC_TRACER_LOGFILE'] "#{fn}-#{Process.pid}" else nil end end |
.flush_logging ⇒ Object
692 693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'ext/gc_tracer/gc_logging.c', line 692
static VALUE
gc_tracer_flush_logging(VALUE self)
{
struct gc_logging *logging = &trace_logging;
if (logging->enabled) {
out_flush(logging->out);
}
else {
rb_raise(rb_eRuntimeError, "GC tracer is not enabled.");
}
return self;
}
|
.setup_logging_events(*args) ⇒ Object
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 480 481 482 483 484 485 486 487 488 489 |
# File 'ext/gc_tracer/gc_logging.c', line 454
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
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'ext/gc_tracer/gc_logging.c', line 542
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
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'ext/gc_tracer/gc_logging.c', line 526
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
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'ext/gc_tracer/gc_logging.c', line 430
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
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
# File 'ext/gc_tracer/gc_logging.c', line 558
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
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'ext/gc_tracer/gc_logging.c', line 491
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"
#ifdef HAVE_CLOCK_GETTIME
,
"nano_time"
#endif
};
static const out_time_func_t funcs[] = {
out_time_none,
out_time_hw_counter,
out_time_time
#ifdef HAVE_CLOCK_GETTIME
,
out_time_nano_time
#endif
};
int i;
for (i=0; i<(int)(sizeof(funcs)/sizeof(out_time_func_t)); 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 */
}
|
.setup_looging_custom_fields=(b) ⇒ Object
custom fields
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# File 'ext/gc_tracer/gc_logging.c', line 574
static VALUE
gc_tracer_setup_logging_custom_fields(VALUE self, VALUE b)
{
struct gc_logging *logging = &trace_logging;
if (RTEST(b)) {
VALUE ary = rb_check_array_type(b);
int i;
logging->config.log_custom_fields_count = RARRAY_LEN(ary);
for (i=0; i<RARRAY_LEN(ary); i++) {
VALUE name = RARRAY_AREF(ary, i);
ID field_id = rb_to_id(name);
if (i >= MAX_CUSTOM_FIELDS) {
rb_raise(rb_eRuntimeError, "Number of custome fields exceeds %d", MAX_CUSTOM_FIELDS);
}
logging->custom_field_names[i] = field_id;
logging->custom_field_values[i] = 0;
}
}
else {
logging->config.log_custom_fields_count = 0;
}
return self;
}
|
.start_logging(filename_opt = nil, filename: nil, events: %i(start end_mark end_sweep),, tick_type: :time, gc_stat: true, gc_latest_gc_info: true, rusage: false, custom_fields: nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gc_tracer.rb', line 14 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: :time, # collect information gc_stat: true, gc_latest_gc_info: true, rusage: false, custom_fields: nil ) # setup raise "do not specify two fienames" if filename && filename_opt setup_logging_out(filename_opt || filename || env_logging_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 self.setup_looging_custom_fields = custom_fields if block_given? begin start_logging_ yield ensure stop_logging end else start_logging_ end end |
.start_logging_(*args) ⇒ Object
664 665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'ext/gc_tracer/gc_logging.c', line 664
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_logging ⇒ Object
678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'ext/gc_tracer/gc_logging.c', line 678
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;
}
|