rails_log_profiling 0.1.0.beta3 → 0.1.0.beta4
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 +11 -8
- data/lib/rails/log/profiling/action_controller.rb +5 -2
- data/lib/rails/log/profiling/query_log_subscriber.rb +16 -8
- data/lib/rails/log/profiling/query_profiling.rb +2 -2
- data/lib/rails/log/profiling/version.rb +1 -1
- data/lib/rails_log_profiling.rb +10 -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: 24c2d5ab42bd508964e59d05624aca85c2755c30
|
4
|
+
data.tar.gz: d30dc370d4cfe6097326f3cf860d466b25b62101
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a718655ac166899ab4f8afbdb6bc8fcda552d34739b8719c0ab998eea65f6c40044bc5152ae7c0281ca924911682e3739ed8cc339ee114827435c028d1c7f3d
|
7
|
+
data.tar.gz: 9e1db2830a010e7ba53d9ea02d7bc6b9d888d7b9f909874ca01fec63da45c27738c8d8db123af536a68efbc309bcb22a0ea42f1d88fe11d7174420c5372711a2
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Rails::Log::Profiling
|
2
2
|
|
3
3
|

|
4
|
-
[](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=0.1.0.beta4&x4=0)
|
5
5
|
|
6
6
|
Rails専用のパフォーマンスツール
|
7
7
|
- クエリ、viewレンダリングにかかった時間をログに計測して記録
|
@@ -14,13 +14,13 @@ Rails専用のパフォーマンスツール
|
|
14
14
|
- gemとしてインストール
|
15
15
|
|
16
16
|
```
|
17
|
-
$ gem install rails_log_profiling -v 0.1.0.
|
17
|
+
$ gem install rails_log_profiling -v 0.1.0.beta4 --pre
|
18
18
|
```
|
19
19
|
|
20
20
|
- gemfileに追加
|
21
21
|
|
22
22
|
```
|
23
|
-
gem 'rails_log_profiling', '~> 0.1.0.
|
23
|
+
gem 'rails_log_profiling', '~> 0.1.0.beta4', :group => "development"
|
24
24
|
```
|
25
25
|
|
26
26
|
## Usage
|
@@ -46,15 +46,17 @@ Rails::Log::Profiling.view_profiling_enable = true
|
|
46
46
|
$ tail -f log/rails_log_query_profiling.log
|
47
47
|
|
48
48
|
# output
|
49
|
-
|
49
|
+
PostsController#index
|
50
50
|
|
51
|
-
|
52
|
-
Identify Query Location:
|
53
|
-
/Users/fukumone/private_repo/rails_test/app/views/posts/index.html.erb:16:in `_app_views_posts_index_html_erb___3552777926492285037_70120244729720'
|
51
|
+
total query count: 2, total query time: 26.6ms
|
54
52
|
|
55
|
-
|
53
|
+
1: Articles Load (21.7ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` ASC LIMIT 1
|
56
54
|
Identify Query Location:
|
57
55
|
/Users/fukumone/private_repo/rails_test/app/controllers/posts_controller.rb:9:in `index'
|
56
|
+
|
57
|
+
2: Post Load (4.9ms) SELECT `posts`.* FROM `posts`
|
58
|
+
Identify Query Location:
|
59
|
+
/Users/fukumone/private_repo/rails_test/app/views/posts/index.html.erb:16:in `_app_views_posts_index_html_erb__3476269730194822991_70352062040540'
|
58
60
|
```
|
59
61
|
|
60
62
|
```
|
@@ -75,6 +77,7 @@ Rails::Log::Profilingはオプションが用意されています
|
|
75
77
|
- `Rails::Log::Profiling.query_profiling_enable`: true => クエリのプロファイリングを有効にする
|
76
78
|
- `Rails::Log::Profiling.view_profiling_enable`: true => viewのプロファイリングを有効にする
|
77
79
|
- `Rails::Log::Profiling.sort_order`: rails_log_query_profiling.logのクエリの並び順を指定する、降順はdesc、昇順はascと設定してください。初期設定はdescになっています
|
80
|
+
- `Rails::Log::Profiling.continue_to_query_caller`: true => rails_log_query_profiling.logにてクエリメソッドの呼び出し状況を最後までトレースし記録します、探知する量が多くなってしまう場合があるため、初期設定はfalseになっています
|
78
81
|
|
79
82
|
## Inspire
|
80
83
|
- [rack-mini-profiler](https://github.com/MiniProfiler/rack-mini-profiler)
|
@@ -9,8 +9,11 @@ module ActionController
|
|
9
9
|
def rails_query_profiling_logger_execute
|
10
10
|
unless Rails::Log::Profiling.sqls.empty?
|
11
11
|
controller_name = params[:controller].split("_").map(&:capitalize).join
|
12
|
-
Rails::Log::Profiling.query_logger.info("\033[36m #{controller_name}Controller##{params[:action]}")
|
13
|
-
|
12
|
+
Rails::Log::Profiling.query_logger.info("\n\033[36m #{controller_name}Controller##{params[:action]}")
|
13
|
+
log = "\n \033[36m" + "total query count: " + Rails::Log::Profiling.sqls.count.to_s + ", "
|
14
|
+
log += "total query time: #{Rails::Log::Profiling.total_sql_time}ms"
|
15
|
+
Rails::Log::Profiling.total_sql_time = 0
|
16
|
+
Rails::Log::Profiling.query_logger.info(log)
|
14
17
|
Rails::Log::Profiling::QueryProfiling.execute
|
15
18
|
end
|
16
19
|
end
|
@@ -32,7 +32,8 @@ module Rails::Log::Profiling
|
|
32
32
|
sql = color(sql, sql_color(sql), true)
|
33
33
|
|
34
34
|
if !name.match(/.*ActiveRecord::SchemaMigration.*/) && name.match(/.*Load.\(.*ms\).*/)
|
35
|
-
Rails::Log::Profiling.
|
35
|
+
Rails::Log::Profiling.total_sql_time += event.duration.round(1)
|
36
|
+
Rails::Log::Profiling.sqls << [ event.duration.round(1), " #{name} #{sql}#{binds}\n#{locations}"]
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -60,21 +61,28 @@ module Rails::Log::Profiling
|
|
60
61
|
end
|
61
62
|
|
62
63
|
if !name.match(/.*ActiveRecord::SchemaMigration.*/) && name.match(/.*Load.\(.*ms\).*/)
|
63
|
-
Rails::Log::Profiling.
|
64
|
+
Rails::Log::Profiling.total_sql_time += event.duration.round(1)
|
65
|
+
Rails::Log::Profiling.sqls << [ event.duration.round(1), " #{name} #{sql}#{binds}\n #{locations}" ]
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
# クエリの実行箇所を表示
|
68
70
|
def get_locations
|
69
71
|
ans = ""
|
72
|
+
temp = true
|
70
73
|
caller.each do |val|
|
71
74
|
if val.match(Rails::Log::Profiling.current_path)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
if Rails::Log::Profiling.continue_to_query_caller
|
76
|
+
if temp
|
77
|
+
ans += " \033[36mIdentify Query Location:\033[0m\n"
|
78
|
+
temp = false
|
79
|
+
end
|
80
|
+
ans += " " + val + "\n"
|
81
|
+
else
|
82
|
+
ans += " \033[36mIdentify Query Location:\033[0m\n"
|
83
|
+
ans += " " + val
|
84
|
+
break
|
85
|
+
end
|
78
86
|
end
|
79
87
|
end
|
80
88
|
ans
|
@@ -4,7 +4,7 @@ module Rails
|
|
4
4
|
class QueryProfiling
|
5
5
|
def self.execute
|
6
6
|
return if Rails::Log::Profiling.sqls.empty?
|
7
|
-
|
7
|
+
query_sort
|
8
8
|
Rails::Log::Profiling.sqls.each.with_index(1) do |val, ind|
|
9
9
|
Rails::Log::Profiling.query_logger.debug("\n \033[36m #{ind}:" + val[1]) # colorで出力
|
10
10
|
end
|
@@ -12,7 +12,7 @@ module Rails
|
|
12
12
|
Rails::Log::Profiling.sqls.clear
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
private
|
16
16
|
def self.query_sort
|
17
17
|
if Rails::Log::Profiling.sort_order == "desc"
|
18
18
|
Rails::Log::Profiling.sqls.sort! { |a, b| b[0] <=> a[0] }
|
data/lib/rails_log_profiling.rb
CHANGED
@@ -27,6 +27,10 @@ module Rails
|
|
27
27
|
[]
|
28
28
|
end
|
29
29
|
|
30
|
+
config_accessor :total_sql_time, instance_accessor: false do
|
31
|
+
0
|
32
|
+
end
|
33
|
+
|
30
34
|
config_accessor :sort_order, instance_accessor: false do
|
31
35
|
"desc"
|
32
36
|
end
|
@@ -38,6 +42,12 @@ module Rails
|
|
38
42
|
config_accessor :rendering_pages, instance_accessor: false do
|
39
43
|
{ parent: "", children: {} }
|
40
44
|
end
|
45
|
+
|
46
|
+
# メソッドの呼び出し状況を制御する
|
47
|
+
# 再帰的に探索するため、探知する量が多くなってしまう場合があるため、デフォルトは一回で止める
|
48
|
+
config_accessor :continue_to_query_caller, instance_accessor: false do
|
49
|
+
false
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
end
|
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.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fukumone
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|