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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52fdc6db848cb26166fad59f18b363eb80661dbb
4
- data.tar.gz: 07af1e509f9da6cd75ba0f74bbc4ee534edb9473
3
+ metadata.gz: 24c2d5ab42bd508964e59d05624aca85c2755c30
4
+ data.tar.gz: d30dc370d4cfe6097326f3cf860d466b25b62101
5
5
  SHA512:
6
- metadata.gz: 68f379b4bf02a72c187e62598f2627c37f2ac17090a5824ea1795c94067dfb4a3776c70b506b0f4b5fb90cb3e4a18fb8d1f40fada4864313411c999398ef6d84
7
- data.tar.gz: 60abe1e9e46977f0027397fb9fe5e21630b5a4f59150d23b247a486cb9d0046c92445840346280b7943610faa875be3acf8ff97398ff159eec8ea663586f094d
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
  ![Build Status](https://travis-ci.org/fukumone/rails_log_profiling.svg)
4
- [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=0.1.0.beta3&x3=0)](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=0.1.0.beta3&x3=0)
4
+ [![Gem Version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=rb&type=6&v=0.1.0.beta4&x4=0)](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.beta3 --pre
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.beta3', :group => "development"
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
- 2件のクエリの検知
49
+ PostsController#index
50
50
 
51
- 1: Post Load (0.5ms) SELECT `posts`.* FROM `posts`
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
- 2: CurationType Load (0.4ms) SELECT `articles`.* FROM `articles` ORDER BY `articles`.`id` ASC LIMIT 1
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
- Rails::Log::Profiling.query_logger.info("\n \033[36m" + Rails::Log::Profiling.sqls.count.to_s + "件のクエリの検知")
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.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}\n#{locations}"]
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.sqls << [ "#{event.duration.round(1)}".to_f, " #{name} #{sql}#{binds}\n #{locations}" ]
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
- ans += " \033[36mIdentify Query Location:\033[0m\n"
73
- ans += " " + val
74
- # メソッドの呼び出し状況を検知するのは一回で止める
75
- # なぜか? => 再帰的に探索するため、探知する量が多くなってしまう場合があるため
76
- # 別途オプションを設けて最後までメソッドの呼び出し箇所をトレースするかは検討中
77
- break
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
- self.query_sort
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
- protected
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] }
@@ -1,7 +1,7 @@
1
1
  module Rails
2
2
  module Log
3
3
  module Profiling
4
- VERSION = "0.1.0.beta3"
4
+ VERSION = "0.1.0.beta4"
5
5
  end
6
6
  end
7
7
  end
@@ -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.beta3
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-03 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler