ruby-prof 0.8.1-x86-mingw32 → 0.11.0.rc1-x86-mingw32
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.
- data/CHANGES +89 -13
- data/LICENSE +4 -3
- data/{README → README.rdoc} +155 -162
- data/Rakefile +50 -123
- data/bin/ruby-prof +86 -47
- data/examples/empty.png +0 -0
- data/examples/graph.dot +106 -0
- data/examples/graph.png +0 -0
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +23 -0
- data/examples/multi.graph.html +906 -0
- data/examples/multi.grind.dat +194 -0
- data/examples/multi.stack.html +573 -0
- data/examples/plus.png +0 -0
- data/examples/stack.html +573 -0
- data/ext/ruby_prof/extconf.rb +53 -0
- data/ext/ruby_prof/rp_call_info.c +369 -0
- data/ext/ruby_prof/rp_call_info.h +46 -0
- data/ext/ruby_prof/rp_measure.c +48 -0
- data/ext/ruby_prof/rp_measure.h +45 -0
- data/ext/ruby_prof/rp_measure_allocations.c +86 -0
- data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
- data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
- data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
- data/ext/ruby_prof/rp_measure_memory.c +81 -0
- data/ext/ruby_prof/rp_measure_process_time.c +71 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
- data/ext/ruby_prof/rp_method.c +363 -0
- data/ext/ruby_prof/rp_method.h +55 -0
- data/ext/ruby_prof/rp_stack.c +61 -0
- data/ext/ruby_prof/rp_stack.h +40 -0
- data/ext/ruby_prof/rp_thread.c +113 -0
- data/ext/ruby_prof/rp_thread.h +20 -0
- data/ext/ruby_prof/ruby_prof.c +332 -1377
- data/ext/ruby_prof/ruby_prof.h +54 -188
- data/ext/ruby_prof/version.h +6 -3
- data/lib/1.8/ruby_prof.so +0 -0
- data/lib/1.9/ruby_prof.exp +0 -0
- data/lib/1.9/ruby_prof.ilk +0 -0
- data/lib/1.9/ruby_prof.lib +0 -0
- data/lib/1.9/ruby_prof.pdb +0 -0
- data/lib/1.9/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +32 -18
- data/lib/ruby-prof/abstract_printer.rb +15 -5
- data/lib/ruby-prof/aggregate_call_info.rb +11 -3
- data/lib/ruby-prof/call_info.rb +68 -1
- data/lib/ruby-prof/call_stack_printer.rb +775 -0
- data/lib/ruby-prof/call_tree_printer.rb +17 -9
- data/lib/ruby-prof/compatibility.rb +134 -0
- data/lib/ruby-prof/dot_printer.rb +152 -0
- data/lib/ruby-prof/empty.png +0 -0
- data/lib/ruby-prof/flat_printer.rb +23 -24
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +17 -21
- data/lib/ruby-prof/graph_html_printer.rb +69 -39
- data/lib/ruby-prof/graph_printer.rb +35 -35
- data/lib/ruby-prof/method_info.rb +26 -4
- data/lib/ruby-prof/minus.png +0 -0
- data/lib/ruby-prof/multi_printer.rb +56 -0
- data/lib/ruby-prof/plus.png +0 -0
- data/lib/ruby-prof/profile.rb +72 -0
- data/lib/ruby-prof/rack.rb +31 -0
- data/lib/ruby-prof/symbol_to_proc.rb +3 -1
- data/lib/ruby-prof/task.rb +20 -19
- data/lib/ruby-prof/test.rb +5 -3
- data/lib/ruby_prof.exp +0 -0
- data/lib/ruby_prof.ilk +0 -0
- data/lib/ruby_prof.lib +0 -0
- data/lib/ruby_prof.pdb +0 -0
- data/lib/ruby_prof.so +0 -0
- data/lib/unprof.rb +2 -0
- data/test/aggregate_test.rb +29 -14
- data/test/basic_test.rb +3 -251
- data/test/bug_test.rb +6 -0
- data/test/duplicate_names_test.rb +4 -4
- data/test/dynamic_method_test.rb +61 -0
- data/test/enumerable_test.rb +4 -4
- data/test/exceptions_test.rb +6 -5
- data/test/exclude_threads_test.rb +47 -47
- data/test/exec_test.rb +5 -5
- data/test/line_number_test.rb +16 -16
- data/test/measure_allocations_test.rb +25 -0
- data/test/measure_cpu_time_test.rb +212 -0
- data/test/measure_gc_runs_test.rb +29 -0
- data/test/measure_gc_time_test.rb +29 -0
- data/test/measure_memory_test.rb +36 -0
- data/test/measure_process_time_test.rb +205 -0
- data/test/measure_wall_time_test.rb +209 -0
- data/test/method_elimination_test.rb +74 -0
- data/test/module_test.rb +12 -21
- data/test/multi_printer_test.rb +81 -0
- data/test/no_method_class_test.rb +5 -3
- data/test/prime.rb +7 -10
- data/test/prime_test.rb +3 -3
- data/test/printers_test.rb +180 -54
- data/test/recursive_test.rb +34 -72
- data/test/singleton_test.rb +5 -4
- data/test/stack_printer_test.rb +73 -0
- data/test/stack_test.rb +7 -7
- data/test/start_stop_test.rb +23 -6
- data/test/test_helper.rb +81 -0
- data/test/test_suite.rb +35 -21
- data/test/thread_test.rb +40 -39
- data/test/unique_call_path_test.rb +6 -6
- metadata +106 -51
- data/ext/ruby_prof/measure_allocations.h +0 -58
- data/ext/ruby_prof/measure_cpu_time.h +0 -152
- data/ext/ruby_prof/measure_gc_runs.h +0 -76
- data/ext/ruby_prof/measure_gc_time.h +0 -57
- data/ext/ruby_prof/measure_memory.h +0 -101
- data/ext/ruby_prof/measure_process_time.h +0 -52
- data/ext/ruby_prof/measure_wall_time.h +0 -53
- data/ext/ruby_prof/mingw/Rakefile +0 -23
- data/ext/ruby_prof/mingw/build.rake +0 -38
- data/rails/environment/profile.rb +0 -24
- data/rails/example/example_test.rb +0 -9
- data/rails/profile_test_helper.rb +0 -21
- data/test/current_failures_windows +0 -8
- data/test/measurement_test.rb +0 -121
- data/test/ruby-prof-bin +0 -20
@@ -0,0 +1,48 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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 "ruby_prof.h"
|
5
|
+
|
6
|
+
VALUE mMeasure;
|
7
|
+
|
8
|
+
prof_measurer_t* prof_get_measurer(prof_measure_mode_t measure)
|
9
|
+
{
|
10
|
+
switch (measure)
|
11
|
+
{
|
12
|
+
case MEASURE_ALLOCATIONS:
|
13
|
+
return prof_measurer_allocations();
|
14
|
+
break;
|
15
|
+
case MEASURE_CPU_TIME:
|
16
|
+
return prof_measurer_cpu_time();
|
17
|
+
break;
|
18
|
+
case MEASURE_GC_RUNS:
|
19
|
+
return prof_measurer_gc_runs();
|
20
|
+
break;
|
21
|
+
case MEASURE_GC_TIME:
|
22
|
+
return prof_measurer_gc_time();
|
23
|
+
break;
|
24
|
+
case MEASURE_MEMORY:
|
25
|
+
return prof_measurer_memory();
|
26
|
+
break;
|
27
|
+
case MEASURE_PROCESS_TIME:
|
28
|
+
return prof_measurer_process_time();
|
29
|
+
break;
|
30
|
+
case MEASURE_WALL_TIME:
|
31
|
+
return prof_measurer_wall_time();
|
32
|
+
break;
|
33
|
+
default:
|
34
|
+
rb_raise(rb_eArgError, "Unknown measure mode: %d", measure);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
void rp_init_measure()
|
39
|
+
{
|
40
|
+
mMeasure = rb_define_module_under(mProf, "Measure");
|
41
|
+
rp_init_measure_allocations();
|
42
|
+
rp_init_measure_cpu_time();
|
43
|
+
rp_init_measure_gc_runs();
|
44
|
+
rp_init_measure_gc_time();
|
45
|
+
rp_init_measure_memory();
|
46
|
+
rp_init_measure_process_time();
|
47
|
+
rp_init_measure_wall_time();
|
48
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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
|
+
#ifndef __RP_MEASUREMENT_H__
|
5
|
+
#define __RP_MEASUREMENT_H__
|
6
|
+
|
7
|
+
extern VALUE mMeasure;
|
8
|
+
|
9
|
+
typedef double (*get_measurement)();
|
10
|
+
|
11
|
+
typedef struct
|
12
|
+
{
|
13
|
+
get_measurement measure;
|
14
|
+
} prof_measurer_t;
|
15
|
+
|
16
|
+
typedef enum
|
17
|
+
{
|
18
|
+
MEASURE_ALLOCATIONS,
|
19
|
+
MEASURE_CPU_TIME,
|
20
|
+
MEASURE_GC_RUNS,
|
21
|
+
MEASURE_GC_TIME,
|
22
|
+
MEASURE_MEMORY,
|
23
|
+
MEASURE_PROCESS_TIME,
|
24
|
+
MEASURE_WALL_TIME,
|
25
|
+
} prof_measure_mode_t;
|
26
|
+
|
27
|
+
prof_measurer_t* prof_get_measurer(prof_measure_mode_t measure);
|
28
|
+
prof_measurer_t* prof_measurer_allocations();
|
29
|
+
prof_measurer_t* prof_measurer_cpu_time();
|
30
|
+
prof_measurer_t* prof_measurer_gc_runs();
|
31
|
+
prof_measurer_t* prof_measurer_gc_time();
|
32
|
+
prof_measurer_t* prof_measurer_memory();
|
33
|
+
prof_measurer_t* prof_measurer_process_time();
|
34
|
+
prof_measurer_t* prof_measurer_wall_time();
|
35
|
+
|
36
|
+
void rp_init_measure();
|
37
|
+
void rp_init_measure_allocations();
|
38
|
+
void rp_init_measure_cpu_time();
|
39
|
+
void rp_init_measure_gc_runs();
|
40
|
+
void rp_init_measure_gc_time();
|
41
|
+
void rp_init_measure_memory();
|
42
|
+
void rp_init_measure_process_time();
|
43
|
+
void rp_init_measure_wall_time();
|
44
|
+
|
45
|
+
#endif //__RP_MEASUREMENT_H__
|
@@ -0,0 +1,86 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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
|
+
/* :nodoc: */
|
5
|
+
|
6
|
+
#include "ruby_prof.h"
|
7
|
+
|
8
|
+
static VALUE cMeasureAllocations;
|
9
|
+
|
10
|
+
#if defined(HAVE_RB_OS_ALLOCATED_OBJECTS)
|
11
|
+
#define MEASURE_ALLOCATIONS_ENABLED Qtrue
|
12
|
+
|
13
|
+
static double
|
14
|
+
measure_allocations()
|
15
|
+
{
|
16
|
+
return rb_os_allocated_objects();
|
17
|
+
}
|
18
|
+
|
19
|
+
/* Document-method: prof_measure_allocations
|
20
|
+
call-seq:
|
21
|
+
measure_allocations -> int
|
22
|
+
|
23
|
+
Returns the total number of object allocations since Ruby started.*/
|
24
|
+
static VALUE
|
25
|
+
prof_measure_allocations(VALUE self)
|
26
|
+
{
|
27
|
+
#if defined(HAVE_LONG_LONG)
|
28
|
+
return ULL2NUM(rb_os_allocated_objects());
|
29
|
+
#else
|
30
|
+
return ULONG2NUM(rb_os_allocated_objects());
|
31
|
+
#endif
|
32
|
+
}
|
33
|
+
|
34
|
+
#elif defined(HAVE_RB_GC_MALLOC_ALLOCATIONS)
|
35
|
+
|
36
|
+
#define MEASURE_ALLOCATIONS_ENABLED Qtrue
|
37
|
+
|
38
|
+
static double
|
39
|
+
measure_allocations()
|
40
|
+
{
|
41
|
+
return rb_gc_malloc_allocations();
|
42
|
+
}
|
43
|
+
|
44
|
+
#else
|
45
|
+
|
46
|
+
#define MEASURE_ALLOCATIONS_ENABLED Qfalse
|
47
|
+
|
48
|
+
static double
|
49
|
+
measure_allocations()
|
50
|
+
{
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
#endif
|
55
|
+
|
56
|
+
|
57
|
+
prof_measurer_t* prof_measurer_allocations()
|
58
|
+
{
|
59
|
+
prof_measurer_t* measure = ALLOC(prof_measurer_t);
|
60
|
+
measure->measure = measure_allocations;
|
61
|
+
return measure;
|
62
|
+
}
|
63
|
+
|
64
|
+
/* call-seq:
|
65
|
+
measure -> int
|
66
|
+
|
67
|
+
Returns the number of Ruby object allocations. */
|
68
|
+
|
69
|
+
static VALUE
|
70
|
+
prof_measure_allocations(VALUE self)
|
71
|
+
{
|
72
|
+
#if defined(HAVE_LONG_LONG)
|
73
|
+
return ULL2NUM(measure_allocations());
|
74
|
+
#else
|
75
|
+
return ULONG2NUM(measure_allocations());
|
76
|
+
#endif
|
77
|
+
}
|
78
|
+
|
79
|
+
void rp_init_measure_allocations()
|
80
|
+
{
|
81
|
+
rb_define_const(mProf, "ALLOCATIONS", INT2NUM(MEASURE_ALLOCATIONS));
|
82
|
+
rb_define_const(mProf, "ALLOCATIONS_ENABLED", MEASURE_ALLOCATIONS_ENABLED);
|
83
|
+
|
84
|
+
cMeasureAllocations = rb_define_class_under(mMeasure, "Allocations", rb_cObject);
|
85
|
+
rb_define_singleton_method(cMeasureAllocations, "measure", prof_measure_allocations, 0);
|
86
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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 "ruby_prof.h"
|
5
|
+
|
6
|
+
static VALUE cMeasureCpuTime;
|
7
|
+
|
8
|
+
static unsigned long long cpu_frequency = 0;
|
9
|
+
|
10
|
+
/* The _WIN32 check is needed for msys (and maybe cygwin?) */
|
11
|
+
#if defined(__GNUC__) && !defined(_WIN32)
|
12
|
+
|
13
|
+
#include <stdint.h>
|
14
|
+
#include <time.h>
|
15
|
+
|
16
|
+
static unsigned long long get_cpu_time()
|
17
|
+
{
|
18
|
+
#if defined(__i386__) || defined(__x86_64__)
|
19
|
+
uint32_t a, d;
|
20
|
+
__asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
|
21
|
+
return ((uint64_t)d << 32) + a;
|
22
|
+
#elif defined(__powerpc__) || defined(__ppc__)
|
23
|
+
unsigned long long x, y;
|
24
|
+
|
25
|
+
__asm__ __volatile__ ("\n\
|
26
|
+
1: mftbu %1\n\
|
27
|
+
mftb %L0\n\
|
28
|
+
mftbu %0\n\
|
29
|
+
cmpw %0,%1\n\
|
30
|
+
bne- 1b"
|
31
|
+
: "=r" (x), "=r" (y));
|
32
|
+
return x;
|
33
|
+
#endif
|
34
|
+
}
|
35
|
+
|
36
|
+
static unsigned long long get_cpu_frequency()
|
37
|
+
{
|
38
|
+
unsigned long long x, y;
|
39
|
+
|
40
|
+
struct timespec ts;
|
41
|
+
ts.tv_sec = 0;
|
42
|
+
ts.tv_nsec = 500000000;
|
43
|
+
x = get_cpu_time();
|
44
|
+
nanosleep(&ts, NULL);
|
45
|
+
y = get_cpu_time();
|
46
|
+
return (y - x) * 2;
|
47
|
+
}
|
48
|
+
|
49
|
+
#elif defined(_WIN32)
|
50
|
+
|
51
|
+
static unsigned long long get_cpu_time()
|
52
|
+
{
|
53
|
+
LARGE_INTEGER time;
|
54
|
+
QueryPerformanceCounter(&time);
|
55
|
+
return time.QuadPart;
|
56
|
+
};
|
57
|
+
|
58
|
+
static unsigned long long get_cpu_frequency()
|
59
|
+
{
|
60
|
+
LARGE_INTEGER cpu_frequency;
|
61
|
+
QueryPerformanceFrequency(&cpu_frequency);
|
62
|
+
return cpu_frequency.QuadPart;
|
63
|
+
};
|
64
|
+
#endif
|
65
|
+
|
66
|
+
static double
|
67
|
+
measure_cpu_time()
|
68
|
+
{
|
69
|
+
return ((double)get_cpu_time()) / cpu_frequency;
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
prof_measurer_t* prof_measurer_cpu_time()
|
74
|
+
{
|
75
|
+
prof_measurer_t* measure = ALLOC(prof_measurer_t);
|
76
|
+
measure->measure = measure_cpu_time;
|
77
|
+
return measure;
|
78
|
+
}
|
79
|
+
|
80
|
+
/* call-seq:
|
81
|
+
measure -> float
|
82
|
+
|
83
|
+
Returns the cpu time.*/
|
84
|
+
static VALUE
|
85
|
+
prof_measure_cpu_time(VALUE self)
|
86
|
+
{
|
87
|
+
return rb_float_new(measure_cpu_time());
|
88
|
+
}
|
89
|
+
|
90
|
+
/* call-seq:
|
91
|
+
cpu_frequency -> int
|
92
|
+
|
93
|
+
Returns the cpu's frequency. This value is needed when
|
94
|
+
RubyProf::measure_mode is set to CPU_TIME. */
|
95
|
+
static VALUE
|
96
|
+
prof_get_cpu_frequency(VALUE self)
|
97
|
+
{
|
98
|
+
return ULL2NUM(cpu_frequency);
|
99
|
+
}
|
100
|
+
|
101
|
+
void rp_init_measure_cpu_time()
|
102
|
+
{
|
103
|
+
rb_define_const(mProf, "CPU_TIME", INT2NUM(MEASURE_CPU_TIME));
|
104
|
+
rb_define_const(mProf, "CPU_TIME_ENABLED", Qtrue);
|
105
|
+
|
106
|
+
cMeasureCpuTime = rb_define_class_under(mMeasure, "CpuTime", rb_cObject);
|
107
|
+
rb_define_singleton_method(cMeasureCpuTime, "measure", prof_measure_cpu_time, 0);
|
108
|
+
rb_define_singleton_method(cMeasureCpuTime, "frequency", prof_get_cpu_frequency, 0);
|
109
|
+
|
110
|
+
/* Get cpu_frequency */
|
111
|
+
cpu_frequency = get_cpu_frequency();
|
112
|
+
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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
|
+
/* :nodoc: */
|
5
|
+
|
6
|
+
#include "ruby_prof.h"
|
7
|
+
|
8
|
+
static VALUE cMeasureGcRuns;
|
9
|
+
|
10
|
+
#if defined(HAVE_RB_GC_COLLECTIONS)
|
11
|
+
|
12
|
+
#define MEASURE_GC_RUNS_ENABLED Qtrue
|
13
|
+
|
14
|
+
static double
|
15
|
+
measure_gc_runs()
|
16
|
+
{
|
17
|
+
return NUM2INT(rb_gc_collections());
|
18
|
+
}
|
19
|
+
|
20
|
+
/* call-seq:
|
21
|
+
gc_runs -> Integer
|
22
|
+
|
23
|
+
Returns the total number of garbage collections.*/
|
24
|
+
static VALUE
|
25
|
+
prof_measure_gc_runs(VALUE self)
|
26
|
+
{
|
27
|
+
return rb_gc_collections();
|
28
|
+
}
|
29
|
+
|
30
|
+
#elif defined(HAVE_RB_GC_HEAP_INFO)
|
31
|
+
|
32
|
+
#define MEASURE_GC_RUNS_ENABLED Qtrue
|
33
|
+
|
34
|
+
static double
|
35
|
+
measure_gc_runs()
|
36
|
+
{
|
37
|
+
VALUE h = rb_gc_heap_info();
|
38
|
+
return NUM2UINT(rb_hash_aref(h, rb_str_new2("num_gc_passes")));
|
39
|
+
}
|
40
|
+
|
41
|
+
static VALUE
|
42
|
+
prof_measure_gc_runs(VALUE self)
|
43
|
+
{
|
44
|
+
VALUE h = rb_gc_heap_info();
|
45
|
+
return rb_hash_aref(h, rb_str_new2("num_gc_passes"));
|
46
|
+
}
|
47
|
+
|
48
|
+
#else
|
49
|
+
|
50
|
+
#define MEASURE_GC_RUNS_ENABLED Qfalse
|
51
|
+
|
52
|
+
static double
|
53
|
+
measure_gc_runs()
|
54
|
+
{
|
55
|
+
return 0;
|
56
|
+
}
|
57
|
+
#endif
|
58
|
+
|
59
|
+
prof_measurer_t* prof_measurer_gc_runs()
|
60
|
+
{
|
61
|
+
prof_measurer_t* measure = ALLOC(prof_measurer_t);
|
62
|
+
measure->measure = measure_gc_runs;
|
63
|
+
return measure;
|
64
|
+
}
|
65
|
+
|
66
|
+
/* call-seq:
|
67
|
+
measure -> int
|
68
|
+
|
69
|
+
Returns the number of GC runs.*/
|
70
|
+
static VALUE
|
71
|
+
prof_measure_gc_runs(VALUE self)
|
72
|
+
{
|
73
|
+
#if defined(HAVE_LONG_LONG)
|
74
|
+
return ULL2NUM(measure_gc_runs());
|
75
|
+
#else
|
76
|
+
return ULONG2NUM(measure_gc_runs());
|
77
|
+
#endif
|
78
|
+
}
|
79
|
+
|
80
|
+
void rp_init_measure_gc_runs()
|
81
|
+
{
|
82
|
+
rb_define_const(mProf, "GC_RUNS", INT2NUM(MEASURE_GC_RUNS));
|
83
|
+
rb_define_const(mProf, "GC_RUNS_ENABLED", MEASURE_GC_RUNS_ENABLED);
|
84
|
+
|
85
|
+
cMeasureGcRuns = rb_define_class_under(mMeasure, "GcRuns", rb_cObject);
|
86
|
+
rb_define_singleton_method(cMeasureGcRuns, "measure", prof_measure_gc_runs, 0);
|
87
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/* Copyright (C) 2005-2011 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
|
+
/* :nodoc: */
|
5
|
+
|
6
|
+
#include "ruby_prof.h"
|
7
|
+
|
8
|
+
static VALUE cMeasureGcTimes;
|
9
|
+
|
10
|
+
#if defined(HAVE_RB_GC_TIME)
|
11
|
+
|
12
|
+
#define MEASURE_GC_TIME_ENABLED Qtrue
|
13
|
+
|
14
|
+
static double
|
15
|
+
measure_gc_time()
|
16
|
+
{
|
17
|
+
int conversion = 1000000
|
18
|
+
#if HAVE_LONG_LONG
|
19
|
+
return NUM2LL(rb_gc_time() / conversion);
|
20
|
+
#else
|
21
|
+
return NUM2LONG(rb_gc_time() / conversion));
|
22
|
+
#endif
|
23
|
+
}
|
24
|
+
|
25
|
+
/* call-seq:
|
26
|
+
gc_time -> Integer
|
27
|
+
|
28
|
+
Returns the time spent doing garbage collections in microseconds.*/
|
29
|
+
static VALUE
|
30
|
+
prof_measure_gc_time(VALUE self)
|
31
|
+
{
|
32
|
+
return rb_gc_time();
|
33
|
+
}
|
34
|
+
|
35
|
+
#else
|
36
|
+
|
37
|
+
#define MEASURE_GC_TIME_ENABLED Qfalse
|
38
|
+
|
39
|
+
static double
|
40
|
+
measure_gc_time()
|
41
|
+
{
|
42
|
+
return 0;
|
43
|
+
}
|
44
|
+
#endif
|
45
|
+
|
46
|
+
prof_measurer_t* prof_measurer_gc_time()
|
47
|
+
{
|
48
|
+
prof_measurer_t* measure = ALLOC(prof_measurer_t);
|
49
|
+
measure->measure = measure_gc_time;
|
50
|
+
return measure;
|
51
|
+
}
|
52
|
+
|
53
|
+
/* call-seq:
|
54
|
+
measure -> float
|
55
|
+
|
56
|
+
Returns the number of GC runs.*/
|
57
|
+
static VALUE
|
58
|
+
prof_measure_gc_time(VALUE self)
|
59
|
+
{
|
60
|
+
#if defined(HAVE_LONG_LONG)
|
61
|
+
return ULL2NUM(measure_gc_time());
|
62
|
+
#else
|
63
|
+
return ULONG2NUM(measure_gc_time());
|
64
|
+
#endif
|
65
|
+
}
|
66
|
+
void rp_init_measure_gc_time()
|
67
|
+
{
|
68
|
+
rb_define_const(mProf, "GC_TIME", INT2NUM(MEASURE_GC_TIME));
|
69
|
+
rb_define_const(mProf, "GC_TIME_ENABLED", MEASURE_GC_TIME_ENABLED);
|
70
|
+
|
71
|
+
cMeasureGcTimes = rb_define_class_under(mMeasure, "GcTime", rb_cObject);
|
72
|
+
rb_define_singleton_method(cMeasureGcTimes, "measure", prof_measure_gc_time, 0);
|
73
|
+
}
|