ruby-prof 1.7.1-x64-mingw-ucrt → 1.7.2-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGES +8 -0
 - data/ext/ruby_prof/extconf.rb +23 -22
 - data/ext/ruby_prof/rp_call_trees.c +296 -296
 - data/ext/ruby_prof/rp_call_trees.h +28 -28
 - data/ext/ruby_prof/rp_measure_allocations.c +47 -47
 - data/ext/ruby_prof/rp_measure_process_time.c +64 -66
 - data/ext/ruby_prof/rp_measure_wall_time.c +52 -64
 - data/ext/ruby_prof/rp_method.c +551 -551
 - data/ext/ruby_prof/rp_stack.c +212 -212
 - data/ext/ruby_prof/ruby_prof.c +50 -50
 - data/ext/ruby_prof/ruby_prof.h +3 -2
 - data/ext/ruby_prof/vc/ruby_prof.vcxproj +3 -3
 - data/lib/3.4/ruby_prof.so +0 -0
 - data/lib/ruby-prof/compatibility.rb +113 -113
 - data/lib/ruby-prof/exclude_common_methods.rb +204 -204
 - data/lib/ruby-prof/printers/abstract_printer.rb +156 -138
 - data/lib/ruby-prof/version.rb +3 -3
 - data/ruby-prof.gemspec +66 -65
 - data/test/dynamic_method_test.rb +9 -21
 - data/test/enumerable_test.rb +23 -21
 - data/test/exclude_methods_test.rb +363 -257
 - data/test/fiber_test.rb +195 -195
 - data/test/gc_test.rb +104 -102
 - data/test/line_number_test.rb +426 -289
 - data/test/measure_allocations_test.rb +1172 -1081
 - data/test/measure_memory_test.rb +1193 -1456
 - data/test/measure_process_time_test.rb +3330 -2477
 - data/test/measure_wall_time_test.rb +634 -568
 - data/test/merge_test.rb +146 -146
 - data/test/method_info_test.rb +100 -95
 - data/test/printers_test.rb +178 -135
 - data/test/recursive_test.rb +796 -622
 - data/test/start_stop_test.rb +4 -4
 - data/test/test_helper.rb +20 -20
 - data/test/thread_test.rb +229 -231
 - data/test/unique_call_path_test.rb +9 -22
 - data/test/yarv_test.rb +1 -5
 - metadata +20 -10
 - data/lib/3.3/ruby_prof.so +0 -0
 - data/test/crash2.rb +0 -144
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 3d6d1a0b81ddaa8a4b247429c59c2f0d2368394299576a4e34f64592da3af842
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9cd22f2660899fbebdc3cd1f1e560cabf1aa26c91e4035aa58d2751e531e4af0
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 417d2f93a7946e63fa78c65f5a0a8668cecbaf654bbd07365946934878e3e5abbe701056cc3483c181d8f7f8a0a24d145e621edc42136ae44d462f413a7462ae
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d1b5908f3b89cea71a4513551fd5bbd26b59f7f91f413c11bf7acdae1db8801119430f86455b339cc5484d3ac021a04bf78014ff508992f915636460e989f15d
         
     | 
    
        data/CHANGES
    CHANGED
    
    | 
         @@ -1,3 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            1.7.2 (2025-05-21)
         
     | 
| 
      
 2 
     | 
    
         
            +
            =====================
         
     | 
| 
      
 3 
     | 
    
         
            +
            * Fix compiling on Ubuntu and Arch Linux
         
     | 
| 
      
 4 
     | 
    
         
            +
            * Update tests for Ruby 3.4
         
     | 
| 
      
 5 
     | 
    
         
            +
            * Remove tests for Ruby 3.1
         
     | 
| 
      
 6 
     | 
    
         
            +
            * Update MacOS to use clock_gettime (same as Linux) instead of proprietary mach_absolute_time API
         
     | 
| 
      
 7 
     | 
    
         
            +
            * Add CMake support
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       1 
9 
     | 
    
         
             
            1.7.1 (2024-10-19)
         
     | 
| 
       2 
10 
     | 
    
         
             
            =====================
         
     | 
| 
       3 
11 
     | 
    
         
             
            * Fix crashes when calling merge due to inconsistent method keys (Chris Heald)
         
     | 
    
        data/ext/ruby_prof/extconf.rb
    CHANGED
    
    | 
         @@ -1,22 +1,23 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require "mkmf"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            # Let's go with a modern version of C! want to intermix declarations and code (ie, don't define
         
     | 
| 
       4 
     | 
    
         
            -
            # all variables at the top of the method). If using Visual Studio, you'll need 2019 version
         
     | 
| 
       5 
     | 
    
         
            -
            # 16.8 or higher
         
     | 
| 
       6 
     | 
    
         
            -
            if RUBY_PLATFORM =~ /mswin/
         
     | 
| 
       7 
     | 
    
         
            -
              $CFLAGS += ' /std:c11'
         
     | 
| 
       8 
     | 
    
         
            -
            else
         
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require "mkmf"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # Let's go with a modern version of C! want to intermix declarations and code (ie, don't define
         
     | 
| 
      
 4 
     | 
    
         
            +
            # all variables at the top of the method). If using Visual Studio, you'll need 2019 version
         
     | 
| 
      
 5 
     | 
    
         
            +
            # 16.8 or higher
         
     | 
| 
      
 6 
     | 
    
         
            +
            if RUBY_PLATFORM =~ /mswin/
         
     | 
| 
      
 7 
     | 
    
         
            +
              $CFLAGS += ' /std:c11'
         
     | 
| 
      
 8 
     | 
    
         
            +
            else
         
     | 
| 
      
 9 
     | 
    
         
            +
              # Need -D_POSIX_C_SOURCE=199309L for clock_gettime
         
     | 
| 
      
 10 
     | 
    
         
            +
              $CFLAGS += ' -std=c11 -D_POSIX_C_SOURCE=199309L'
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            # For gcc add -s to strip symbols, reducing library size from 17MB to 78KB (at least on Windows with mingw64)
         
     | 
| 
      
 14 
     | 
    
         
            +
            if RUBY_PLATFORM !~ /mswin/
         
     | 
| 
      
 15 
     | 
    
         
            +
              $LDFLAGS += ' -s'
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            # And since we are using C99 we want to disable Ruby sending these warnings to gcc
         
     | 
| 
      
 19 
     | 
    
         
            +
            if CONFIG['warnflags']
         
     | 
| 
      
 20 
     | 
    
         
            +
              CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            create_makefile("ruby_prof")
         
     | 
| 
         @@ -1,296 +1,296 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
         
     | 
| 
       2 
     | 
    
         
            -
               Please see the LICENSE file for copyright and distribution information */
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            #include "rp_call_trees.h"
         
     | 
| 
       5 
     | 
    
         
            -
            #include "rp_measurement.h"
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            #define INITIAL_CALL_TREES_SIZE 2
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            VALUE cRpCallTrees;
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            /* =======  Call Infos   ========*/
         
     | 
| 
       12 
     | 
    
         
            -
            prof_call_trees_t* prof_get_call_trees(VALUE self)
         
     | 
| 
       13 
     | 
    
         
            -
            {
         
     | 
| 
       14 
     | 
    
         
            -
                /* Can't use Data_Get_Struct because that triggers the event hook
         
     | 
| 
       15 
     | 
    
         
            -
                   ending up in endless recursion. */
         
     | 
| 
       16 
     | 
    
         
            -
                prof_call_trees_t* result = RTYPEDDATA_DATA(self);
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                if (!result)
         
     | 
| 
       19 
     | 
    
         
            -
                    rb_raise(rb_eRuntimeError, "This RubyProf::CallTrees instance has already been freed, likely because its profile has been freed.");
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                return result;
         
     | 
| 
       22 
     | 
    
         
            -
            }
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            prof_call_trees_t* prof_call_trees_create(void)
         
     | 
| 
       25 
     | 
    
         
            -
            {
         
     | 
| 
       26 
     | 
    
         
            -
                prof_call_trees_t* result = ALLOC(prof_call_trees_t);
         
     | 
| 
       27 
     | 
    
         
            -
                result->start = ALLOC_N(prof_call_tree_t*, INITIAL_CALL_TREES_SIZE);
         
     | 
| 
       28 
     | 
    
         
            -
                result->end = result->start + INITIAL_CALL_TREES_SIZE;
         
     | 
| 
       29 
     | 
    
         
            -
                result->ptr = result->start;
         
     | 
| 
       30 
     | 
    
         
            -
                result->object = Qnil;
         
     | 
| 
       31 
     | 
    
         
            -
                return result;
         
     | 
| 
       32 
     | 
    
         
            -
            }
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            void prof_call_trees_mark(void* data)
         
     | 
| 
       35 
     | 
    
         
            -
            {
         
     | 
| 
       36 
     | 
    
         
            -
                if (!data) return;
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                prof_call_trees_t* call_trees = (prof_call_trees_t*)data;
         
     | 
| 
       39 
     | 
    
         
            -
                prof_call_tree_t** call_tree;
         
     | 
| 
       40 
     | 
    
         
            -
                for (call_tree = call_trees->start; call_tree < call_trees->ptr; call_tree++)
         
     | 
| 
       41 
     | 
    
         
            -
                {
         
     | 
| 
       42 
     | 
    
         
            -
                    prof_call_tree_mark(*call_tree);
         
     | 
| 
       43 
     | 
    
         
            -
                }
         
     | 
| 
       44 
     | 
    
         
            -
            }
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            void prof_call_trees_free(prof_call_trees_t* call_trees)
         
     | 
| 
       47 
     | 
    
         
            -
            {
         
     | 
| 
       48 
     | 
    
         
            -
                /* Has this method object been accessed by Ruby?  If
         
     | 
| 
       49 
     | 
    
         
            -
                   yes clean it up so to avoid a segmentation fault. */
         
     | 
| 
       50 
     | 
    
         
            -
                if (call_trees->object != Qnil)
         
     | 
| 
       51 
     | 
    
         
            -
                {
         
     | 
| 
       52 
     | 
    
         
            -
                    RTYPEDDATA(call_trees->object)->data = NULL;
         
     | 
| 
       53 
     | 
    
         
            -
                    call_trees->object = Qnil;
         
     | 
| 
       54 
     | 
    
         
            -
                }
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                // Note we do not free our call_tree structures - since they have no parents they will free themselves
         
     | 
| 
       57 
     | 
    
         
            -
                xfree(call_trees);
         
     | 
| 
       58 
     | 
    
         
            -
            }
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
            void prof_call_trees_ruby_gc_free(void* data)
         
     | 
| 
       61 
     | 
    
         
            -
            {
         
     | 
| 
       62 
     | 
    
         
            -
                if (data)
         
     | 
| 
       63 
     | 
    
         
            -
                {
         
     | 
| 
       64 
     | 
    
         
            -
                    // This object gets freed by its owning method
         
     | 
| 
       65 
     | 
    
         
            -
                    prof_call_trees_t* call_trees = (prof_call_trees_t*)data;
         
     | 
| 
       66 
     | 
    
         
            -
                    call_trees->object = Qnil;
         
     | 
| 
       67 
     | 
    
         
            -
                }
         
     | 
| 
       68 
     | 
    
         
            -
            }
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            static int prof_call_trees_collect(st_data_t key, st_data_t value, st_data_t data)
         
     | 
| 
       71 
     | 
    
         
            -
            {
         
     | 
| 
       72 
     | 
    
         
            -
                VALUE result = (VALUE)data;
         
     | 
| 
       73 
     | 
    
         
            -
                prof_call_tree_t* call_tree_data = (prof_call_tree_t*)value;
         
     | 
| 
       74 
     | 
    
         
            -
                VALUE aggregate_call_tree = prof_call_tree_wrap(call_tree_data);
         
     | 
| 
       75 
     | 
    
         
            -
                rb_ary_push(result, aggregate_call_tree);
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                return ST_CONTINUE;
         
     | 
| 
       78 
     | 
    
         
            -
            }
         
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
            static int prof_call_trees_collect_callees(st_data_t key, st_data_t value, st_data_t hash)
         
     | 
| 
       81 
     | 
    
         
            -
            {
         
     | 
| 
       82 
     | 
    
         
            -
                st_table* callers = (st_table*)hash;
         
     | 
| 
       83 
     | 
    
         
            -
                prof_call_tree_t* call_tree_data = (prof_call_tree_t*)value;
         
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
                prof_call_tree_t* aggregate_call_tree_data = NULL;
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
                if (rb_st_lookup(callers, call_tree_data->method->key, (st_data_t*)&aggregate_call_tree_data))
         
     | 
| 
       88 
     | 
    
         
            -
                {
         
     | 
| 
       89 
     | 
    
         
            -
                  prof_measurement_merge_internal(aggregate_call_tree_data->measurement, call_tree_data->measurement);
         
     | 
| 
       90 
     | 
    
         
            -
                }
         
     | 
| 
       91 
     | 
    
         
            -
                else
         
     | 
| 
       92 
     | 
    
         
            -
                {
         
     | 
| 
       93 
     | 
    
         
            -
                    // Copy the call tree so we don't touch the original and give Ruby ownerhip 
         
     | 
| 
       94 
     | 
    
         
            -
                    // of it so that it is freed on GC
         
     | 
| 
       95 
     | 
    
         
            -
                    aggregate_call_tree_data = prof_call_tree_copy(call_tree_data);
         
     | 
| 
       96 
     | 
    
         
            -
                    aggregate_call_tree_data->owner = OWNER_RUBY;
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
                    rb_st_insert(callers, call_tree_data->method->key, (st_data_t)aggregate_call_tree_data);
         
     | 
| 
       100 
     | 
    
         
            -
                }
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                return ST_CONTINUE;
         
     | 
| 
       103 
     | 
    
         
            -
            }
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
            size_t prof_call_trees_size(const void* data)
         
     | 
| 
       106 
     | 
    
         
            -
            {
         
     | 
| 
       107 
     | 
    
         
            -
                return sizeof(prof_call_trees_t);
         
     | 
| 
       108 
     | 
    
         
            -
            }
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
            static const rb_data_type_t call_trees_type =
         
     | 
| 
       111 
     | 
    
         
            -
            {
         
     | 
| 
       112 
     | 
    
         
            -
                .wrap_struct_name = "CallTrees",
         
     | 
| 
       113 
     | 
    
         
            -
                .function =
         
     | 
| 
       114 
     | 
    
         
            -
                {
         
     | 
| 
       115 
     | 
    
         
            -
                    .dmark = prof_call_trees_mark,
         
     | 
| 
       116 
     | 
    
         
            -
                    .dfree = prof_call_trees_ruby_gc_free,
         
     | 
| 
       117 
     | 
    
         
            -
                    .dsize = prof_call_trees_size,
         
     | 
| 
       118 
     | 
    
         
            -
                },
         
     | 
| 
       119 
     | 
    
         
            -
                .data = NULL,
         
     | 
| 
       120 
     | 
    
         
            -
                .flags = RUBY_TYPED_FREE_IMMEDIATELY
         
     | 
| 
       121 
     | 
    
         
            -
            };
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
            VALUE prof_call_trees_wrap(prof_call_trees_t* call_trees)
         
     | 
| 
       124 
     | 
    
         
            -
            {
         
     | 
| 
       125 
     | 
    
         
            -
                if (call_trees->object == Qnil)
         
     | 
| 
       126 
     | 
    
         
            -
                {
         
     | 
| 
       127 
     | 
    
         
            -
                    call_trees->object = TypedData_Wrap_Struct(cRpCallTrees, &call_trees_type, call_trees);
         
     | 
| 
       128 
     | 
    
         
            -
                }
         
     | 
| 
       129 
     | 
    
         
            -
                return call_trees->object;
         
     | 
| 
       130 
     | 
    
         
            -
            }
         
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
            void prof_add_call_tree(prof_call_trees_t* call_trees, prof_call_tree_t* call_tree)
         
     | 
| 
       133 
     | 
    
         
            -
            {
         
     | 
| 
       134 
     | 
    
         
            -
                if (call_trees->ptr == call_trees->end)
         
     | 
| 
       135 
     | 
    
         
            -
                {
         
     | 
| 
       136 
     | 
    
         
            -
                    size_t len = call_trees->ptr - call_trees->start;
         
     | 
| 
       137 
     | 
    
         
            -
                    size_t new_capacity = (call_trees->end - call_trees->start) * 2;
         
     | 
| 
       138 
     | 
    
         
            -
                    REALLOC_N(call_trees->start, prof_call_tree_t*, new_capacity);
         
     | 
| 
       139 
     | 
    
         
            -
                    call_trees->ptr = call_trees->start + len;
         
     | 
| 
       140 
     | 
    
         
            -
                    call_trees->end = call_trees->start + new_capacity;
         
     | 
| 
       141 
     | 
    
         
            -
                }
         
     | 
| 
       142 
     | 
    
         
            -
                *call_trees->ptr = call_tree;
         
     | 
| 
       143 
     | 
    
         
            -
                call_trees->ptr++;
         
     | 
| 
       144 
     | 
    
         
            -
            }
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
            /* ================  Call Infos   =================*/
         
     | 
| 
       147 
     | 
    
         
            -
            /* Document-class: RubyProf::CallTrees
         
     | 
| 
       148 
     | 
    
         
            -
            The RubyProf::MethodInfo class stores profiling data for a method.
         
     | 
| 
       149 
     | 
    
         
            -
            One instance of the RubyProf::MethodInfo class is created per method
         
     | 
| 
       150 
     | 
    
         
            -
            called per thread.  Thus, if a method is called in two different
         
     | 
| 
       151 
     | 
    
         
            -
            thread then there will be two RubyProf::MethodInfo objects
         
     | 
| 
       152 
     | 
    
         
            -
            created.  RubyProf::MethodInfo objects can be accessed via
         
     | 
| 
       153 
     | 
    
         
            -
            the RubyProf::Profile object. */
         
     | 
| 
       154 
     | 
    
         
            -
            VALUE prof_call_trees_allocate(VALUE klass)
         
     | 
| 
       155 
     | 
    
         
            -
            {
         
     | 
| 
       156 
     | 
    
         
            -
                prof_call_trees_t* call_trees_data = prof_call_trees_create();
         
     | 
| 
       157 
     | 
    
         
            -
                call_trees_data->object = prof_call_trees_wrap(call_trees_data);
         
     | 
| 
       158 
     | 
    
         
            -
                return call_trees_data->object;
         
     | 
| 
       159 
     | 
    
         
            -
            }
         
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
            /* call-seq:
         
     | 
| 
       163 
     | 
    
         
            -
               min_depth -> Integer
         
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
            Returns the minimum depth of this method in any call tree */
         
     | 
| 
       166 
     | 
    
         
            -
            VALUE prof_call_trees_min_depth(VALUE self)
         
     | 
| 
       167 
     | 
    
         
            -
            {
         
     | 
| 
       168 
     | 
    
         
            -
                unsigned int depth = INT_MAX;
         
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
       171 
     | 
    
         
            -
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
       172 
     | 
    
         
            -
                {
         
     | 
| 
       173 
     | 
    
         
            -
                    unsigned int call_tree_depth = prof_call_tree_figure_depth(*p_call_tree);
         
     | 
| 
       174 
     | 
    
         
            -
                    if (call_tree_depth < depth)
         
     | 
| 
       175 
     | 
    
         
            -
                        depth = call_tree_depth;
         
     | 
| 
       176 
     | 
    
         
            -
                }
         
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
                return UINT2NUM(depth);
         
     | 
| 
       179 
     | 
    
         
            -
            }
         
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
            /* call-seq:
         
     | 
| 
       182 
     | 
    
         
            -
               callers -> array
         
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
            Returns an array of all CallTree objects that called this method. */
         
     | 
| 
       185 
     | 
    
         
            -
            VALUE prof_call_trees_call_trees(VALUE self)
         
     | 
| 
       186 
     | 
    
         
            -
            {
         
     | 
| 
       187 
     | 
    
         
            -
                VALUE result = rb_ary_new();
         
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
       190 
     | 
    
         
            -
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
       191 
     | 
    
         
            -
                {
         
     | 
| 
       192 
     | 
    
         
            -
                    VALUE call_tree = prof_call_tree_wrap(*p_call_tree);
         
     | 
| 
       193 
     | 
    
         
            -
                    rb_ary_push(result, call_tree);
         
     | 
| 
       194 
     | 
    
         
            -
                }
         
     | 
| 
       195 
     | 
    
         
            -
                return result;
         
     | 
| 
       196 
     | 
    
         
            -
            }
         
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
            /* call-seq:
         
     | 
| 
       199 
     | 
    
         
            -
               callers -> array
         
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
            Returns an array of aggregated CallTree objects that called this method (ie, parents).*/
         
     | 
| 
       202 
     | 
    
         
            -
            VALUE prof_call_trees_callers(VALUE self)
         
     | 
| 
       203 
     | 
    
         
            -
            {
         
     | 
| 
       204 
     | 
    
         
            -
                st_table* callers = rb_st_init_numtable();
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
     | 
    
         
            -
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
       207 
     | 
    
         
            -
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
       208 
     | 
    
         
            -
                {
         
     | 
| 
       209 
     | 
    
         
            -
                    prof_call_tree_t* parent = (*p_call_tree)->parent;
         
     | 
| 
       210 
     | 
    
         
            -
                    if (parent == NULL)
         
     | 
| 
       211 
     | 
    
         
            -
                        continue;
         
     | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
       213 
     | 
    
         
            -
                    prof_call_tree_t* aggregate_call_tree_data = NULL;
         
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
                    if (rb_st_lookup(callers, parent->method->key, (st_data_t*)&aggregate_call_tree_data))
         
     | 
| 
       216 
     | 
    
         
            -
                    {
         
     | 
| 
       217 
     | 
    
         
            -
                      prof_measurement_merge_internal(aggregate_call_tree_data->measurement, (*p_call_tree)->measurement);
         
     | 
| 
       218 
     | 
    
         
            -
                    }
         
     | 
| 
       219 
     | 
    
         
            -
                    else
         
     | 
| 
       220 
     | 
    
         
            -
                    {
         
     | 
| 
       221 
     | 
    
         
            -
                        // Copy the call tree so we don't touch the original and give Ruby ownerhip 
         
     | 
| 
       222 
     | 
    
         
            -
                        // of it so that it is freed on GC
         
     | 
| 
       223 
     | 
    
         
            -
                        aggregate_call_tree_data = prof_call_tree_copy(*p_call_tree);
         
     | 
| 
       224 
     | 
    
         
            -
                        aggregate_call_tree_data->owner = OWNER_RUBY;
         
     | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
                        rb_st_insert(callers, parent->method->key, (st_data_t)aggregate_call_tree_data);
         
     | 
| 
       227 
     | 
    
         
            -
                    }
         
     | 
| 
       228 
     | 
    
         
            -
                }
         
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
                VALUE result = rb_ary_new_capa((long)callers->num_entries);
         
     | 
| 
       231 
     | 
    
         
            -
                rb_st_foreach(callers, prof_call_trees_collect, result);
         
     | 
| 
       232 
     | 
    
         
            -
                rb_st_free_table(callers);
         
     | 
| 
       233 
     | 
    
         
            -
                return result;
         
     | 
| 
       234 
     | 
    
         
            -
            }
         
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
            /* call-seq:
         
     | 
| 
       237 
     | 
    
         
            -
               callees -> array
         
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
            Returns an array of aggregated CallTree objects that this method called (ie, children).*/
         
     | 
| 
       240 
     | 
    
         
            -
            VALUE prof_call_trees_callees(VALUE self)
         
     | 
| 
       241 
     | 
    
         
            -
            {
         
     | 
| 
       242 
     | 
    
         
            -
                st_table* callees = rb_st_init_numtable();
         
     | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
     | 
    
         
            -
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
       245 
     | 
    
         
            -
                for (prof_call_tree_t** call_tree = call_trees->start; call_tree < call_trees->ptr; call_tree++)
         
     | 
| 
       246 
     | 
    
         
            -
                {
         
     | 
| 
       247 
     | 
    
         
            -
                    rb_st_foreach((*call_tree)->children, prof_call_trees_collect_callees, (st_data_t)callees);
         
     | 
| 
       248 
     | 
    
         
            -
                }
         
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
                VALUE result = rb_ary_new_capa((long)callees->num_entries);
         
     | 
| 
       251 
     | 
    
         
            -
                rb_st_foreach(callees, prof_call_trees_collect, result);
         
     | 
| 
       252 
     | 
    
         
            -
                rb_st_free_table(callees);
         
     | 
| 
       253 
     | 
    
         
            -
                return result;
         
     | 
| 
       254 
     | 
    
         
            -
            }
         
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
            /* :nodoc: */
         
     | 
| 
       257 
     | 
    
         
            -
            VALUE prof_call_trees_dump(VALUE self)
         
     | 
| 
       258 
     | 
    
         
            -
            {
         
     | 
| 
       259 
     | 
    
         
            -
                VALUE result = rb_hash_new();
         
     | 
| 
       260 
     | 
    
         
            -
                rb_hash_aset(result, ID2SYM(rb_intern("call_trees")), prof_call_trees_call_trees(self));
         
     | 
| 
       261 
     | 
    
         
            -
             
     | 
| 
       262 
     | 
    
         
            -
                return result;
         
     | 
| 
       263 
     | 
    
         
            -
            }
         
     | 
| 
       264 
     | 
    
         
            -
             
     | 
| 
       265 
     | 
    
         
            -
            /* :nodoc: */
         
     | 
| 
       266 
     | 
    
         
            -
            VALUE prof_call_trees_load(VALUE self, VALUE data)
         
     | 
| 
       267 
     | 
    
         
            -
            {
         
     | 
| 
       268 
     | 
    
         
            -
                prof_call_trees_t* call_trees_data = prof_get_call_trees(self);
         
     | 
| 
       269 
     | 
    
         
            -
                call_trees_data->object = self;
         
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
                VALUE call_trees = rb_hash_aref(data, ID2SYM(rb_intern("call_trees")));
         
     | 
| 
       272 
     | 
    
         
            -
                for (int i = 0; i < rb_array_len(call_trees); i++)
         
     | 
| 
       273 
     | 
    
         
            -
                {
         
     | 
| 
       274 
     | 
    
         
            -
                    VALUE call_tree = rb_ary_entry(call_trees, i);
         
     | 
| 
       275 
     | 
    
         
            -
                    prof_call_tree_t* call_tree_data = prof_get_call_tree(call_tree);
         
     | 
| 
       276 
     | 
    
         
            -
                    prof_add_call_tree(call_trees_data, call_tree_data);
         
     | 
| 
       277 
     | 
    
         
            -
                }
         
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
                return data;
         
     | 
| 
       280 
     | 
    
         
            -
            }
         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
            void rp_init_call_trees(void)
         
     | 
| 
       283 
     | 
    
         
            -
            {
         
     | 
| 
       284 
     | 
    
         
            -
                cRpCallTrees = rb_define_class_under(mProf, "CallTrees", rb_cObject);
         
     | 
| 
       285 
     | 
    
         
            -
                rb_undef_method(CLASS_OF(cRpCallTrees), "new");
         
     | 
| 
       286 
     | 
    
         
            -
                rb_define_alloc_func(cRpCallTrees, prof_call_trees_allocate);
         
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "min_depth", prof_call_trees_min_depth, 0);
         
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
       290 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "call_trees", prof_call_trees_call_trees, 0);
         
     | 
| 
       291 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "callers", prof_call_trees_callers, 0);
         
     | 
| 
       292 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "callees", prof_call_trees_callees, 0);
         
     | 
| 
       293 
     | 
    
         
            -
             
     | 
| 
       294 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "_dump_data", prof_call_trees_dump, 0);
         
     | 
| 
       295 
     | 
    
         
            -
                rb_define_method(cRpCallTrees, "_load_data", prof_call_trees_load, 1);
         
     | 
| 
       296 
     | 
    
         
            -
            }
         
     | 
| 
      
 1 
     | 
    
         
            +
            /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
         
     | 
| 
      
 2 
     | 
    
         
            +
               Please see the LICENSE file for copyright and distribution information */
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            #include "rp_call_trees.h"
         
     | 
| 
      
 5 
     | 
    
         
            +
            #include "rp_measurement.h"
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            #define INITIAL_CALL_TREES_SIZE 2
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            VALUE cRpCallTrees;
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            /* =======  Call Infos   ========*/
         
     | 
| 
      
 12 
     | 
    
         
            +
            prof_call_trees_t* prof_get_call_trees(VALUE self)
         
     | 
| 
      
 13 
     | 
    
         
            +
            {
         
     | 
| 
      
 14 
     | 
    
         
            +
                /* Can't use Data_Get_Struct because that triggers the event hook
         
     | 
| 
      
 15 
     | 
    
         
            +
                   ending up in endless recursion. */
         
     | 
| 
      
 16 
     | 
    
         
            +
                prof_call_trees_t* result = RTYPEDDATA_DATA(self);
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                if (!result)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    rb_raise(rb_eRuntimeError, "This RubyProf::CallTrees instance has already been freed, likely because its profile has been freed.");
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 22 
     | 
    
         
            +
            }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            prof_call_trees_t* prof_call_trees_create(void)
         
     | 
| 
      
 25 
     | 
    
         
            +
            {
         
     | 
| 
      
 26 
     | 
    
         
            +
                prof_call_trees_t* result = ALLOC(prof_call_trees_t);
         
     | 
| 
      
 27 
     | 
    
         
            +
                result->start = ALLOC_N(prof_call_tree_t*, INITIAL_CALL_TREES_SIZE);
         
     | 
| 
      
 28 
     | 
    
         
            +
                result->end = result->start + INITIAL_CALL_TREES_SIZE;
         
     | 
| 
      
 29 
     | 
    
         
            +
                result->ptr = result->start;
         
     | 
| 
      
 30 
     | 
    
         
            +
                result->object = Qnil;
         
     | 
| 
      
 31 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 32 
     | 
    
         
            +
            }
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            void prof_call_trees_mark(void* data)
         
     | 
| 
      
 35 
     | 
    
         
            +
            {
         
     | 
| 
      
 36 
     | 
    
         
            +
                if (!data) return;
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                prof_call_trees_t* call_trees = (prof_call_trees_t*)data;
         
     | 
| 
      
 39 
     | 
    
         
            +
                prof_call_tree_t** call_tree;
         
     | 
| 
      
 40 
     | 
    
         
            +
                for (call_tree = call_trees->start; call_tree < call_trees->ptr; call_tree++)
         
     | 
| 
      
 41 
     | 
    
         
            +
                {
         
     | 
| 
      
 42 
     | 
    
         
            +
                    prof_call_tree_mark(*call_tree);
         
     | 
| 
      
 43 
     | 
    
         
            +
                }
         
     | 
| 
      
 44 
     | 
    
         
            +
            }
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            void prof_call_trees_free(prof_call_trees_t* call_trees)
         
     | 
| 
      
 47 
     | 
    
         
            +
            {
         
     | 
| 
      
 48 
     | 
    
         
            +
                /* Has this method object been accessed by Ruby?  If
         
     | 
| 
      
 49 
     | 
    
         
            +
                   yes clean it up so to avoid a segmentation fault. */
         
     | 
| 
      
 50 
     | 
    
         
            +
                if (call_trees->object != Qnil)
         
     | 
| 
      
 51 
     | 
    
         
            +
                {
         
     | 
| 
      
 52 
     | 
    
         
            +
                    RTYPEDDATA(call_trees->object)->data = NULL;
         
     | 
| 
      
 53 
     | 
    
         
            +
                    call_trees->object = Qnil;
         
     | 
| 
      
 54 
     | 
    
         
            +
                }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                // Note we do not free our call_tree structures - since they have no parents they will free themselves
         
     | 
| 
      
 57 
     | 
    
         
            +
                xfree(call_trees);
         
     | 
| 
      
 58 
     | 
    
         
            +
            }
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
            void prof_call_trees_ruby_gc_free(void* data)
         
     | 
| 
      
 61 
     | 
    
         
            +
            {
         
     | 
| 
      
 62 
     | 
    
         
            +
                if (data)
         
     | 
| 
      
 63 
     | 
    
         
            +
                {
         
     | 
| 
      
 64 
     | 
    
         
            +
                    // This object gets freed by its owning method
         
     | 
| 
      
 65 
     | 
    
         
            +
                    prof_call_trees_t* call_trees = (prof_call_trees_t*)data;
         
     | 
| 
      
 66 
     | 
    
         
            +
                    call_trees->object = Qnil;
         
     | 
| 
      
 67 
     | 
    
         
            +
                }
         
     | 
| 
      
 68 
     | 
    
         
            +
            }
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            static int prof_call_trees_collect(st_data_t key, st_data_t value, st_data_t data)
         
     | 
| 
      
 71 
     | 
    
         
            +
            {
         
     | 
| 
      
 72 
     | 
    
         
            +
                VALUE result = (VALUE)data;
         
     | 
| 
      
 73 
     | 
    
         
            +
                prof_call_tree_t* call_tree_data = (prof_call_tree_t*)value;
         
     | 
| 
      
 74 
     | 
    
         
            +
                VALUE aggregate_call_tree = prof_call_tree_wrap(call_tree_data);
         
     | 
| 
      
 75 
     | 
    
         
            +
                rb_ary_push(result, aggregate_call_tree);
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                return ST_CONTINUE;
         
     | 
| 
      
 78 
     | 
    
         
            +
            }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            static int prof_call_trees_collect_callees(st_data_t key, st_data_t value, st_data_t hash)
         
     | 
| 
      
 81 
     | 
    
         
            +
            {
         
     | 
| 
      
 82 
     | 
    
         
            +
                st_table* callers = (st_table*)hash;
         
     | 
| 
      
 83 
     | 
    
         
            +
                prof_call_tree_t* call_tree_data = (prof_call_tree_t*)value;
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                prof_call_tree_t* aggregate_call_tree_data = NULL;
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                if (rb_st_lookup(callers, call_tree_data->method->key, (st_data_t*)&aggregate_call_tree_data))
         
     | 
| 
      
 88 
     | 
    
         
            +
                {
         
     | 
| 
      
 89 
     | 
    
         
            +
                  prof_measurement_merge_internal(aggregate_call_tree_data->measurement, call_tree_data->measurement);
         
     | 
| 
      
 90 
     | 
    
         
            +
                }
         
     | 
| 
      
 91 
     | 
    
         
            +
                else
         
     | 
| 
      
 92 
     | 
    
         
            +
                {
         
     | 
| 
      
 93 
     | 
    
         
            +
                    // Copy the call tree so we don't touch the original and give Ruby ownerhip 
         
     | 
| 
      
 94 
     | 
    
         
            +
                    // of it so that it is freed on GC
         
     | 
| 
      
 95 
     | 
    
         
            +
                    aggregate_call_tree_data = prof_call_tree_copy(call_tree_data);
         
     | 
| 
      
 96 
     | 
    
         
            +
                    aggregate_call_tree_data->owner = OWNER_RUBY;
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    rb_st_insert(callers, call_tree_data->method->key, (st_data_t)aggregate_call_tree_data);
         
     | 
| 
      
 100 
     | 
    
         
            +
                }
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                return ST_CONTINUE;
         
     | 
| 
      
 103 
     | 
    
         
            +
            }
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            size_t prof_call_trees_size(const void* data)
         
     | 
| 
      
 106 
     | 
    
         
            +
            {
         
     | 
| 
      
 107 
     | 
    
         
            +
                return sizeof(prof_call_trees_t);
         
     | 
| 
      
 108 
     | 
    
         
            +
            }
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            static const rb_data_type_t call_trees_type =
         
     | 
| 
      
 111 
     | 
    
         
            +
            {
         
     | 
| 
      
 112 
     | 
    
         
            +
                .wrap_struct_name = "CallTrees",
         
     | 
| 
      
 113 
     | 
    
         
            +
                .function =
         
     | 
| 
      
 114 
     | 
    
         
            +
                {
         
     | 
| 
      
 115 
     | 
    
         
            +
                    .dmark = prof_call_trees_mark,
         
     | 
| 
      
 116 
     | 
    
         
            +
                    .dfree = prof_call_trees_ruby_gc_free,
         
     | 
| 
      
 117 
     | 
    
         
            +
                    .dsize = prof_call_trees_size,
         
     | 
| 
      
 118 
     | 
    
         
            +
                },
         
     | 
| 
      
 119 
     | 
    
         
            +
                .data = NULL,
         
     | 
| 
      
 120 
     | 
    
         
            +
                .flags = RUBY_TYPED_FREE_IMMEDIATELY
         
     | 
| 
      
 121 
     | 
    
         
            +
            };
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
            VALUE prof_call_trees_wrap(prof_call_trees_t* call_trees)
         
     | 
| 
      
 124 
     | 
    
         
            +
            {
         
     | 
| 
      
 125 
     | 
    
         
            +
                if (call_trees->object == Qnil)
         
     | 
| 
      
 126 
     | 
    
         
            +
                {
         
     | 
| 
      
 127 
     | 
    
         
            +
                    call_trees->object = TypedData_Wrap_Struct(cRpCallTrees, &call_trees_type, call_trees);
         
     | 
| 
      
 128 
     | 
    
         
            +
                }
         
     | 
| 
      
 129 
     | 
    
         
            +
                return call_trees->object;
         
     | 
| 
      
 130 
     | 
    
         
            +
            }
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
            void prof_add_call_tree(prof_call_trees_t* call_trees, prof_call_tree_t* call_tree)
         
     | 
| 
      
 133 
     | 
    
         
            +
            {
         
     | 
| 
      
 134 
     | 
    
         
            +
                if (call_trees->ptr == call_trees->end)
         
     | 
| 
      
 135 
     | 
    
         
            +
                {
         
     | 
| 
      
 136 
     | 
    
         
            +
                    size_t len = call_trees->ptr - call_trees->start;
         
     | 
| 
      
 137 
     | 
    
         
            +
                    size_t new_capacity = (call_trees->end - call_trees->start) * 2;
         
     | 
| 
      
 138 
     | 
    
         
            +
                    REALLOC_N(call_trees->start, prof_call_tree_t*, new_capacity);
         
     | 
| 
      
 139 
     | 
    
         
            +
                    call_trees->ptr = call_trees->start + len;
         
     | 
| 
      
 140 
     | 
    
         
            +
                    call_trees->end = call_trees->start + new_capacity;
         
     | 
| 
      
 141 
     | 
    
         
            +
                }
         
     | 
| 
      
 142 
     | 
    
         
            +
                *call_trees->ptr = call_tree;
         
     | 
| 
      
 143 
     | 
    
         
            +
                call_trees->ptr++;
         
     | 
| 
      
 144 
     | 
    
         
            +
            }
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
            /* ================  Call Infos   =================*/
         
     | 
| 
      
 147 
     | 
    
         
            +
            /* Document-class: RubyProf::CallTrees
         
     | 
| 
      
 148 
     | 
    
         
            +
            The RubyProf::MethodInfo class stores profiling data for a method.
         
     | 
| 
      
 149 
     | 
    
         
            +
            One instance of the RubyProf::MethodInfo class is created per method
         
     | 
| 
      
 150 
     | 
    
         
            +
            called per thread.  Thus, if a method is called in two different
         
     | 
| 
      
 151 
     | 
    
         
            +
            thread then there will be two RubyProf::MethodInfo objects
         
     | 
| 
      
 152 
     | 
    
         
            +
            created.  RubyProf::MethodInfo objects can be accessed via
         
     | 
| 
      
 153 
     | 
    
         
            +
            the RubyProf::Profile object. */
         
     | 
| 
      
 154 
     | 
    
         
            +
            VALUE prof_call_trees_allocate(VALUE klass)
         
     | 
| 
      
 155 
     | 
    
         
            +
            {
         
     | 
| 
      
 156 
     | 
    
         
            +
                prof_call_trees_t* call_trees_data = prof_call_trees_create();
         
     | 
| 
      
 157 
     | 
    
         
            +
                call_trees_data->object = prof_call_trees_wrap(call_trees_data);
         
     | 
| 
      
 158 
     | 
    
         
            +
                return call_trees_data->object;
         
     | 
| 
      
 159 
     | 
    
         
            +
            }
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
            /* call-seq:
         
     | 
| 
      
 163 
     | 
    
         
            +
               min_depth -> Integer
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
            Returns the minimum depth of this method in any call tree */
         
     | 
| 
      
 166 
     | 
    
         
            +
            VALUE prof_call_trees_min_depth(VALUE self)
         
     | 
| 
      
 167 
     | 
    
         
            +
            {
         
     | 
| 
      
 168 
     | 
    
         
            +
                unsigned int depth = INT_MAX;
         
     | 
| 
      
 169 
     | 
    
         
            +
             
     | 
| 
      
 170 
     | 
    
         
            +
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
      
 171 
     | 
    
         
            +
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
      
 172 
     | 
    
         
            +
                {
         
     | 
| 
      
 173 
     | 
    
         
            +
                    unsigned int call_tree_depth = prof_call_tree_figure_depth(*p_call_tree);
         
     | 
| 
      
 174 
     | 
    
         
            +
                    if (call_tree_depth < depth)
         
     | 
| 
      
 175 
     | 
    
         
            +
                        depth = call_tree_depth;
         
     | 
| 
      
 176 
     | 
    
         
            +
                }
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
      
 178 
     | 
    
         
            +
                return UINT2NUM(depth);
         
     | 
| 
      
 179 
     | 
    
         
            +
            }
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
      
 181 
     | 
    
         
            +
            /* call-seq:
         
     | 
| 
      
 182 
     | 
    
         
            +
               callers -> array
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
            Returns an array of all CallTree objects that called this method. */
         
     | 
| 
      
 185 
     | 
    
         
            +
            VALUE prof_call_trees_call_trees(VALUE self)
         
     | 
| 
      
 186 
     | 
    
         
            +
            {
         
     | 
| 
      
 187 
     | 
    
         
            +
                VALUE result = rb_ary_new();
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
      
 190 
     | 
    
         
            +
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
      
 191 
     | 
    
         
            +
                {
         
     | 
| 
      
 192 
     | 
    
         
            +
                    VALUE call_tree = prof_call_tree_wrap(*p_call_tree);
         
     | 
| 
      
 193 
     | 
    
         
            +
                    rb_ary_push(result, call_tree);
         
     | 
| 
      
 194 
     | 
    
         
            +
                }
         
     | 
| 
      
 195 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 196 
     | 
    
         
            +
            }
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
            /* call-seq:
         
     | 
| 
      
 199 
     | 
    
         
            +
               callers -> array
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
            Returns an array of aggregated CallTree objects that called this method (ie, parents).*/
         
     | 
| 
      
 202 
     | 
    
         
            +
            VALUE prof_call_trees_callers(VALUE self)
         
     | 
| 
      
 203 
     | 
    
         
            +
            {
         
     | 
| 
      
 204 
     | 
    
         
            +
                st_table* callers = rb_st_init_numtable();
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
      
 207 
     | 
    
         
            +
                for (prof_call_tree_t** p_call_tree = call_trees->start; p_call_tree < call_trees->ptr; p_call_tree++)
         
     | 
| 
      
 208 
     | 
    
         
            +
                {
         
     | 
| 
      
 209 
     | 
    
         
            +
                    prof_call_tree_t* parent = (*p_call_tree)->parent;
         
     | 
| 
      
 210 
     | 
    
         
            +
                    if (parent == NULL)
         
     | 
| 
      
 211 
     | 
    
         
            +
                        continue;
         
     | 
| 
      
 212 
     | 
    
         
            +
             
     | 
| 
      
 213 
     | 
    
         
            +
                    prof_call_tree_t* aggregate_call_tree_data = NULL;
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                    if (rb_st_lookup(callers, parent->method->key, (st_data_t*)&aggregate_call_tree_data))
         
     | 
| 
      
 216 
     | 
    
         
            +
                    {
         
     | 
| 
      
 217 
     | 
    
         
            +
                      prof_measurement_merge_internal(aggregate_call_tree_data->measurement, (*p_call_tree)->measurement);
         
     | 
| 
      
 218 
     | 
    
         
            +
                    }
         
     | 
| 
      
 219 
     | 
    
         
            +
                    else
         
     | 
| 
      
 220 
     | 
    
         
            +
                    {
         
     | 
| 
      
 221 
     | 
    
         
            +
                        // Copy the call tree so we don't touch the original and give Ruby ownerhip 
         
     | 
| 
      
 222 
     | 
    
         
            +
                        // of it so that it is freed on GC
         
     | 
| 
      
 223 
     | 
    
         
            +
                        aggregate_call_tree_data = prof_call_tree_copy(*p_call_tree);
         
     | 
| 
      
 224 
     | 
    
         
            +
                        aggregate_call_tree_data->owner = OWNER_RUBY;
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                        rb_st_insert(callers, parent->method->key, (st_data_t)aggregate_call_tree_data);
         
     | 
| 
      
 227 
     | 
    
         
            +
                    }
         
     | 
| 
      
 228 
     | 
    
         
            +
                }
         
     | 
| 
      
 229 
     | 
    
         
            +
             
     | 
| 
      
 230 
     | 
    
         
            +
                VALUE result = rb_ary_new_capa((long)callers->num_entries);
         
     | 
| 
      
 231 
     | 
    
         
            +
                rb_st_foreach(callers, prof_call_trees_collect, result);
         
     | 
| 
      
 232 
     | 
    
         
            +
                rb_st_free_table(callers);
         
     | 
| 
      
 233 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 234 
     | 
    
         
            +
            }
         
     | 
| 
      
 235 
     | 
    
         
            +
             
     | 
| 
      
 236 
     | 
    
         
            +
            /* call-seq:
         
     | 
| 
      
 237 
     | 
    
         
            +
               callees -> array
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
            Returns an array of aggregated CallTree objects that this method called (ie, children).*/
         
     | 
| 
      
 240 
     | 
    
         
            +
            VALUE prof_call_trees_callees(VALUE self)
         
     | 
| 
      
 241 
     | 
    
         
            +
            {
         
     | 
| 
      
 242 
     | 
    
         
            +
                st_table* callees = rb_st_init_numtable();
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
                prof_call_trees_t* call_trees = prof_get_call_trees(self);
         
     | 
| 
      
 245 
     | 
    
         
            +
                for (prof_call_tree_t** call_tree = call_trees->start; call_tree < call_trees->ptr; call_tree++)
         
     | 
| 
      
 246 
     | 
    
         
            +
                {
         
     | 
| 
      
 247 
     | 
    
         
            +
                    rb_st_foreach((*call_tree)->children, prof_call_trees_collect_callees, (st_data_t)callees);
         
     | 
| 
      
 248 
     | 
    
         
            +
                }
         
     | 
| 
      
 249 
     | 
    
         
            +
             
     | 
| 
      
 250 
     | 
    
         
            +
                VALUE result = rb_ary_new_capa((long)callees->num_entries);
         
     | 
| 
      
 251 
     | 
    
         
            +
                rb_st_foreach(callees, prof_call_trees_collect, result);
         
     | 
| 
      
 252 
     | 
    
         
            +
                rb_st_free_table(callees);
         
     | 
| 
      
 253 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 254 
     | 
    
         
            +
            }
         
     | 
| 
      
 255 
     | 
    
         
            +
             
     | 
| 
      
 256 
     | 
    
         
            +
            /* :nodoc: */
         
     | 
| 
      
 257 
     | 
    
         
            +
            VALUE prof_call_trees_dump(VALUE self)
         
     | 
| 
      
 258 
     | 
    
         
            +
            {
         
     | 
| 
      
 259 
     | 
    
         
            +
                VALUE result = rb_hash_new();
         
     | 
| 
      
 260 
     | 
    
         
            +
                rb_hash_aset(result, ID2SYM(rb_intern("call_trees")), prof_call_trees_call_trees(self));
         
     | 
| 
      
 261 
     | 
    
         
            +
             
     | 
| 
      
 262 
     | 
    
         
            +
                return result;
         
     | 
| 
      
 263 
     | 
    
         
            +
            }
         
     | 
| 
      
 264 
     | 
    
         
            +
             
     | 
| 
      
 265 
     | 
    
         
            +
            /* :nodoc: */
         
     | 
| 
      
 266 
     | 
    
         
            +
            VALUE prof_call_trees_load(VALUE self, VALUE data)
         
     | 
| 
      
 267 
     | 
    
         
            +
            {
         
     | 
| 
      
 268 
     | 
    
         
            +
                prof_call_trees_t* call_trees_data = prof_get_call_trees(self);
         
     | 
| 
      
 269 
     | 
    
         
            +
                call_trees_data->object = self;
         
     | 
| 
      
 270 
     | 
    
         
            +
             
     | 
| 
      
 271 
     | 
    
         
            +
                VALUE call_trees = rb_hash_aref(data, ID2SYM(rb_intern("call_trees")));
         
     | 
| 
      
 272 
     | 
    
         
            +
                for (int i = 0; i < rb_array_len(call_trees); i++)
         
     | 
| 
      
 273 
     | 
    
         
            +
                {
         
     | 
| 
      
 274 
     | 
    
         
            +
                    VALUE call_tree = rb_ary_entry(call_trees, i);
         
     | 
| 
      
 275 
     | 
    
         
            +
                    prof_call_tree_t* call_tree_data = prof_get_call_tree(call_tree);
         
     | 
| 
      
 276 
     | 
    
         
            +
                    prof_add_call_tree(call_trees_data, call_tree_data);
         
     | 
| 
      
 277 
     | 
    
         
            +
                }
         
     | 
| 
      
 278 
     | 
    
         
            +
             
     | 
| 
      
 279 
     | 
    
         
            +
                return data;
         
     | 
| 
      
 280 
     | 
    
         
            +
            }
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
            void rp_init_call_trees(void)
         
     | 
| 
      
 283 
     | 
    
         
            +
            {
         
     | 
| 
      
 284 
     | 
    
         
            +
                cRpCallTrees = rb_define_class_under(mProf, "CallTrees", rb_cObject);
         
     | 
| 
      
 285 
     | 
    
         
            +
                rb_undef_method(CLASS_OF(cRpCallTrees), "new");
         
     | 
| 
      
 286 
     | 
    
         
            +
                rb_define_alloc_func(cRpCallTrees, prof_call_trees_allocate);
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "min_depth", prof_call_trees_min_depth, 0);
         
     | 
| 
      
 289 
     | 
    
         
            +
             
     | 
| 
      
 290 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "call_trees", prof_call_trees_call_trees, 0);
         
     | 
| 
      
 291 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "callers", prof_call_trees_callers, 0);
         
     | 
| 
      
 292 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "callees", prof_call_trees_callees, 0);
         
     | 
| 
      
 293 
     | 
    
         
            +
             
     | 
| 
      
 294 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "_dump_data", prof_call_trees_dump, 0);
         
     | 
| 
      
 295 
     | 
    
         
            +
                rb_define_method(cRpCallTrees, "_load_data", prof_call_trees_load, 1);
         
     | 
| 
      
 296 
     | 
    
         
            +
            }
         
     |