@@ -77,6 +77,7 @@ static VALUE sym_object, sym_wall, sym_cpu, sym_custom, sym_name, sym_file, sym_
7777static VALUE sym_samples , sym_total_samples , sym_missed_samples , sym_edges , sym_lines ;
7878static VALUE sym_version , sym_mode , sym_interval , sym_raw , sym_metadata , sym_frames , sym_ignore_gc , sym_out ;
7979static VALUE sym_aggregate , sym_raw_timestamp_deltas , sym_state , sym_marking , sym_sweeping ;
80+ static VALUE str_top_label ;
8081static VALUE sym_gc_samples , objtracer ;
8182static VALUE gc_hook ;
8283static VALUE rb_mStackProf ;
@@ -224,6 +225,17 @@ frame_lines_i(st_data_t key, st_data_t val, st_data_t arg)
224225 return ST_CONTINUE ;
225226}
226227
228+ static VALUE
229+ coerce_frame_name (VALUE name , VALUE line ) {
230+ char * start_pointer = strstr (RSTRING_PTR (name ), "<top (required)>\0" );
231+ if (start_pointer ) {
232+ VALUE new_name = rb_str_new (RSTRING_PTR (name ), start_pointer - RSTRING_PTR (name ));
233+ rb_str_cat_cstr (new_name , RSTRING_PTR (line ));
234+ return new_name ;
235+ }
236+ return name ;
237+ }
238+
227239static int
228240frame_i (st_data_t key , st_data_t val , st_data_t arg )
229241{
@@ -242,13 +254,15 @@ frame_i(st_data_t key, st_data_t val, st_data_t arg)
242254 line = INT2FIX (0 );
243255 } else {
244256 name = rb_profile_frame_full_label (frame );
245-
246257 file = rb_profile_frame_absolute_path (frame );
247258 if (NIL_P (file ))
248259 file = rb_profile_frame_path (frame );
249260 line = rb_profile_frame_first_lineno (frame );
250261 }
251262
263+
264+ name = coerce_frame_name (name , file );
265+
252266 rb_hash_aset (details , sym_name , name );
253267 rb_hash_aset (details , sym_file , file );
254268 if (line != INT2FIX (0 )) {
@@ -741,6 +755,8 @@ Init_stackprof(void)
741755 S (sweeping );
742756#undef S
743757
758+ str_top_label = rb_str_new_cstr ("<top (required)>" );
759+
744760 /* Need to run this to warm the symbol table before we call this during GC */
745761 rb_gc_latest_gc_info (sym_state );
746762
0 commit comments