static void sampling_job_handler(void *data_unused) { int start = 0; int lines[BUF_SIZE]; VALUE buff[BUF_SIZE]; VALUE rb_method_name, rb_label, rb_file, rb_singleton_method; int i, is_singleton; char *method_name, *label, *file; unsigned long line, thread_id; rbkit_cpu_sample *sample = malloc(sizeof(rbkit_cpu_sample)); int collected_size = rb_profile_frames(start, sizeof(buff) / sizeof(VALUE), buff, lines); rbkit_frame_data *frame_data = malloc(sizeof(rbkit_frame_data) * collected_size); sample->frames = frame_data; sample->frame_count = collected_size; for (i=0; i<collected_size; i++) { rb_method_name = rb_profile_frame_method_name(buff[i]); if(NIL_P(rb_method_name)) { method_name = NULL; } else { method_name = StringValueCStr(rb_method_name); } frame_data[i].method_name = method_name; rb_label = rb_profile_frame_full_label(buff[i]); label = StringValueCStr(rb_label); frame_data[i].label = label; rb_file = rb_profile_frame_absolute_path(buff[i]); if(NIL_P(rb_file)) rb_file = rb_profile_frame_path(buff[i]); file = StringValueCStr(rb_file); frame_data[i].file = file; line = FIX2ULONG(rb_profile_frame_first_lineno(buff[i])); frame_data[i].line = line; rb_singleton_method = rb_profile_frame_singleton_method_p(buff[i]); is_singleton = rb_singleton_method == Qtrue; frame_data[i].is_singleton_method = is_singleton; thread_id = FIX2ULONG(rb_obj_id(rb_thread_current())); frame_data[i].thread_id = thread_id; } queue_cpu_sample_for_sending(sample); free(frame_data); free(sample); }
static int frame_i(st_data_t key, st_data_t val, st_data_t arg) { VALUE frame = (VALUE)key; frame_data_t *frame_data = (frame_data_t *)val; VALUE results = (VALUE)arg; VALUE details = rb_hash_new(); VALUE name, file, edges, lines; VALUE line; rb_hash_aset(results, rb_obj_id(frame), details); name = rb_profile_frame_full_label(frame); rb_hash_aset(details, sym_name, name); file = rb_profile_frame_absolute_path(frame); if (NIL_P(file)) file = rb_profile_frame_path(frame); rb_hash_aset(details, sym_file, file); if ((line = rb_profile_frame_first_lineno(frame)) != INT2FIX(0)) rb_hash_aset(details, sym_line, line); rb_hash_aset(details, sym_total_samples, SIZET2NUM(frame_data->total_samples)); rb_hash_aset(details, sym_samples, SIZET2NUM(frame_data->caller_samples)); if (frame_data->edges) { edges = rb_hash_new(); rb_hash_aset(details, sym_edges, edges); st_foreach(frame_data->edges, frame_edges_i, (st_data_t)edges); st_free_table(frame_data->edges); frame_data->edges = NULL; } if (frame_data->lines) { lines = rb_hash_new(); rb_hash_aset(details, sym_lines, lines); st_foreach(frame_data->lines, frame_lines_i, (st_data_t)lines); st_free_table(frame_data->lines); frame_data->lines = NULL; } xfree(frame_data); return ST_DELETE; }