active-profiling 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -2
- data/lib/active-profiling.rb +3 -2
- data/lib/active-profiling/action_controller.rb +3 -0
- data/lib/active-profiling/{log_subscriber.rb → action_controller/log_subscriber.rb} +2 -2
- data/lib/active-profiling/active_record.rb +3 -0
- data/lib/active-profiling/active_record/backtrace_log_subscriber.rb +41 -0
- data/lib/active-profiling/railtie.rb +25 -0
- data/lib/active-profiling/ruby_profiler.rb +11 -2
- data/lib/active-profiling/version.rb +1 -1
- metadata +15 -9
data/README.rdoc
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
= ActiveProfiling
|
3
3
|
|
4
4
|
ActiveProfiling is a gem I've slapped together over the years to help with
|
5
|
-
profiling Rails applications.
|
6
|
-
can also be used to profile generic blocks of code.
|
5
|
+
profiling Rails applications.
|
7
6
|
|
8
7
|
== Profiler ActionController Filters
|
9
8
|
|
@@ -25,6 +24,9 @@ To enable this filter, add the following to your application configuration:
|
|
25
24
|
|
26
25
|
config.active_profiling.profiler.enabled = true
|
27
26
|
|
27
|
+
Additional configuration options can be found in the documentation for
|
28
|
+
ActiveProfiling::Railtie.
|
29
|
+
|
28
30
|
=== +action_gc_statistics+
|
29
31
|
|
30
32
|
This filter wraps up the functionality of either GC::Profiler in Ruby 1.9+ or
|
@@ -45,6 +47,9 @@ To enable this filter, add the following to your application configuration:
|
|
45
47
|
|
46
48
|
config.active_profiling.gc_statistics.enabled = true
|
47
49
|
|
50
|
+
Additional configuration options can be found in the documentation for
|
51
|
+
ActiveProfiling::Railtie.
|
52
|
+
|
48
53
|
== Profiling Blocks
|
49
54
|
|
50
55
|
You can also profile individual blocks of code by using the
|
@@ -65,6 +70,23 @@ minus the +:enabled+ option.
|
|
65
70
|
# ...
|
66
71
|
end
|
67
72
|
|
73
|
+
|
74
|
+
== Extended ActiveRecord Logging
|
75
|
+
|
76
|
+
The database can often be a performance hotspot, and tracking down where and
|
77
|
+
why some queries are occuring in your application can be a pain.
|
78
|
+
ActiveProfiling includes an extended query logger that can be configured
|
79
|
+
to log backtraces for SQL queries that can help you track down where
|
80
|
+
unexpected queries are occuring in your code.
|
81
|
+
|
82
|
+
To enable extended logging, add the following to your application
|
83
|
+
configuration:
|
84
|
+
|
85
|
+
config.active_profiling.active_record.backtrace_logger.enabled = true
|
86
|
+
|
87
|
+
Additional configuration options can be found in the documentation for
|
88
|
+
ActiveProfiling::Railtie.
|
89
|
+
|
68
90
|
== Using In A Rails Project
|
69
91
|
|
70
92
|
Profiling should be performed in a production environment, as profiling in
|
@@ -107,6 +129,8 @@ like so:
|
|
107
129
|
:print_file => true
|
108
130
|
}
|
109
131
|
config.active_profiling.gc_statistics.enabled = true
|
132
|
+
|
133
|
+
config.active_profiling.active_record.backtrace_logger.enabled = true
|
110
134
|
end
|
111
135
|
|
112
136
|
# etc...
|
data/lib/active-profiling.rb
CHANGED
@@ -20,7 +20,8 @@ module ActiveProfiling
|
|
20
20
|
end
|
21
21
|
|
22
22
|
require 'active-profiling/railtie'
|
23
|
-
require 'active-profiling/log_subscriber'
|
24
23
|
require 'active-profiling/gc_statistics'
|
25
24
|
require 'active-profiling/ruby_profiler'
|
26
|
-
require 'active-profiling/action_controller
|
25
|
+
require 'active-profiling/action_controller'
|
26
|
+
require 'active-profiling/active_record'
|
27
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
module ActiveProfiling
|
2
|
+
module ActiveProfiling::ActionController
|
3
3
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
4
4
|
def profiler_output(event)
|
5
5
|
return unless logger &&
|
@@ -56,4 +56,4 @@ module ActiveProfiling
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
ActiveProfiling::LogSubscriber.attach_to :active_profiling
|
59
|
+
ActiveProfiling::ActionController::LogSubscriber.attach_to :active_profiling
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
module ActiveProfiling::ActiveRecord
|
3
|
+
class BacktraceLogSubscriber < ::ActiveSupport::LogSubscriber
|
4
|
+
def sql(event)
|
5
|
+
return unless config.log_level &&
|
6
|
+
logger &&
|
7
|
+
logger.send("#{config.log_level}?")
|
8
|
+
|
9
|
+
payload = event.payload
|
10
|
+
|
11
|
+
return if 'SCHEMA' == payload[:name]
|
12
|
+
|
13
|
+
backtrace = event.send(:caller).collect { |line|
|
14
|
+
if line_match(line)
|
15
|
+
" #{line}"
|
16
|
+
end
|
17
|
+
}.compact
|
18
|
+
|
19
|
+
unless backtrace.empty?
|
20
|
+
name = color(payload[:name], YELLOW, true)
|
21
|
+
logger.send(config.log_level, " #{name}\n#{backtrace.join("\n")}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def logger
|
26
|
+
::ActiveRecord::Base.logger
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def config
|
31
|
+
Rails.application.config.active_profiling.active_record.backtrace_logger
|
32
|
+
end
|
33
|
+
|
34
|
+
def line_match(line)
|
35
|
+
config.enabled && (config.verbose || !!(line =~ config.matcher))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ActiveProfiling::ActiveRecord::BacktraceLogSubscriber.attach_to :active_record
|
41
|
+
|
@@ -84,15 +84,40 @@ module ActiveProfiling
|
|
84
84
|
:log_level => :info
|
85
85
|
}.freeze
|
86
86
|
|
87
|
+
# These settings are the default values used for the ActiveRecord
|
88
|
+
# backtrace logger.
|
89
|
+
#
|
90
|
+
# * +:enabled+ - Enables backtrace logging of SQL queries so you can see
|
91
|
+
# where your queries originate.
|
92
|
+
# * +:verbose+ - Logs all backtrace lines. Normally we have a +:matcher+
|
93
|
+
# option that you can use to filter out lines you want to log, but this
|
94
|
+
# is a quick method to bypass that matching completely.
|
95
|
+
# * +:log_level+ - The log level to use when logging SQL backtraces.
|
96
|
+
# * +:matcher+ - A Regexp that is used to match caller lines in the
|
97
|
+
# backtraces being logged. By default, this is set to
|
98
|
+
# /^#{Rails.root}(?!(\/vendor\/rails|\/\.bundle))/ so that only lines
|
99
|
+
# in your application code are logged.
|
100
|
+
DEFAULT_AR_BACKTRACE_LOGGER_OPTIONS = {
|
101
|
+
:enabled => false,
|
102
|
+
|
103
|
+
:verbose => false,
|
104
|
+
|
105
|
+
:log_level => :debug
|
106
|
+
}.freeze
|
107
|
+
|
87
108
|
config.active_profiling = ActiveSupport::OrderedOptions.new
|
88
109
|
config.active_profiling.profiler = ActiveSupport::OrderedOptions.new
|
89
110
|
config.active_profiling.gc_statistics = ActiveSupport::OrderedOptions.new
|
111
|
+
config.active_profiling.active_record = ActiveSupport::OrderedOptions.new
|
112
|
+
config.active_profiling.active_record.backtrace_logger = ActiveSupport::OrderedOptions.new
|
90
113
|
|
91
114
|
initializer "active_profiling.set_profiling_config" do |app|
|
92
115
|
options = app.config.active_profiling
|
93
116
|
|
94
117
|
options.profiler.reverse_merge!(DEFAULT_PROFILER_OPTIONS)
|
95
118
|
options.gc_statistics.reverse_merge!(DEFAULT_GC_STATISTICS_OPTIONS)
|
119
|
+
options.active_record.backtrace_logger.reverse_merge!(DEFAULT_AR_BACKTRACE_LOGGER_OPTIONS)
|
120
|
+
options.active_record.backtrace_logger[:matcher] ||= /^#{Rails.root}(?!(\/vendor\/rails|\/\.bundle))/
|
96
121
|
end
|
97
122
|
end
|
98
123
|
end
|
@@ -36,8 +36,13 @@ module ActiveProfiling
|
|
36
36
|
GC.disable if options[:disable_gc]
|
37
37
|
|
38
38
|
result = nil
|
39
|
+
exception = nil
|
39
40
|
profiler_result = RubyProf.profile do
|
40
|
-
|
41
|
+
begin
|
42
|
+
result = yield
|
43
|
+
rescue
|
44
|
+
exception = $!
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
case output
|
@@ -94,7 +99,11 @@ module ActiveProfiling
|
|
94
99
|
printer_class.new(profiler_result).print(File.open(file_name, 'w'), options[:printer_options])
|
95
100
|
end
|
96
101
|
|
97
|
-
|
102
|
+
if exception
|
103
|
+
raise exception
|
104
|
+
else
|
105
|
+
result
|
106
|
+
end
|
98
107
|
ensure
|
99
108
|
GC.enable if options[:disable_gc]
|
100
109
|
end
|
metadata
CHANGED
@@ -2,31 +2,31 @@
|
|
2
2
|
name: active-profiling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- J Smith
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
15
|
+
name: rails
|
16
|
+
type: :runtime
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '3.0'
|
20
22
|
none: false
|
21
|
-
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
requirement: !ruby/object:Gem::Requirement
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
24
|
requirements:
|
26
25
|
- - ! '>='
|
27
26
|
- !ruby/object:Gem::Version
|
28
27
|
version: '3.0'
|
29
28
|
none: false
|
29
|
+
prerelease: false
|
30
30
|
description: A Rails profiling suite.
|
31
31
|
email: dark.panda@gmail.com
|
32
32
|
executables: []
|
@@ -41,9 +41,12 @@ files:
|
|
41
41
|
- Rakefile
|
42
42
|
- active-profiling.gemspec
|
43
43
|
- lib/active-profiling.rb
|
44
|
+
- lib/active-profiling/action_controller.rb
|
44
45
|
- lib/active-profiling/action_controller/action_profiling.rb
|
46
|
+
- lib/active-profiling/action_controller/log_subscriber.rb
|
47
|
+
- lib/active-profiling/active_record.rb
|
48
|
+
- lib/active-profiling/active_record/backtrace_log_subscriber.rb
|
45
49
|
- lib/active-profiling/gc_statistics.rb
|
46
|
-
- lib/active-profiling/log_subscriber.rb
|
47
50
|
- lib/active-profiling/railtie.rb
|
48
51
|
- lib/active-profiling/ruby_profiler.rb
|
49
52
|
- lib/active-profiling/version.rb
|
@@ -57,6 +60,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
60
|
requirements:
|
58
61
|
- - ! '>='
|
59
62
|
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: 1112450418277949513
|
60
66
|
version: '0'
|
61
67
|
none: false
|
62
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -67,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
73
|
none: false
|
68
74
|
requirements: []
|
69
75
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.24
|
71
77
|
signing_key:
|
72
78
|
specification_version: 3
|
73
79
|
summary: A Rails profiling suite.
|