query_counter 0.1.2 → 0.2.0

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: 508d6bf9db870504c20574b843e5e9b2b96a5b6f
4
- data.tar.gz: 97bd7b8cd1551fa7c3bf7a069824311a6e8cb130
3
+ metadata.gz: d69555984b1eaadf69789d406d1c2866abe2cb0c
4
+ data.tar.gz: 7131e5990e060322feafa5ec7823a720f2ffd510
5
5
  SHA512:
6
- metadata.gz: 3da22c2df1a96384f083cbc82dcf2bde0bc851f38ef99121772ceeeb7dcbb37b834d33b1fa75533ed4a504573789ca4f911af8249cde6aec038fd7e64006de90
7
- data.tar.gz: ab08ef24e6796b48587ee5915da553da30ca77fc79779ee72a214be9ff921d23cc5e1dd26eb444b4d6f97bbb2eb8ea3cb691683fb6dc31958735a5ff6b94f2f7
6
+ metadata.gz: ea44f6c728227a52c44b30fc0c10755a0e7ec99fc1d214506559f5539ba65af12f48c9a69d76f925e18b44e88dcda0fd321b277107dbba861e6af45f8df1f06a
7
+ data.tar.gz: 90ca373df91ccedb757d0dc9e115819ebdf40e20926309e519ba61c8b68ad0f03faea5431dbd0355f1eb6aa1021d32bc85eff267efebe38ba717f64da91f5bdf
@@ -0,0 +1,14 @@
1
+ module QueryCounter
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ Thread.current[:starting_gc_count] = GC.count
9
+ Thread.current[:starting_count_objects] = ObjectSpace.count_objects
10
+ QueryCounter.reset
11
+ @app.call(env)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module QueryCounter
2
+ module RequestHelper
3
+ def qc_log_resource_usage_around
4
+ yield
5
+ ensure
6
+ qc_log_resource_usage
7
+ end
8
+
9
+ def qc_log_count_objects_around
10
+ yield
11
+ ensure
12
+ qc_log_count_objects
13
+ end
14
+
15
+ def qc_log_resource_usage
16
+ gc = GC.count - Thread.current[:starting_gc_count]
17
+ stats = []
18
+ stats << "gc: #{gc}" if gc > 0
19
+ QueryCounter.current_collector.stats.each do |resource, stat|
20
+ stats << "#{resource}: #{stat.count} [#{stat.time.to_i}ms]"
21
+ end
22
+
23
+ logger.info 'Resource Stats ' + stats.join(', ')
24
+ end
25
+
26
+ def qc_log_count_objects
27
+ diff_count_objects = {}
28
+ ObjectSpace.count_objects.each do |name, count|
29
+ if (diff = (count - Thread.current[:starting_count_objects][name].to_i)) > 0
30
+ diff_count_objects[name] = diff
31
+ end
32
+ end
33
+
34
+ logger.info "Objects: #{diff_count_objects}"
35
+ end
36
+ end
37
+ end
data/lib/query_counter.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module QueryCounter
2
2
  autoload :Collector, 'query_counter/collector'
3
3
  autoload :Global, 'query_counter/global'
4
+ autoload :Middleware, 'query_counter/middleware'
5
+ autoload :RequestHelper, 'query_counter/request_helper'
4
6
  autoload :Stat, 'query_counter/stat'
5
7
 
6
8
  def self.global_collector
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_counter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2019-01-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Used for monitoring number of external calls
14
14
  email: dougyouch@gmail.com
@@ -19,6 +19,8 @@ files:
19
19
  - lib/query_counter.rb
20
20
  - lib/query_counter/collector.rb
21
21
  - lib/query_counter/global.rb
22
+ - lib/query_counter/middleware.rb
23
+ - lib/query_counter/request_helper.rb
22
24
  - lib/query_counter/stat.rb
23
25
  homepage: https://github.com/evertrue/query_counter
24
26
  licenses: []