ruby-prof 0.10.8 → 0.11.0.rc1
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 +38 -18
- data/LICENSE +4 -3
- data/README.rdoc +30 -66
- data/Rakefile +47 -54
- data/bin/ruby-prof +24 -4
- data/ext/ruby_prof/extconf.rb +9 -16
- 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 +259 -1398
- data/ext/ruby_prof/ruby_prof.h +54 -190
- 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 +14 -11
- data/lib/ruby-prof/abstract_printer.rb +10 -0
- data/lib/ruby-prof/aggregate_call_info.rb +2 -0
- data/lib/ruby-prof/call_info.rb +2 -0
- data/lib/ruby-prof/call_stack_printer.rb +2 -4
- data/lib/ruby-prof/call_tree_printer.rb +1 -0
- data/lib/ruby-prof/compatibility.rb +134 -0
- data/lib/ruby-prof/dot_printer.rb +7 -7
- data/lib/ruby-prof/flat_printer.rb +7 -7
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +2 -5
- data/lib/ruby-prof/graph_html_printer.rb +4 -2
- data/lib/ruby-prof/graph_printer.rb +4 -3
- data/lib/ruby-prof/method_info.rb +2 -0
- data/lib/ruby-prof/multi_printer.rb +2 -0
- data/lib/ruby-prof/{result.rb → profile.rb} +3 -1
- data/lib/ruby-prof/rack.rb +1 -0
- data/lib/ruby-prof/symbol_to_proc.rb +2 -0
- data/lib/ruby-prof/task.rb +1 -0
- data/lib/ruby-prof/test.rb +2 -0
- 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 +8 -8
- data/test/basic_test.rb +3 -251
- data/test/bug_test.rb +6 -0
- data/test/duplicate_names_test.rb +2 -2
- data/test/dynamic_method_test.rb +61 -0
- data/test/enumerable_test.rb +2 -2
- data/test/exceptions_test.rb +4 -3
- data/test/exclude_threads_test.rb +2 -2
- data/test/exec_test.rb +3 -3
- data/test/line_number_test.rb +5 -5
- 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 +2 -2
- data/test/module_test.rb +3 -2
- data/test/multi_printer_test.rb +2 -2
- data/test/no_method_class_test.rb +3 -1
- data/test/prime_test.rb +3 -3
- data/test/printers_test.rb +106 -8
- data/test/recursive_test.rb +7 -6
- data/test/singleton_test.rb +2 -2
- data/test/stack_printer_test.rb +2 -3
- data/test/stack_test.rb +2 -2
- data/test/start_stop_test.rb +2 -2
- data/test/test_helper.rb +81 -0
- data/test/test_suite.rb +34 -29
- data/test/thread_test.rb +24 -23
- data/test/unique_call_path_test.rb +2 -2
- metadata +101 -69
- data/ext/ruby_prof/measure_allocations.h +0 -83
- 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 -63
- 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 -132
- data/test/ruby-prof-bin +0 -20
data/ext/ruby_prof/ruby_prof.h
CHANGED
|
@@ -1,190 +1,54 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#include <ruby.h>
|
|
56
|
-
|
|
57
|
-
#ifndef RUBY_VM
|
|
58
|
-
#include <node.h>
|
|
59
|
-
#include <st.h>
|
|
60
|
-
typedef rb_event_t rb_event_flag_t;
|
|
61
|
-
#define rb_sourcefile() (node ? node->nd_file : 0)
|
|
62
|
-
#define rb_sourceline() (node ? nd_line(node) : 0)
|
|
63
|
-
#endif
|
|
64
|
-
|
|
65
|
-
#include "version.h"
|
|
66
|
-
|
|
67
|
-
/* ================ Constants =================*/
|
|
68
|
-
#define INITIAL_STACK_SIZE 8
|
|
69
|
-
#define INITIAL_CALL_INFOS_SIZE 2
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/* ================ Measurement =================*/
|
|
73
|
-
#ifdef HAVE_LONG_LONG
|
|
74
|
-
typedef unsigned LONG_LONG prof_measure_t; // long long is 8 bytes on 32-bit
|
|
75
|
-
#else
|
|
76
|
-
typedef unsigned long prof_measure_t;
|
|
77
|
-
#endif
|
|
78
|
-
|
|
79
|
-
#include "measure_process_time.h"
|
|
80
|
-
#include "measure_wall_time.h"
|
|
81
|
-
#include "measure_cpu_time.h"
|
|
82
|
-
#include "measure_allocations.h"
|
|
83
|
-
#include "measure_memory.h"
|
|
84
|
-
#include "measure_gc_runs.h"
|
|
85
|
-
#include "measure_gc_time.h"
|
|
86
|
-
|
|
87
|
-
static prof_measure_t (*get_measurement)() = measure_process_time;
|
|
88
|
-
static double (*convert_measurement)(prof_measure_t) = convert_process_time;
|
|
89
|
-
|
|
90
|
-
/* ================ DataTypes =================*/
|
|
91
|
-
static VALUE mProf;
|
|
92
|
-
static VALUE cResult;
|
|
93
|
-
static VALUE cMethodInfo;
|
|
94
|
-
static VALUE cCallInfo;
|
|
95
|
-
|
|
96
|
-
/* nasty hack to avoid compilation warnings related to 64/32 bit conversions */
|
|
97
|
-
#ifndef SIZEOF_ST_INDEX_T
|
|
98
|
-
#define st_index_t int
|
|
99
|
-
#endif
|
|
100
|
-
|
|
101
|
-
/* Profiling information for each method. */
|
|
102
|
-
typedef struct {
|
|
103
|
-
VALUE klass; /* The method's class. */
|
|
104
|
-
ID mid; /* The method id. */
|
|
105
|
-
int depth; /* The recursion depth. */
|
|
106
|
-
st_index_t key; /* Cache calculated key */
|
|
107
|
-
} prof_method_key_t;
|
|
108
|
-
|
|
109
|
-
struct prof_call_infos_t;
|
|
110
|
-
|
|
111
|
-
/* Profiling information for each method. */
|
|
112
|
-
typedef struct {
|
|
113
|
-
prof_method_key_t *key; /* Method key */
|
|
114
|
-
const char *source_file; /* The method's source file */
|
|
115
|
-
int line; /* The method's line number. */
|
|
116
|
-
struct prof_call_infos_t *call_infos; /* Call info objects for this method */
|
|
117
|
-
VALUE object; /* Cahced ruby object */
|
|
118
|
-
} prof_method_t;
|
|
119
|
-
|
|
120
|
-
/* Callers and callee information for a method. */
|
|
121
|
-
typedef struct prof_call_info_t {
|
|
122
|
-
prof_method_t *target; /* Use target instead of method to avoid conflict with Ruby method */
|
|
123
|
-
struct prof_call_info_t *parent;
|
|
124
|
-
st_table *call_infos;
|
|
125
|
-
int called;
|
|
126
|
-
prof_measure_t total_time;
|
|
127
|
-
prof_measure_t self_time;
|
|
128
|
-
prof_measure_t wait_time;
|
|
129
|
-
int line;
|
|
130
|
-
VALUE object;
|
|
131
|
-
VALUE children;
|
|
132
|
-
} prof_call_info_t;
|
|
133
|
-
|
|
134
|
-
/* Array of call_info objects */
|
|
135
|
-
typedef struct prof_call_infos_t {
|
|
136
|
-
prof_call_info_t **start;
|
|
137
|
-
prof_call_info_t **end;
|
|
138
|
-
prof_call_info_t **ptr;
|
|
139
|
-
VALUE object;
|
|
140
|
-
} prof_call_infos_t;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/* Temporary object that maintains profiling information
|
|
144
|
-
for active methods - there is one per method.*/
|
|
145
|
-
typedef struct {
|
|
146
|
-
/* Caching prof_method_t values significantly
|
|
147
|
-
increases performance. */
|
|
148
|
-
prof_call_info_t *call_info;
|
|
149
|
-
prof_measure_t start_time;
|
|
150
|
-
prof_measure_t wait_time;
|
|
151
|
-
prof_measure_t child_time;
|
|
152
|
-
unsigned int line;
|
|
153
|
-
} prof_frame_t;
|
|
154
|
-
|
|
155
|
-
/* Current stack of active methods.*/
|
|
156
|
-
typedef struct {
|
|
157
|
-
prof_frame_t *start;
|
|
158
|
-
prof_frame_t *end;
|
|
159
|
-
prof_frame_t *ptr;
|
|
160
|
-
} prof_stack_t;
|
|
161
|
-
|
|
162
|
-
/* Profiling information for a thread. */
|
|
163
|
-
typedef struct {
|
|
164
|
-
VALUE thread_id; /* Thread id */
|
|
165
|
-
st_table* method_table; /* Methods called in the thread */
|
|
166
|
-
prof_stack_t* stack; /* Active methods */
|
|
167
|
-
prof_measure_t last_switch; /* Point of last context switch */
|
|
168
|
-
} thread_data_t;
|
|
169
|
-
|
|
170
|
-
typedef struct {
|
|
171
|
-
VALUE threads;
|
|
172
|
-
} prof_result_t;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
/* ================ Variables =================*/
|
|
176
|
-
static int measure_mode;
|
|
177
|
-
static st_table *threads_tbl = NULL;
|
|
178
|
-
static st_table *exclude_threads_tbl = NULL;
|
|
179
|
-
|
|
180
|
-
/* TODO - If Ruby become multi-threaded this has to turn into
|
|
181
|
-
a separate stack since this isn't thread safe! */
|
|
182
|
-
static thread_data_t* last_thread_data = NULL;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
/* Forward declarations */
|
|
186
|
-
static VALUE prof_call_infos_wrap(prof_call_infos_t *call_infos);
|
|
187
|
-
static VALUE prof_call_info_wrap(prof_call_info_t *call_info);
|
|
188
|
-
static VALUE prof_method_wrap(prof_method_t *result);
|
|
189
|
-
|
|
190
|
-
#endif
|
|
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 __RUBY_PROF_H__
|
|
5
|
+
#define __RUBY_PROF_H__
|
|
6
|
+
|
|
7
|
+
#include <stdio.h>
|
|
8
|
+
#include <ruby.h>
|
|
9
|
+
|
|
10
|
+
#if RUBY_VERSION == 186
|
|
11
|
+
# error 1.8.6 is not supported. Please upgrade to 1.8.7 or 1.9.2 or higher.
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#if RUBY_VERSION == 190
|
|
15
|
+
# error 1.9.0 is not supported. Please upgrade to 1.9.2 or higher.
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
#if RUBY_VERSION == 191
|
|
19
|
+
# error 1.9.1 is not supported. Please upgrade to 1.9.2 or higher.
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
#ifndef RUBY_VM
|
|
23
|
+
#include <node.h>
|
|
24
|
+
typedef rb_event_t rb_event_flag_t;
|
|
25
|
+
#define rb_sourcefile() (node ? node->nd_file : 0)
|
|
26
|
+
#define rb_sourceline() (node ? nd_line(node) : 0)
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#include "version.h"
|
|
30
|
+
|
|
31
|
+
#include "rp_measure.h"
|
|
32
|
+
#include "rp_method.h"
|
|
33
|
+
#include "rp_call_info.h"
|
|
34
|
+
#include "rp_stack.h"
|
|
35
|
+
#include "rp_thread.h"
|
|
36
|
+
|
|
37
|
+
extern VALUE mProf;
|
|
38
|
+
extern VALUE cProfile;
|
|
39
|
+
|
|
40
|
+
void method_key(prof_method_key_t* key, VALUE klass, ID mid);
|
|
41
|
+
|
|
42
|
+
typedef struct
|
|
43
|
+
{
|
|
44
|
+
VALUE running;
|
|
45
|
+
prof_measurer_t* measurer;
|
|
46
|
+
double measurement;
|
|
47
|
+
VALUE threads;
|
|
48
|
+
st_table* threads_tbl;
|
|
49
|
+
st_table* exclude_threads_tbl;
|
|
50
|
+
thread_data_t* last_thread_data;
|
|
51
|
+
} prof_profile_t;
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
#endif //__RUBY_PROF_H__
|
data/ext/ruby_prof/version.h
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
+
#define RUBY_PROF_VERSION "0.11.0" // for easy parsing from rake files
|
|
2
5
|
#define RUBY_PROF_VERSION_MAJ 0
|
|
3
|
-
#define RUBY_PROF_VERSION_MIN
|
|
4
|
-
#define RUBY_PROF_VERSION_MIC
|
|
6
|
+
#define RUBY_PROF_VERSION_MIN 11
|
|
7
|
+
#define RUBY_PROF_VERSION_MIC 0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/ruby-prof.rb
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
# Load the C-based binding.
|
|
4
|
+
begin
|
|
5
|
+
RUBY_VERSION =~ /(\d+.\d+)/
|
|
6
|
+
require "#{$1}/ruby_prof"
|
|
7
|
+
rescue LoadError
|
|
8
|
+
require "ruby_prof"
|
|
9
|
+
end
|
|
10
|
+
|
|
3
11
|
|
|
4
12
|
module RubyProf
|
|
5
|
-
|
|
6
|
-
if RUBY_VERSION < '1.8.7'
|
|
7
|
-
require File.dirname(__FILE__) + '/ruby-prof/symbol_to_proc'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
13
|
def self.camelcase(phrase)
|
|
11
14
|
('_' + phrase).gsub(/_([a-z])/){|b| b[1..1].upcase}
|
|
12
15
|
end
|
|
@@ -20,15 +23,15 @@ module RubyProf
|
|
|
20
23
|
|
|
21
24
|
# A few need to be loaded manually their classes were already defined by the .so file so autoload won't work for them.
|
|
22
25
|
# plus we need them anyway
|
|
23
|
-
for name in ['
|
|
26
|
+
for name in ['profile', 'method_info', 'call_info']
|
|
24
27
|
require lib_dir + name
|
|
25
28
|
end
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
# Compatability layer for suporting old api
|
|
31
|
+
require lib_dir + 'compatibility'
|
|
28
32
|
|
|
29
33
|
# we don't require unprof.rb, as well, purposefully
|
|
30
34
|
|
|
31
|
-
|
|
32
35
|
# Checks if the user specified the clock mode via
|
|
33
36
|
# the RUBY_PROF_MEASURE_MODE environment variable
|
|
34
37
|
def self.figure_measure_mode
|
|
@@ -64,4 +67,4 @@ module RubyProf
|
|
|
64
67
|
end
|
|
65
68
|
end
|
|
66
69
|
|
|
67
|
-
RubyProf::figure_measure_mode
|
|
70
|
+
RubyProf::figure_measure_mode
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
module RubyProf
|
|
2
4
|
class AbstractPrinter
|
|
3
5
|
def initialize(result)
|
|
@@ -18,6 +20,10 @@ module RubyProf
|
|
|
18
20
|
# :print_file - True or false. Specifies if a method's source
|
|
19
21
|
# file should be printed. Default value if false.
|
|
20
22
|
#
|
|
23
|
+
# :sort_method - Specifies method used for sorting method infos.
|
|
24
|
+
# Available values are :total_time, :self_time,
|
|
25
|
+
# :wait_time, :children_time
|
|
26
|
+
# Default value is :total_time
|
|
21
27
|
def setup_options(options = {})
|
|
22
28
|
@options = options
|
|
23
29
|
end
|
|
@@ -30,6 +36,10 @@ module RubyProf
|
|
|
30
36
|
@options[:print_file] || false
|
|
31
37
|
end
|
|
32
38
|
|
|
39
|
+
def sort_method
|
|
40
|
+
@options[:sort_method] || :total_time
|
|
41
|
+
end
|
|
42
|
+
|
|
33
43
|
def method_name(method)
|
|
34
44
|
name = method.full_name
|
|
35
45
|
if print_file
|
data/lib/ruby-prof/call_info.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
require 'erb'
|
|
2
4
|
require 'fileutils'
|
|
3
5
|
|
|
@@ -6,10 +8,6 @@ module RubyProf
|
|
|
6
8
|
class CallStackPrinter < AbstractPrinter
|
|
7
9
|
include ERB::Util
|
|
8
10
|
|
|
9
|
-
def initialize(result)
|
|
10
|
-
super(result)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
11
|
# Specify print options.
|
|
14
12
|
#
|
|
15
13
|
# options - Hash table
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
# These methods are here for backwards compatability with previous RubyProf releases
|
|
4
|
+
module RubyProf
|
|
5
|
+
# Measurements
|
|
6
|
+
def self.cpu_frequency
|
|
7
|
+
Measure::CpuTime.frequency
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.cpu_frequency=(value)
|
|
11
|
+
Measure::CpuTime.frequency = value
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.measure_allocations
|
|
15
|
+
Measure::Allocations.measure
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.measure_cpu_time
|
|
19
|
+
Measure::CpuTime.measure
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.measure_gc_runs
|
|
23
|
+
Measure::GcRuns.measure
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.measure_gc_time
|
|
27
|
+
Measure::GcTime.measure
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.measure_memory
|
|
31
|
+
Measure::Memory.measure
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.measure_process_time
|
|
35
|
+
Measure::ProcessTime.measure
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.measure_wall_time
|
|
39
|
+
Measure::WallTime.measure
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# call-seq:
|
|
43
|
+
# measure_mode -> measure_mode
|
|
44
|
+
#
|
|
45
|
+
# Returns what ruby-prof is measuring. Valid values include:
|
|
46
|
+
#
|
|
47
|
+
# *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library.
|
|
48
|
+
# *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
|
|
49
|
+
# *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
|
|
50
|
+
# *RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter.
|
|
51
|
+
# *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter.
|
|
52
|
+
# *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter.
|
|
53
|
+
# *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/
|
|
54
|
+
|
|
55
|
+
def self.measure_mode
|
|
56
|
+
@measure_mode ||= RubyProf::WALL_TIME
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# call-seq:
|
|
60
|
+
# measure_mode=value -> void
|
|
61
|
+
#
|
|
62
|
+
# Specifies what ruby-prof should measure. Valid values include:
|
|
63
|
+
#
|
|
64
|
+
# *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library.
|
|
65
|
+
# *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
|
|
66
|
+
# *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
|
|
67
|
+
# *RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter.
|
|
68
|
+
# *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter.
|
|
69
|
+
# *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter.
|
|
70
|
+
# *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/
|
|
71
|
+
def self.measure_mode=(value)
|
|
72
|
+
@measure_mode = value
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# call-seq:
|
|
76
|
+
# exclude_threads= -> void
|
|
77
|
+
#
|
|
78
|
+
# Specifies what threads ruby-prof should exclude from profiling
|
|
79
|
+
|
|
80
|
+
def self.exclude_threads
|
|
81
|
+
@exclude_threads ||= Array.new
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.exclude_threads=(value)
|
|
85
|
+
@exclude_threads = value
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Profiling
|
|
89
|
+
def self.start
|
|
90
|
+
if running?
|
|
91
|
+
raise(RuntimeError, "RubyProf is already running");
|
|
92
|
+
end
|
|
93
|
+
@profile = Profile.new(self.measure_mode, self.exclude_threads)
|
|
94
|
+
@profile.start
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def self.pause
|
|
98
|
+
unless running?
|
|
99
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
|
100
|
+
end
|
|
101
|
+
@profile.pause
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def self.running?
|
|
105
|
+
if defined?(@profile) and @profile
|
|
106
|
+
@profile.running?
|
|
107
|
+
else
|
|
108
|
+
false
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def self.resume
|
|
113
|
+
unless running?
|
|
114
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
|
115
|
+
end
|
|
116
|
+
@profile.resume
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def self.stop
|
|
120
|
+
unless running?
|
|
121
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
|
122
|
+
end
|
|
123
|
+
result = @profile.stop
|
|
124
|
+
@profile = nil
|
|
125
|
+
result
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def self.profile(&block)
|
|
129
|
+
if running?
|
|
130
|
+
raise(RuntimeError, "RubyProf is already running");
|
|
131
|
+
end
|
|
132
|
+
Profile.profile(self.measure_mode, self.exclude_threads, &block)
|
|
133
|
+
end
|
|
134
|
+
end
|