rails_request_stats 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2d27ad0c7ca09478c330b639daab0a4813a2256
4
- data.tar.gz: 5265e09e5fa4c1b39f30d8232ffb2b544b1dec27
3
+ metadata.gz: ab69ce19ea59ef2b15b17bc12415087f6a16ece0
4
+ data.tar.gz: 4c556b965584ba9b96000acbe57b1c22868e01fa
5
5
  SHA512:
6
- metadata.gz: f66bf947b48629445e225ae7ce1b43131e8d7d4e9d697d67a017422c8d9e4fad6cb567da2074ffd697d7ca5b5423a1aeef417dc3d01ed641a36405910ed1f94f
7
- data.tar.gz: 5662c228ddbaa04ab9f45a7e35d5c5e0264f2b8302be7c0512b9021e9700aea0fd8c91a72fe65316f463653b35d02fabda3cec46d5e8b423ac9eb3343a476848
6
+ metadata.gz: f2266f9d67a4425d725f2d427743091cffd71648c132502c2d64cbcf190f8b52e6dc952cf45772632bf5b67e3cf000133bdd4abfc097a8be71d7ea25fce230ab
7
+ data.tar.gz: ddb528f614494ed89034524c498694415d42c432c89633e139ae9e12fa761cfb13e6ad1484553b2cd791dd9b37c27616ed49097892d9eefcc81992fc215ca9e9
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
4
  before_install: gem install bundler -v 1.10.6
5
+ after_success:
6
+ - bundle exec codeclimate-test-reporter
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in rails_request_stats.gemspec
4
- gemspec
3
+ group :test do
4
+ gem 'simplecov'
5
+ gem 'codeclimate-test-reporter', '~> 1.0.0'
6
+ end
5
7
 
6
- gem 'codeclimate-test-reporter', group: :test, require: nil
8
+ gemspec
data/README.md CHANGED
@@ -19,6 +19,8 @@ During development have you ever:
19
19
  `RailsRequestStats::NotificationSubscribers` when required will subscribe to the `sql.active_record`, `start_processing.action_controller`, and `process_action.action_controller` `ActionSupport::Notifications`.
20
20
 
21
21
  * The `sql.active_record` event allow us to count each SQL query that passes though ActiveRecord, which we count internally.
22
+ * The `cache_read.active_support` event allows us to count each read and hit to the Rails cache.
23
+ * The `cache_fetch_hit.active_support` event allows us to count the cache hits to the Rails cache when using *fetch*.
22
24
  * The `start_processing.action_controller` event allows us to clear iternal counts, as well as perform a `GC.start` and capturing the count of objects residing in the `ObjectSpace`.
23
25
  * The `process_action.action_controller` event provides us runtime information along with identifying controller action details, we even determine the number of generated objects since the start of processing the action. At this point we are able to synthesis the query information and runtime information and store them internally in running collection of `RailsRequestStats::RequestStats` objects.
24
26
 
@@ -37,10 +39,10 @@ gem 'rails_request_stats', group: :development
37
39
  Within the console ./log/development.log you should start seeing the following statement appearing at the end of processing a request:
38
40
 
39
41
  ```
40
- [RailsRequestStats] (AVG view_runtime: 163.655ms | AVG db_runtime: 15.465ms | AVG generated_object_count: 14523 | query_count: 9 | cached_query_count: 0)
42
+ [RailsRequestStats] (AVG view_runtime: 163.655ms | AVG db_runtime: 15.465ms | AVG generated_object_count: 14523 | query_count: 9 | cached_query_count: 0 | cache_read_count: 3 | cache_hit_count: 3)
41
43
  ```
42
44
 
43
- Finally when you exit the application's server, you should see a report of all the data captured:
45
+ Finally when you exit the application's server, you should see a summary report of all the data captured:
44
46
 
45
47
  ```
46
48
  [RailsRequestStats] INDEX:html "/users" (AVG view_runtime: 128.492ms | AVG db_runtime: 9.186ms | AVG generated_object_count: 25529 | MIN query_count: 8 | MAX query_count: 9) from 4 requests
@@ -60,7 +62,7 @@ RailsRequestStats::Report.print_memory_stats = true
60
62
  You can see the *generated objects* within the `ObjectSpace` for individual requests:
61
63
 
62
64
  ```
63
- [RailsRequestStats] (AVG view_runtime: 93.7252ms | AVG db_runtime: 8.66075ms | AVG generated_object_count: 125282 | query_count: 8 | cached_query_count: 0 | generated_objects: {:total_generated_objects=>111878, :object=>921, :class=>35, :module=>0, :float=>0, :string=>49501, :regexp=>1556, :array=>17855, :hash=>2087, :struct=>103, :bignum=>0, :file=>0, :data=>37682, :match=>373, :complex=>0, :node=>1688, :iclass=>0})
65
+ [RailsRequestStats] (AVG view_runtime: 93.7252ms | AVG db_runtime: 8.66075ms | AVG generated_object_count: 125282 | query_count: 8 | cached_query_count: 0 | cache_read_count: 3 | cache_hit_count: 3 | generated_objects: {:total_generated_objects=>111878, :object=>921, :class=>35, :module=>0, :float=>0, :string=>49501, :regexp=>1556, :array=>17855, :hash=>2087, :struct=>103, :bignum=>0, :file=>0, :data=>37682, :match=>373, :complex=>0, :node=>1688, :iclass=>0})
64
66
  ```
65
67
 
66
68
  ### Override Reports
@@ -6,14 +6,18 @@ module RailsRequestStats
6
6
  class << self
7
7
  attr_accessor :query_count,
8
8
  :cached_query_count,
9
+ :cache_read_count,
10
+ :cache_hit_count,
9
11
  :before_object_space,
10
- :after_object_space
12
+ :after_object_space,
11
13
  :requests
12
14
  end
13
15
 
14
16
  def self.reset_counts
15
17
  @query_count = 0
16
18
  @cached_query_count = 0
19
+ @cache_read_count = 0
20
+ @cache_hit_count = 0
17
21
  @before_object_space = {}
18
22
  @after_object_space = {}
19
23
  end
@@ -40,12 +44,29 @@ module RailsRequestStats
40
44
  handle_process_action_event(args.extract_options!)
41
45
  end
42
46
 
47
+ ActiveSupport::Notifications.subscribe('cache_read.active_support') do |*args|
48
+ handle_cache_read_event(args.extract_options!)
49
+ end
50
+
51
+ ActiveSupport::Notifications.subscribe('cache_fetch_hit.active_support') do |*args|
52
+ handle_cache_fetch_hit_event(args.extract_options!)
53
+ end
54
+
43
55
  def self.at_exit_handler
44
56
  @requests.each_value do |request_stats|
45
57
  Rails.logger.info { Report.new(request_stats).exit_report_text }
46
58
  end
47
59
  end
48
60
 
61
+ def self.handle_cache_read_event(event)
62
+ @cache_read_count += 1
63
+ @cache_hit_count += 1 if event.fetch(:hit, false)
64
+ end
65
+
66
+ def self.handle_cache_fetch_hit_event(event)
67
+ @cache_hit_count += 1
68
+ end
69
+
49
70
  def self.handle_sql_event(event)
50
71
  return if event[:name] == SCHEMA_NAME
51
72
 
@@ -70,6 +91,7 @@ module RailsRequestStats
70
91
  request_key = { action: event[:action], format: event[:format], method: event[:method], path: event[:path] }
71
92
  request_stats = @requests[request_key] || RequestStats.new(request_key)
72
93
  @requests[request_key] = request_stats.tap do |stats|
94
+ stats.add_cache_stats(@cache_read_count, @cache_hit_count)
73
95
  stats.add_database_query_stats(@query_count, @cached_query_count)
74
96
  stats.add_object_space_stats(@before_object_space, @after_object_space)
75
97
  stats.add_runtime_stats(event[:view_runtime], event[:db_runtime])
@@ -19,9 +19,11 @@ module RailsRequestStats
19
19
  avg_generated_object_count = "AVG generated_object_count: #{format_number(avg(object_space_stats.generated_object_count_collection))}"
20
20
  query_count = "query_count: #{format_number(database_query_stats.query_count_collection.last)}"
21
21
  cached_query_count = "cached_query_count: #{format_number(database_query_stats.cached_query_count_collection.last)}"
22
+ cache_read_count = "cache_read_count: #{format_number(cache_stats.cache_read_count_collection.last)}"
23
+ cache_hit_count = "cache_hit_count: #{format_number(cache_stats.cache_hit_count_collection.last)}"
22
24
  generated_objects = self.class.print_memory_stats ? "generated_objects: #{object_space_stats.last_stats_generated_objects}" : nil
23
25
 
24
- "[RailsRequestStats] (#{[avg_view_runtime, avg_db_runtime, avg_generated_object_count, query_count, cached_query_count, generated_objects].compact.join(' | ')})"
26
+ "[RailsRequestStats] (#{[avg_view_runtime, avg_db_runtime, avg_generated_object_count, query_count, cached_query_count, cache_read_count, cache_hit_count, generated_objects].compact.join(' | ')})"
25
27
  end
26
28
 
27
29
  def exit_report_text
@@ -61,5 +63,9 @@ module RailsRequestStats
61
63
  def runtime_stats
62
64
  @runtime_stats ||= @request_stats.runtime_stats
63
65
  end
66
+
67
+ def cache_stats
68
+ @cache_stats ||= @request_stats.cache_stats
69
+ end
64
70
  end
65
71
  end
@@ -7,7 +7,8 @@ module RailsRequestStats
7
7
 
8
8
  :database_query_stats,
9
9
  :object_space_stats,
10
- :runtime_stats
10
+ :runtime_stats,
11
+ :cache_stats
11
12
 
12
13
  def initialize(key)
13
14
  @action = key[:action]
@@ -18,6 +19,7 @@ module RailsRequestStats
18
19
  @database_query_stats = Stats::DatabaseQueryStats.new
19
20
  @object_space_stats = Stats::ObjectSpaceStats.new
20
21
  @runtime_stats = Stats::RuntimeStats.new
22
+ @cache_stats = Stats::CacheStats.new
21
23
  end
22
24
 
23
25
  def add_database_query_stats(query_count, cached_query_count)
@@ -31,5 +33,9 @@ module RailsRequestStats
31
33
  def add_runtime_stats(view_runtime, db_runtime)
32
34
  @runtime_stats.add_stats(view_runtime, db_runtime)
33
35
  end
36
+
37
+ def add_cache_stats(cache_read_count, cache_hit_count)
38
+ @cache_stats.add_stats(cache_read_count, cache_hit_count)
39
+ end
34
40
  end
35
41
  end
@@ -0,0 +1,18 @@
1
+ module RailsRequestStats
2
+ module Stats
3
+ class CacheStats
4
+ attr_reader :cache_read_count_collection
5
+ attr_reader :cache_hit_count_collection
6
+
7
+ def initialize
8
+ @cache_read_count_collection = []
9
+ @cache_hit_count_collection = []
10
+ end
11
+
12
+ def add_stats(cache_read_count, cache_hit_count)
13
+ @cache_read_count_collection << cache_read_count
14
+ @cache_hit_count_collection << cache_hit_count
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsRequestStats
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_request_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Jalbert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-10 00:00:00.000000000 Z
11
+ date: 2016-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,6 +99,7 @@ files:
99
99
  - lib/rails_request_stats/notification_subscribers.rb
100
100
  - lib/rails_request_stats/report.rb
101
101
  - lib/rails_request_stats/request_stats.rb
102
+ - lib/rails_request_stats/stats/cache_stats.rb
102
103
  - lib/rails_request_stats/stats/database_query_stats.rb
103
104
  - lib/rails_request_stats/stats/object_space_stats.rb
104
105
  - lib/rails_request_stats/stats/runtime_stats.rb
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  requirements: []
126
127
  rubyforge_project:
127
- rubygems_version: 2.4.5.1
128
+ rubygems_version: 2.5.1
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: Provides additional development statistics on Rails requests in logfile