Module: LowlevelToolkit

Defined in:
lib/lowlevel_toolkit/version.rb,
lib/lowlevel-toolkit.rb,
ext/lowlevel_toolkit_native_extension/lowlevel_toolkit.c

Overview

frozen_string_literal: true

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.last_allocation_atObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'ext/lowlevel_toolkit_native_extension/last_allocation_at.c', line 25

static VALUE last_allocation_at(RB_UNUSED_VAR(VALUE _)) {
  VALUE raw_stack = stack;
  stack = Qnil; // Pause recording of stacks while we're doing the copying below
  VALUE result = rb_ary_new();
  for (int i = 0; i < RARRAY_LEN(raw_stack); i++) {
    VALUE entry = rb_ary_entry(raw_stack, i);
    VALUE file = rb_profile_frame_path(entry);
    if (file != Qnil) rb_ary_push(result, rb_ary_new_from_args(2, file, rb_profile_frame_label(entry)));
  }
  stack = raw_stack; // Resume recording again
  return result;
}

.release_gvl_profilerObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'ext/lowlevel_toolkit_native_extension/release_gvl_profiler.c', line 85

static VALUE release_gvl_profiler(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE _)) {
  VALUE options;
  rb_scan_args(argc, argv, "0:", &options);
  if (options == Qnil) options = rb_hash_new();
  VALUE filename_prefix = rb_hash_fetch(options, ID2SYM(rb_intern("filename_prefix")));

  VALUE result = rb_hash_new();
  rb_internal_thread_event_hook_t *hook = rb_internal_thread_add_event_hook(
    on_thread_event,
    RUBY_INTERNAL_THREAD_EVENT_SUSPENDED | RUBY_INTERNAL_THREAD_EVENT_RESUMED,
    (void *) result
  );
  rb_yield(Qnil);
  rb_internal_thread_remove_event_hook(hook);

  write_stacks(filename_prefix, result);
  return result;
}

.track_last_allocation_atObject



18
19
20
21
22
23
# File 'ext/lowlevel_toolkit_native_extension/last_allocation_at.c', line 18

static VALUE track_last_allocation_at(RB_UNUSED_VAR(VALUE _)) {
  stack = rb_ary_new_capa(MAX_DEPTH);
  VALUE tp = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, on_newobj_event, NULL);
  rb_tracepoint_enable(tp); rb_yield(Qnil); rb_tracepoint_disable(tp);
  return Qnil;
}

.track_objects_createdObject



17
18
19
20
21
22
# File 'ext/lowlevel_toolkit_native_extension/track_objects_created.c', line 17

static VALUE track_objects_created(RB_UNUSED_VAR(VALUE _)) {
  VALUE result = rb_ary_new();
  VALUE tp = rb_tracepoint_new(0, RUBY_INTERNAL_EVENT_NEWOBJ, on_newobj_event, (void *) result);
  rb_tracepoint_enable(tp); rb_yield(Qnil); rb_tracepoint_disable(tp);
  return filter_hidden_objects(result);
}