rdp-ruby-prof 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGES +202 -0
  2. data/LICENSE +23 -0
  3. data/README +445 -0
  4. data/Rakefile +123 -0
  5. data/bin/ruby-prof +207 -0
  6. data/examples/flat.txt +55 -0
  7. data/examples/graph.html +823 -0
  8. data/examples/graph.txt +170 -0
  9. data/ext/#ruby_prof.c# +1679 -0
  10. data/ext/Makefile +180 -0
  11. data/ext/extconf.rb +40 -0
  12. data/ext/measure_allocations.h +58 -0
  13. data/ext/measure_cpu_time.h +152 -0
  14. data/ext/measure_gc_runs.h +76 -0
  15. data/ext/measure_gc_time.h +57 -0
  16. data/ext/measure_memory.h +101 -0
  17. data/ext/measure_process_time.h +52 -0
  18. data/ext/measure_wall_time.h +53 -0
  19. data/ext/mingw/Rakefile +23 -0
  20. data/ext/mingw/build.rake +38 -0
  21. data/ext/ruby_prof.c +1707 -0
  22. data/ext/ruby_prof.e +19984 -0
  23. data/ext/ruby_prof.h +188 -0
  24. data/ext/vc/ruby_prof.sln +20 -0
  25. data/ext/vc/ruby_prof.vcproj +241 -0
  26. data/ext/version.h +4 -0
  27. data/lib/ruby-prof.rb +48 -0
  28. data/lib/ruby-prof/abstract_printer.rb +41 -0
  29. data/lib/ruby-prof/aggregate_call_info.rb +62 -0
  30. data/lib/ruby-prof/call_info.rb +47 -0
  31. data/lib/ruby-prof/call_tree_printer.rb +84 -0
  32. data/lib/ruby-prof/flat_printer.rb +79 -0
  33. data/lib/ruby-prof/graph_html_printer.rb +256 -0
  34. data/lib/ruby-prof/graph_html_printer.rb.orig +256 -0
  35. data/lib/ruby-prof/graph_html_printer.rb.rej +34 -0
  36. data/lib/ruby-prof/graph_printer.rb +164 -0
  37. data/lib/ruby-prof/graph_printer.rb.orig +164 -0
  38. data/lib/ruby-prof/method_info.rb +111 -0
  39. data/lib/ruby-prof/task.rb +146 -0
  40. data/lib/ruby-prof/test.rb +148 -0
  41. data/lib/unprof.rb +8 -0
  42. data/rails/environment/profile.rb +24 -0
  43. data/rails/example/example_test.rb +9 -0
  44. data/rails/profile_test_helper.rb +21 -0
  45. data/test/aggregate_test.rb +121 -0
  46. data/test/basic_test.rb +283 -0
  47. data/test/duplicate_names_test.rb +32 -0
  48. data/test/exceptions_test.rb +15 -0
  49. data/test/exclude_threads_test.rb +54 -0
  50. data/test/line_number_test.rb +73 -0
  51. data/test/measurement_test.rb +121 -0
  52. data/test/module_test.rb +54 -0
  53. data/test/no_method_class_test.rb +13 -0
  54. data/test/prime.rb +58 -0
  55. data/test/prime_test.rb +13 -0
  56. data/test/printers_test.rb +71 -0
  57. data/test/recursive_test.rb +254 -0
  58. data/test/singleton_test.rb +37 -0
  59. data/test/stack_test.rb +138 -0
  60. data/test/start_stop_test.rb +95 -0
  61. data/test/test_suite.rb +23 -0
  62. data/test/thread_test.rb +159 -0
  63. data/test/unique_call_path_test.rb +206 -0
  64. metadata +124 -0
@@ -0,0 +1,180 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /C/installs/ruby191p243p2/include/ruby-1.9.1
8
+ hdrdir = /C/installs/ruby191p243p2/include/ruby-1.9.1
9
+ arch_hdrdir = C:/installs/ruby191p243p2/include/ruby-1.9.1/$(arch)
10
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
11
+
12
+ DESTDIR = C:
13
+ prefix = $(DESTDIR)/installs/ruby191p243p2
14
+ exec_prefix = $(prefix)
15
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
16
+ sitehdrdir = $(rubyhdrdir)/site_ruby
17
+ rubyhdrdir = $(includedir)/$(RUBY_INSTALL_NAME)-$(ruby_version)
18
+ vendordir = $(libdir)/$(RUBY_INSTALL_NAME)/vendor_ruby
19
+ sitedir = $(libdir)/$(RUBY_INSTALL_NAME)/site_ruby
20
+ mandir = $(datarootdir)/man
21
+ localedir = $(datarootdir)/locale
22
+ libdir = $(exec_prefix)/lib
23
+ psdir = $(docdir)
24
+ pdfdir = $(docdir)
25
+ dvidir = $(docdir)
26
+ htmldir = $(docdir)
27
+ infodir = $(datarootdir)/info
28
+ docdir = $(datarootdir)/doc/$(PACKAGE)
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ includedir = $(prefix)/include
31
+ localstatedir = $(prefix)/var
32
+ sharedstatedir = $(prefix)/com
33
+ sysconfdir = $(prefix)/etc
34
+ datadir = $(datarootdir)
35
+ datarootdir = $(prefix)/share
36
+ libexecdir = $(exec_prefix)/libexec
37
+ sbindir = $(exec_prefix)/sbin
38
+ bindir = $(exec_prefix)/bin
39
+ rubylibdir = $(libdir)/$(ruby_install_name)/$(ruby_version)
40
+ archdir = $(rubylibdir)/$(arch)
41
+ sitelibdir = $(sitedir)/$(ruby_version)
42
+ sitearchdir = $(sitelibdir)/$(sitearch)
43
+ vendorlibdir = $(vendordir)/$(ruby_version)
44
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
45
+
46
+ CC = gcc
47
+ CXX = g++
48
+ LIBRUBY = lib$(RUBY_SO_NAME).dll.a
49
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
50
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
51
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
52
+ OUTFLAG = -o
53
+ COUTFLAG = -o
54
+
55
+ RUBY_EXTCONF_H =
56
+ cflags = $(optflags) $(debugflags) $(warnflags)
57
+ optflags = -O2
58
+ debugflags = -g
59
+ warnflags = -Wall -Wno-parentheses
60
+ CFLAGS = $(cflags)
61
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
62
+ DEFS =
63
+ CPPFLAGS = -DRUBY_VM $(DEFS) $(cppflags)
64
+ CXXFLAGS = $(CFLAGS) $(cxxflags)
65
+ ldflags = -L.
66
+ dldflags = -Wl,--enable-auto-image-base,--enable-auto-import
67
+ archflag =
68
+ DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
69
+ LDSHARED = gcc -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)
70
+ LDSHAREDXX = g++ -shared $(if $(filter-out -g -g0,$(debugflags)),,-s)
71
+ AR = ar
72
+ EXEEXT = .exe
73
+
74
+ RUBY_INSTALL_NAME = ruby
75
+ RUBY_SO_NAME = msvcrt-ruby191
76
+ arch = i386-mingw32
77
+ sitearch = i386-msvcrt
78
+ ruby_version = 1.9.1
79
+ ruby = C:/installs/ruby191p243p2/bin/ruby
80
+ RUBY = $(ruby)
81
+ RM = rm -f
82
+ RM_RF = $(RUBY) -run -e rm -- -rf
83
+ RMDIRS = $(RUBY) -run -e rmdir -- -p
84
+ MAKEDIRS = mkdir -p
85
+ INSTALL = /bin/install -c
86
+ INSTALL_PROG = $(INSTALL) -m 0755
87
+ INSTALL_DATA = $(INSTALL) -m 644
88
+ COPY = cp
89
+
90
+ #### End of system configuration section. ####
91
+
92
+ preload =
93
+
94
+ libpath = . $(libdir)
95
+ LIBPATH = -L. -L$(libdir)
96
+ DEFFILE =
97
+
98
+ CLEANFILES = mkmf.log
99
+ DISTCLEANFILES =
100
+ DISTCLEANDIRS =
101
+
102
+ extout =
103
+ extout_prefix =
104
+ target_prefix =
105
+ LOCAL_LIBS =
106
+ LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lws2_32
107
+ SRCS = ruby_prof.c
108
+ OBJS = ruby_prof.o
109
+ TARGET = ruby_prof
110
+ DLLIB = $(TARGET).so
111
+ EXTSTATIC =
112
+ STATIC_LIB =
113
+
114
+ BINDIR = $(bindir)
115
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
116
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
117
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
118
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
119
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
120
+
121
+ TARGET_SO = $(DLLIB)
122
+ CLEANLIBS = $(TARGET).so
123
+ CLEANOBJS = *.o *.bak
124
+
125
+ all: $(DLLIB)
126
+ static: $(STATIC_LIB)
127
+
128
+ clean-rb-default::
129
+ clean-rb::
130
+ clean-so::
131
+ clean: clean-so clean-rb-default clean-rb
132
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
133
+
134
+ distclean-rb-default::
135
+ distclean-rb::
136
+ distclean-so::
137
+ distclean: clean distclean-so distclean-rb-default distclean-rb
138
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
139
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
140
+ @-$(RMDIRS) $(DISTCLEANDIRS)
141
+
142
+ realclean: distclean
143
+ install: install-so install-rb
144
+
145
+ install-so: $(RUBYARCHDIR)
146
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
147
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
148
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
149
+ install-rb: pre-install-rb install-rb-default
150
+ install-rb-default: pre-install-rb-default
151
+ pre-install-rb: Makefile
152
+ pre-install-rb-default: Makefile
153
+ $(RUBYARCHDIR):
154
+ $(MAKEDIRS) $@
155
+
156
+ site-install: site-install-so site-install-rb
157
+ site-install-so: install-so
158
+ site-install-rb: install-rb
159
+
160
+ .SUFFIXES: .c .m .cc .cxx .cpp .o
161
+
162
+ .cc.o:
163
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
164
+
165
+ .cxx.o:
166
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
167
+
168
+ .cpp.o:
169
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $<
170
+
171
+ .c.o:
172
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $<
173
+
174
+ $(DLLIB): $(OBJS) Makefile
175
+ @-$(RM) $(@)
176
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
177
+
178
+
179
+
180
+ $(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h
@@ -0,0 +1,40 @@
1
+ require "mkmf"
2
+
3
+ if RUBY_VERSION >= "1.9"
4
+ if RUBY_RELEASE_DATE < "2005-03-17"
5
+ STDERR.print("Ruby version is too old\n")
6
+ exit(1)
7
+ end
8
+ elsif RUBY_VERSION >= "1.8"
9
+ if RUBY_RELEASE_DATE < "2005-03-22"
10
+ STDERR.print("Ruby version is too old\n")
11
+ exit(1)
12
+ end
13
+ else
14
+ STDERR.print("Ruby version is too old\n")
15
+ exit(1)
16
+ end
17
+
18
+ have_header("sys/times.h")
19
+
20
+ # Stefan Kaes / Alexander Dymo GC patch
21
+ have_func("rb_os_allocated_objects")
22
+ have_func("rb_gc_allocated_size")
23
+ have_func("rb_gc_collections")
24
+ have_func("rb_gc_time")
25
+
26
+ # Lloyd Hilaiel's heap info patch
27
+ have_func("rb_heap_total_mem")
28
+ have_func("rb_gc_heap_info")
29
+
30
+ # Ruby 1.9 unexposed methods
31
+ have_func("rb_gc_malloc_allocations")
32
+ have_func("rb_gc_malloc_allocated_size")
33
+
34
+ def add_define(name)
35
+ $defs.push("-D#{name}")
36
+ end
37
+
38
+ add_define 'RUBY_VM' if RUBY_VERSION >= '1.9'
39
+
40
+ create_makefile("ruby_prof")
@@ -0,0 +1,58 @@
1
+ /* :nodoc:
2
+ * Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
3
+ * Charlie Savage <cfis@savagexi.com>
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ * SUCH DAMAGE. */
26
+
27
+ #include <ruby.h>
28
+
29
+ #if defined(HAVE_RB_OS_ALLOCATED_OBJECTS)
30
+ #define MEASURE_ALLOCATIONS 3
31
+
32
+ static prof_measure_t
33
+ measure_allocations()
34
+ {
35
+ return rb_os_allocated_objects();
36
+ }
37
+
38
+ static double
39
+ convert_allocations(prof_measure_t c)
40
+ {
41
+ return c;
42
+ }
43
+
44
+ /* Document-method: prof_measure_allocations
45
+ call-seq:
46
+ measure_allocations -> int
47
+
48
+ Returns the total number of object allocations since Ruby started.*/
49
+ static VALUE
50
+ prof_measure_allocations(VALUE self)
51
+ {
52
+ #if defined(HAVE_LONG_LONG)
53
+ return ULL2NUM(rb_os_allocated_objects());
54
+ #else
55
+ return ULONG2NUM(rb_os_allocated_objects());
56
+ #endif
57
+ }
58
+ #endif
@@ -0,0 +1,152 @@
1
+ /* :nodoc:
2
+ * Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
3
+ * Charlie Savage <cfis@savagexi.com>
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ * SUCH DAMAGE. */
26
+
27
+ #include <ruby.h>
28
+
29
+ #if defined(_WIN32) || (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__ppc__)))
30
+ #define MEASURE_CPU_TIME 2
31
+
32
+ static unsigned long long cpu_frequency;
33
+
34
+ #if defined(__GNUC__)
35
+
36
+ #include <stdint.h>
37
+
38
+ static prof_measure_t
39
+ measure_cpu_time()
40
+ {
41
+ #if defined(__i386__) || defined(__x86_64__)
42
+ uint32_t a, d;
43
+ __asm__ volatile("rdtsc" : "=a" (a), "=d" (d));
44
+ return ((uint64_t)d << 32) + a;
45
+ #elif defined(__powerpc__) || defined(__ppc__)
46
+ unsigned long long x, y;
47
+
48
+ __asm__ __volatile__ ("\n\
49
+ 1: mftbu %1\n\
50
+ mftb %L0\n\
51
+ mftbu %0\n\
52
+ cmpw %0,%1\n\
53
+ bne- 1b"
54
+ : "=r" (x), "=r" (y));
55
+ return x;
56
+ #endif
57
+ }
58
+
59
+ #elif defined(_WIN32)
60
+
61
+ static prof_measure_t
62
+ measure_cpu_time()
63
+ {
64
+ prof_measure_t cycles = 0;
65
+
66
+ __asm
67
+ {
68
+ rdtsc
69
+ mov DWORD PTR cycles, eax
70
+ mov DWORD PTR [cycles + 4], edx
71
+ }
72
+ return cycles;
73
+ }
74
+
75
+ #endif
76
+
77
+
78
+ /* The _WIN32 check is needed for msys (and maybe cygwin?) */
79
+ #if defined(__GNUC__) && !defined(_WIN32)
80
+
81
+ unsigned long long get_cpu_frequency()
82
+ {
83
+ unsigned long long x, y;
84
+
85
+ struct timespec ts;
86
+ ts.tv_sec = 0;
87
+ ts.tv_nsec = 500000000;
88
+ x = measure_cpu_time();
89
+ nanosleep(&ts, NULL);
90
+ y = measure_cpu_time();
91
+ return (y - x) * 2;
92
+ }
93
+
94
+ #elif defined(_WIN32)
95
+
96
+ unsigned long long get_cpu_frequency()
97
+ {
98
+ unsigned long long x, y;
99
+ unsigned long long frequency;
100
+ x = measure_cpu_time();
101
+
102
+ /* Use the windows sleep function, not Ruby's */
103
+ Sleep(500);
104
+ y = measure_cpu_time();
105
+ frequency = 2*(y-x);
106
+ return frequency;
107
+ }
108
+ #endif
109
+
110
+ static double
111
+ convert_cpu_time(prof_measure_t c)
112
+ {
113
+ return (double) c / cpu_frequency;
114
+ }
115
+
116
+ /* Document-method: prof_measure_cpu_time
117
+ call-seq:
118
+ measure_cpu_time -> float
119
+
120
+ Returns the cpu time.*/
121
+ static VALUE
122
+ prof_measure_cpu_time(VALUE self)
123
+ {
124
+ return rb_float_new(convert_cpu_time(measure_cpu_time()));
125
+ }
126
+
127
+ /* Document-method: prof_get_cpu_frequency
128
+ call-seq:
129
+ cpu_frequency -> int
130
+
131
+ Returns the cpu's frequency. This value is needed when
132
+ RubyProf::measure_mode is set to CPU_TIME. */
133
+ static VALUE
134
+ prof_get_cpu_frequency(VALUE self)
135
+ {
136
+ return ULL2NUM(cpu_frequency);
137
+ }
138
+
139
+ /* Document-method: prof_set_cpu_frequency
140
+ call-seq:
141
+ cpu_frequency=value -> void
142
+
143
+ Sets the cpu's frequency. This value is needed when
144
+ RubyProf::measure_mode is set to CPU_TIME. */
145
+ static VALUE
146
+ prof_set_cpu_frequency(VALUE self, VALUE val)
147
+ {
148
+ cpu_frequency = NUM2LL(val);
149
+ return val;
150
+ }
151
+
152
+ #endif
@@ -0,0 +1,76 @@
1
+ /* :nodoc:
2
+ * Copyright (C) 2008 Shugo Maeda <shugo@ruby-lang.org>
3
+ * Charlie Savage <cfis@savagexi.com>
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
+ * SUCH DAMAGE. */
26
+
27
+ #if defined(HAVE_RB_GC_COLLECTIONS)
28
+ #define MEASURE_GC_RUNS 5
29
+
30
+ static prof_measure_t
31
+ measure_gc_runs()
32
+ {
33
+ return NUM2INT(rb_gc_collections());
34
+ }
35
+
36
+ static double
37
+ convert_gc_runs(prof_measure_t c)
38
+ {
39
+ return c;
40
+ }
41
+
42
+ /* Document-method: prof_measure_gc_runs
43
+ call-seq:
44
+ gc_runs -> Integer
45
+
46
+ Returns the total number of garbage collections.*/
47
+ static VALUE
48
+ prof_measure_gc_runs(VALUE self)
49
+ {
50
+ return rb_gc_collections();
51
+ }
52
+
53
+ #elif defined(HAVE_RB_GC_HEAP_INFO)
54
+ #define MEASURE_GC_RUNS 5
55
+
56
+ static prof_measure_t
57
+ measure_gc_runs()
58
+ {
59
+ VALUE h = rb_gc_heap_info();
60
+ return NUM2UINT(rb_hash_aref(h, rb_str_new2("num_gc_passes")));
61
+ }
62
+
63
+ static double
64
+ convert_gc_runs(prof_measure_t c)
65
+ {
66
+ return c;
67
+ }
68
+
69
+ static VALUE
70
+ prof_measure_gc_runs(VALUE self)
71
+ {
72
+ VALUE h = rb_gc_heap_info();
73
+ return rb_hash_aref(h, rb_str_new2("num_gc_passes"));
74
+ }
75
+
76
+ #endif