gctools-rails 0.0.1
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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.md +19 -0
- data/Rakefile +20 -0
- data/gctools-rails.gemspec +18 -0
- data/lib/gctools/rails.rb +5 -0
- data/lib/gctools/rails/middleware.rb +16 -0
- data/lib/gctools/rails/railtie.rb +13 -0
- data/lib/gctools/rails/time_logger.rb +22 -0
- data/lib/gctools/rails/timer.rb +21 -0
- data/lib/gctools/rails/version.rb +5 -0
- data/test/test_rails.rb +57 -0
- metadata +75 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: cdc8d15dffd87f6c054da68038632f4cd243c5ad
         | 
| 4 | 
            +
              data.tar.gz: c9ef627da0520a515ea2b0e5c1abca7640871aef
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 7c0a16a9246b01abea5bf153bd134d50bd44dba208db076552eb4862020929e599cd708ece77ea3c1121cef139f6b93b8f4bb391c7b0b385ad4d76308a4c0789
         | 
| 7 | 
            +
              data.tar.gz: c8495fbadbb6deb50f1fd2a2aa336277e051dd8a56ef0ed8498a921e7a90980d67f465f4446df26a9b2cb7d752b1f0a67f0f0f71b0f1bca1fc0614c64da78e8f
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            ## gctools-rails
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Logs the amount of time spent in the MRI garbage collector to the Rails controller log. For example:
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ```
         | 
| 6 | 
            +
            Completed 200 OK in 631ms (Views: 22.1ms | ActiveRecord: 18.7ms | GC=167.0ms | Search=0.0ms | Redis=2 | Memcache=7 | master-queries=3 | shard_0-queries=20 | shop_name=shop1.myshopify.io  | dest_host=shop1.myshopify.io  | pid=45776  | shop_id=1 | shard_id=0 | request_id=cfec5667-8f0b-4b11-b676-6300083bd04f | session_id=20ee8aefeeeae62ece61f6510eed6ac6446723cb315659084f760488bcac1857 | ssl=false | rev=1 )
         | 
| 7 | 
            +
            ```
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ### Install
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            Add the following to your Gemfile:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ```ruby
         | 
| 14 | 
            +
            gem 'gctools-rails'
         | 
| 15 | 
            +
            ```
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ### Notes
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            gctools-rails cannot be used at the same time as the [gctools logger](https://github.com/tmm1/gctools/blob/master/lib/gctools/logger.rb), as they both use `GCProf.after_gc_hook`.
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            task :default => :test
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # ==========================================================
         | 
| 4 | 
            +
            # Packaging
         | 
| 5 | 
            +
            # ==========================================================
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            GEMSPEC = eval(File.read('gctools-rails.gemspec'))
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            require 'rubygems/package_task'
         | 
| 10 | 
            +
            Gem::PackageTask.new(GEMSPEC) do |pkg|
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            # ==========================================================
         | 
| 14 | 
            +
            # Testing
         | 
| 15 | 
            +
            # ==========================================================
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            require 'rake/testtask'
         | 
| 18 | 
            +
            Rake::TestTask.new 'test' do |t|
         | 
| 19 | 
            +
              t.test_files = FileList['test/test_*.rb']
         | 
| 20 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            $:.unshift File.expand_path("../lib", __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'gctools/rails/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name = 'gctools-rails'
         | 
| 7 | 
            +
              s.version = Gctools::Rails::VERSION
         | 
| 8 | 
            +
              s.summary = 'rails logging with gctools'
         | 
| 9 | 
            +
              s.description = 'rails controller logging of GC stats using gctools'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              s.homepage = 'https://github.com/csfrancis/gctools-rails'
         | 
| 12 | 
            +
              s.authors = 'Scott Francis'
         | 
| 13 | 
            +
              s.email   = 'scott.francis@shopify.com'
         | 
| 14 | 
            +
              s.license = 'MIT'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.files = `git ls-files`.split("\n")
         | 
| 17 | 
            +
              s.add_runtime_dependency 'gctools', '~> 0.2', '>= 0.2.3'
         | 
| 18 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            module Gctools
         | 
| 2 | 
            +
              module Rails
         | 
| 3 | 
            +
                class Railtie < ::Rails::Railtie
         | 
| 4 | 
            +
                  initializer 'gctools_rails.configure_controller' do |app|
         | 
| 5 | 
            +
                    app.config.middleware.insert 0, Gctools::Rails::Middleware
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                    ActiveSupport.on_load :action_controller do
         | 
| 8 | 
            +
                      include TimeLogger
         | 
| 9 | 
            +
                    end
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            require 'active_support'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Gctools
         | 
| 4 | 
            +
              module Rails
         | 
| 5 | 
            +
                module TimeLogger
         | 
| 6 | 
            +
                  extend ActiveSupport::Concern
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def append_info_to_payload(payload)
         | 
| 9 | 
            +
                    super
         | 
| 10 | 
            +
                    payload[:gc_time] = Timer.value
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  module ClassMethods
         | 
| 14 | 
            +
                    def log_process_action(payload)
         | 
| 15 | 
            +
                      messages, gc_time = super, payload[:gc_time]
         | 
| 16 | 
            +
                      messages << ("GC=%.1fms" % gc_time) if gc_time
         | 
| 17 | 
            +
                      messages
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module Gctools
         | 
| 2 | 
            +
              module Rails
         | 
| 3 | 
            +
                module Timer
         | 
| 4 | 
            +
                  def self.value
         | 
| 5 | 
            +
                    Thread.current[:gctools_time] ||= 0
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def self.add(gc_time_ms)
         | 
| 9 | 
            +
                    Thread.current[:gctools_time] = value + gc_time_ms
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def self.clear
         | 
| 13 | 
            +
                    Thread.current[:gctools_time] = 0
         | 
| 14 | 
            +
                  end
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            GCProf.after_gc_hook = Proc.new { |info, start, end_mark, end_sweep|
         | 
| 20 | 
            +
              Gctools::Rails::Timer.add((end_mark[:time] - start[:time]) * 1000) if end_sweep
         | 
| 21 | 
            +
            }
         | 
    
        data/test/test_rails.rb
    ADDED
    
    | @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            require 'minitest/autorun'
         | 
| 2 | 
            +
            require 'gctools/rails'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class FakeBaseController
         | 
| 5 | 
            +
              def append_info_to_payload(payload); payload;  end
         | 
| 6 | 
            +
              def self.log_process_action(payload); ''; end
         | 
| 7 | 
            +
            end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            class FakeController < FakeBaseController
         | 
| 10 | 
            +
              include Gctools::Rails::TimeLogger
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            class TestRails < MiniTest::Test
         | 
| 14 | 
            +
              def setup
         | 
| 15 | 
            +
                Gctools::Rails::Timer.clear
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def test_timer_is_thread_local
         | 
| 19 | 
            +
                t = Gctools::Rails::Timer
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                assert_equal 0, t.value
         | 
| 22 | 
            +
                t.add(100)
         | 
| 23 | 
            +
                assert_equal 100, t.value
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                th = Thread.new do
         | 
| 26 | 
            +
                  assert_equal 0, t.value
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              ensure
         | 
| 29 | 
            +
                th.join if th
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def test_time_logger_updates_payload
         | 
| 33 | 
            +
                c = FakeController.new
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                Gctools::Rails::Timer.add(100)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                p = {}
         | 
| 38 | 
            +
                c.append_info_to_payload(p)
         | 
| 39 | 
            +
                assert_equal 100, p[:gc_time]
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                assert c.class.log_process_action(p) =~ /GC=/
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              def test_middleware_clears_timer
         | 
| 45 | 
            +
                c = Class.new do
         | 
| 46 | 
            +
                  def call(env)
         | 
| 47 | 
            +
                    v = Gctools::Rails::Timer.value
         | 
| 48 | 
            +
                    Gctools::Rails::Timer.add(100)
         | 
| 49 | 
            +
                    v
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end.new
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                Gctools::Rails::Timer.add(100)
         | 
| 54 | 
            +
                assert_equal 0, Gctools::Rails::Middleware.new(c).call({})
         | 
| 55 | 
            +
                assert_equal 0, Gctools::Rails::Timer.value
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: gctools-rails
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Scott Francis
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-11-26 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: gctools
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0.2'
         | 
| 20 | 
            +
                - - ">="
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: 0.2.3
         | 
| 23 | 
            +
              type: :runtime
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - "~>"
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '0.2'
         | 
| 30 | 
            +
                - - ">="
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: 0.2.3
         | 
| 33 | 
            +
            description: rails controller logging of GC stats using gctools
         | 
| 34 | 
            +
            email: scott.francis@shopify.com
         | 
| 35 | 
            +
            executables: []
         | 
| 36 | 
            +
            extensions: []
         | 
| 37 | 
            +
            extra_rdoc_files: []
         | 
| 38 | 
            +
            files:
         | 
| 39 | 
            +
            - ".gitignore"
         | 
| 40 | 
            +
            - Gemfile
         | 
| 41 | 
            +
            - README.md
         | 
| 42 | 
            +
            - Rakefile
         | 
| 43 | 
            +
            - gctools-rails.gemspec
         | 
| 44 | 
            +
            - lib/gctools/rails.rb
         | 
| 45 | 
            +
            - lib/gctools/rails/middleware.rb
         | 
| 46 | 
            +
            - lib/gctools/rails/railtie.rb
         | 
| 47 | 
            +
            - lib/gctools/rails/time_logger.rb
         | 
| 48 | 
            +
            - lib/gctools/rails/timer.rb
         | 
| 49 | 
            +
            - lib/gctools/rails/version.rb
         | 
| 50 | 
            +
            - test/test_rails.rb
         | 
| 51 | 
            +
            homepage: https://github.com/csfrancis/gctools-rails
         | 
| 52 | 
            +
            licenses:
         | 
| 53 | 
            +
            - MIT
         | 
| 54 | 
            +
            metadata: {}
         | 
| 55 | 
            +
            post_install_message: 
         | 
| 56 | 
            +
            rdoc_options: []
         | 
| 57 | 
            +
            require_paths:
         | 
| 58 | 
            +
            - lib
         | 
| 59 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 60 | 
            +
              requirements:
         | 
| 61 | 
            +
              - - ">="
         | 
| 62 | 
            +
                - !ruby/object:Gem::Version
         | 
| 63 | 
            +
                  version: '0'
         | 
| 64 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
              requirements:
         | 
| 66 | 
            +
              - - ">="
         | 
| 67 | 
            +
                - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                  version: '0'
         | 
| 69 | 
            +
            requirements: []
         | 
| 70 | 
            +
            rubyforge_project: 
         | 
| 71 | 
            +
            rubygems_version: 2.2.2
         | 
| 72 | 
            +
            signing_key: 
         | 
| 73 | 
            +
            specification_version: 4
         | 
| 74 | 
            +
            summary: rails logging with gctools
         | 
| 75 | 
            +
            test_files: []
         |