rails_log_profiling 0.1.0.beta1 → 0.1.0.beta2
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/README.md +18 -11
- data/lib/rails/log/profiling/action_controller.rb +8 -10
- data/lib/rails/log/profiling/logger.rb +1 -0
- data/lib/rails/log/profiling/query_log_subscriber.rb +23 -7
- data/lib/rails/log/profiling/version.rb +1 -1
- data/lib/rails_log_profiling.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3012512b383e13d08eb6a013af5ee0ecdf7b82e
|
4
|
+
data.tar.gz: 0b82ba4ba1ef9932c8a9bffecfcb5ba97efda835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aaad508e4cee7775e7282632f4e7e185459bbd10c25a98d8b393809cc062ad2c6b66c132e3e41c0c0b944e6e5f68ccc7ce565969e1cc2b7715d06ccd6f6b6a19
|
7
|
+
data.tar.gz: 41fd34dc7da2d30a0864dce28891e363342ac3adbd2d7cfcfe36d0c79f50bdae4a73841cf979349dfdbf87500164a1236b1b8bfcdd7978dbf3755f259c312d91
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Rails::Log::Profiling
|
2
2
|
|
3
3
|

|
4
|
+
[](http://badge.fury.io/rb/rails_log_profiling)
|
4
5
|
|
5
6
|
Rails専用のパフォーマンスツール
|
6
7
|
- クエリプロファイリング:クエリを降順、昇順に整理してログに出力
|
@@ -11,9 +12,9 @@ TODO:
|
|
11
12
|
- Beta1
|
12
13
|
- クエリプロファイリング機能追加
|
13
14
|
- Beta2
|
14
|
-
- Viewプロファイル機能追加
|
15
15
|
- メソッドの実行箇所検知機能追加
|
16
16
|
- Beta3
|
17
|
+
- Viewプロファイル機能追加
|
17
18
|
- Rails4.0、Rails4.1、Rails4.2、Rails5.0正式サポート
|
18
19
|
|
19
20
|
## Installation
|
@@ -27,11 +28,18 @@ $ gem install rails_log_profiling --pre
|
|
27
28
|
- gemfileに追加
|
28
29
|
|
29
30
|
```
|
30
|
-
gem 'rails_log_profiling', '~> 0.1.0.
|
31
|
+
gem 'rails_log_profiling', '~> 0.1.0.beta2', :group => "development"
|
31
32
|
```
|
32
33
|
|
33
34
|
## Usage
|
34
|
-
|
35
|
+
Rails::Log::Profilingは初期の段階ではなにも行いません、動作させるには
|
36
|
+
config/environments/development.rbに下記の設定を追加してください
|
37
|
+
|
38
|
+
```:devlopment.rb
|
39
|
+
Rails::Log::Profiling.enable = true
|
40
|
+
```
|
41
|
+
|
42
|
+
設定後、Rails Serverを起動
|
35
43
|
log/以下にログファイルが作られ、記録されます
|
36
44
|
|
37
45
|
```
|
@@ -41,19 +49,18 @@ $ tail -f log/rails_log_profiling.log
|
|
41
49
|
PostsController#index
|
42
50
|
|
43
51
|
2件のクエリの検知
|
44
|
-
1: Post Load (1.4ms) SELECT `posts`.* FROM `posts`
|
45
52
|
|
46
|
-
|
47
|
-
|
53
|
+
1: Post Load (3.7ms) SELECT `posts`.* FROM `posts`
|
54
|
+
Identify Query Location::
|
55
|
+
/Users/fukumone/private_repo/rails_test/app/views/posts/index.html.erb:16:in `_app_views_posts_index_html_erb___191904507552904544_70102088595360'
|
48
56
|
|
49
|
-
## Configuration
|
50
|
-
Rails::Log::Profilingは初期の段階ではなにも行いません、動作させるには
|
51
|
-
config/environments/development.rbに下記の設定を追加してください
|
52
57
|
|
53
|
-
|
54
|
-
|
58
|
+
2: CurationType Load (1.4ms) SELECT `curation_types`.* FROM `curation_types` ORDER BY `curation_types`.`id` ASC LIMIT 1
|
59
|
+
Identify Query Location::
|
60
|
+
/Users/fukumone/private_repo/rails_test/app/controllers/posts_controller.rb:9:in `index'
|
55
61
|
```
|
56
62
|
|
63
|
+
## Configuration
|
57
64
|
Rails::Log::Profilingはオプションが用意されています
|
58
65
|
- `Rails::Log::Profiling.enable`: true => Rails::Log::Profilingを有効にする
|
59
66
|
- `Rails::Log::Profiling.sort_order`: クエリの並び順を指定する、降順はdesc、昇順はascと設定してください。初期設定はdescになっています
|
@@ -3,18 +3,16 @@ require 'action_controller'
|
|
3
3
|
module ActionController
|
4
4
|
class Base
|
5
5
|
include Rails::Log::Profiling
|
6
|
-
|
7
|
-
after_action :logger_execute
|
6
|
+
after_action :rails_query_profiling_logger_execute
|
8
7
|
|
9
8
|
private
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Rails::Log::Profiling::QueryProfiling.execute
|
9
|
+
def rails_query_profiling_logger_execute
|
10
|
+
unless Rails::Log::Profiling.sqls.empty?
|
11
|
+
controller_name = params[:controller].split("_").map(&:capitalize).join
|
12
|
+
Rails::Log::Profiling.logger.info("\033[36m #{controller_name}Controller##{params[:action]}")
|
13
|
+
Rails::Log::Profiling.logger.info("\n \033[36m" + Rails::Log::Profiling.sqls.count.to_s + "件のクエリの検知")
|
14
|
+
Rails::Log::Profiling::QueryProfiling.execute
|
15
|
+
end
|
18
16
|
end
|
19
17
|
end
|
20
18
|
end
|
@@ -4,20 +4,21 @@ require "active_record/log_subscriber"
|
|
4
4
|
module Rails::Log::Profiling
|
5
5
|
class QueryLogSubscriber < ActiveRecord::LogSubscriber
|
6
6
|
def sql(event)
|
7
|
+
locations = get_locations
|
8
|
+
return if locations.empty?
|
7
9
|
payload = event.payload
|
8
10
|
|
9
11
|
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
10
12
|
|
11
13
|
if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
|
12
|
-
ar_ver_5(event)
|
14
|
+
ar_ver_5(event, locations)
|
13
15
|
else
|
14
|
-
ar_ver_4(event)
|
16
|
+
ar_ver_4(event, locations)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
19
|
-
|
20
|
-
def ar_ver_5(event)
|
21
|
+
def ar_ver_5(event, locations)
|
21
22
|
payload = event.payload
|
22
23
|
name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
|
23
24
|
sql = payload[:sql]
|
@@ -31,11 +32,11 @@ module Rails::Log::Profiling
|
|
31
32
|
sql = color(sql, sql_color(sql), true)
|
32
33
|
|
33
34
|
if !name.match(/.*ActiveRecord::SchemaMigration.*/) && name.match(/.*Load.\(.*ms\).*/)
|
34
|
-
Rails::Log::Profiling.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}"]
|
35
|
+
Rails::Log::Profiling.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}\n#{locations}"]
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
def ar_ver_4(event)
|
39
|
+
def ar_ver_4(event, locations)
|
39
40
|
payload = event.payload
|
40
41
|
name = '%s (%.1fms)' % [payload[:name], event.duration]
|
41
42
|
sql = payload[:sql].squeeze(' ')
|
@@ -59,8 +60,23 @@ module Rails::Log::Profiling
|
|
59
60
|
end
|
60
61
|
|
61
62
|
if !name.match(/.*ActiveRecord::SchemaMigration.*/) && name.match(/.*Load.\(.*ms\).*/)
|
62
|
-
Rails::Log::Profiling.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}" ]
|
63
|
+
Rails::Log::Profiling.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}\n #{locations}" ]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_locations
|
68
|
+
ans = ""
|
69
|
+
temp = true
|
70
|
+
caller.each do |val|
|
71
|
+
if val.match(Rails::Log::Profiling.current_path)
|
72
|
+
if temp
|
73
|
+
ans += " \033[36mIdentify Query Location:\033[0m\n"
|
74
|
+
temp = false
|
75
|
+
end
|
76
|
+
ans += " " + val + "\n"
|
77
|
+
end
|
63
78
|
end
|
79
|
+
ans
|
64
80
|
end
|
65
81
|
end
|
66
82
|
end
|
data/lib/rails_log_profiling.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_log_profiling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukumone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|