padrino-performance 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a2b3056cef3b5c7f80d22207ac1e8b7e6f9f53a
4
+ data.tar.gz: d445e124f7d981a787a6c8d814bc8b90b04ac018
5
+ SHA512:
6
+ metadata.gz: 340fa56cedb59dfcee8cfc702b56ea5086c00e7683cbe33e87748ab8878aafe8edd6c51ff93360264de25f649e1688656b639fb34b2add0c8d71424ed0ecb2f2
7
+ data.tar.gz: 9dc7257e3cd71ef4931109adee531bf657558172e1950d6075ed1af7be19835d5e4b1ebb72d8ed701641e779cc88c6ee32b97fad190236251b8c40d9c85ee550
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Padrino
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Padrino Performance
2
+
3
+ Performance tools for Padrino.
4
+
5
+ ## "Installation"
6
+
7
+ Add ```padrino-performance``` to your ```Gemfile```.
8
+
9
+ ## Available suites
10
+
11
+ * JSON. ```-j``` or ```--json``` option.
12
+ * Memory.
13
+
14
+ ## Basic usage
15
+
16
+ ```bundle exec padrino-performance SUITE -- bundle exec padrino COMMAND```
17
+
18
+ E.g.:
19
+
20
+ * Measure json on a console:
21
+ ```bundle exec padrino-performance -j -- bundle exec padrino console```
22
+
23
+ * Measure memory on a running app:
24
+ ```bundle exec padrino-performance -m -- bundle exec padrino start```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # coding:utf-8
2
+ RAKE_ROOT = __FILE__
3
+
4
+ require 'rubygems'
5
+ require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'rbconfig'
4
+
5
+ padrino_perf_path = File.expand_path('../../lib', __FILE__)
6
+
7
+ argv = []
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: padrino-performance [options]"
10
+
11
+ opts.on("-j", "--json", "Check for multiple loaded json libraries") do |v|
12
+ argv << '-r' + File.expand_path(File.join(padrino_perf_path, "suites", "json"))
13
+ end
14
+
15
+ opts.on("-m", "--mem", "Print memory consumption") do |v|
16
+ argv << '-r' + File.expand_path(File.join(padrino_perf_path, "suites", "mem"))
17
+ end
18
+ end.parse!
19
+
20
+ # This little gem is stolen from Rake, thanks Jim!
21
+ RUBY = File.join(
22
+ RbConfig::CONFIG['bindir'],
23
+ RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']).
24
+ sub(/.*\s.*/m, '"\&"')
25
+
26
+ exec({"RUBYOPT" => argv.join("")}, *[RUBY, "-S", *ARGV])
@@ -0,0 +1,2 @@
1
+ require 'padrino-performance/version'
2
+ require 'padrino-performance/os'
@@ -0,0 +1,23 @@
1
+ module Padrino
2
+ module Performance
3
+ # OS detection useful for targeting CLI commands
4
+ # Source: http://stackoverflow.com/questions/170956/how-can-i-find-which-operating-system-my-ruby-program-is-running-on
5
+ module OS
6
+ def self.windows?
7
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
8
+ end
9
+
10
+ def self.mac?
11
+ (/darwin/ =~ RUBY_PLATFORM) != nil
12
+ end
13
+
14
+ def self.unix?
15
+ !self.windows?
16
+ end
17
+
18
+ def self.linux?
19
+ self.unix? and not self.mac?
20
+ end
21
+ end # OS
22
+ end # Performance
23
+ end # Padrino
@@ -0,0 +1,16 @@
1
+ module Padrino
2
+ module Performance
3
+ # The version constant for the current version of Padrino.
4
+ VERSION = '0.10.7' unless defined?(Padrino::VERSION)
5
+
6
+ #
7
+ # The current Padrino version.
8
+ #
9
+ # @return [String]
10
+ # The version number.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ module Padrino
2
+ module Performance
3
+ module JSON
4
+ module InfectedRequire
5
+ def require(*args)
6
+ lib = args.first
7
+ JSON.loaded_lib!(lib) if JSON.registered_libs.include? lib
8
+ super
9
+ end
10
+ end # InfectedRequire
11
+
12
+ def self.registered_libs
13
+ @registered_libs ||= []
14
+ end
15
+
16
+ def self.loaded_libs
17
+ @loaded_libs ||= {}
18
+ end
19
+
20
+ def self.setup_captures!(*libs)
21
+ @registered_libs = libs
22
+ end
23
+
24
+ def self.loaded_lib!(lib)
25
+ loaded_libs[lib] = caller
26
+
27
+ if loaded_libs.size >= 2
28
+ warn <<-WARN
29
+ Concurring json libraries have been loaded. This incurs an
30
+ unneccessary memory overhead at should be avoided. Consult the
31
+ following call stacks to see who loaded the offending libraries
32
+ and contact the authors if necessary:"
33
+ WARN
34
+ loaded_libs.each do |name, stack|
35
+ $stderr.puts "============"
36
+ $stderr.puts "libname: " + name
37
+ $stderr.puts "============"
38
+ $stderr.puts caller
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.infect_require!
44
+ Object.send(:include, InfectedRequire)
45
+ end
46
+
47
+ infect_require!
48
+ setup_captures!("json", "json_pure", "yajl", "oj", "crack", "crack/json")
49
+ end # JSON
50
+ # Performance
51
+ end
52
+ # Padrino
53
+ end
data/lib/suites/mem.rb ADDED
@@ -0,0 +1,33 @@
1
+ module Padrino
2
+ class << self
3
+ def before_load(&block)
4
+ @_before_load ||= []
5
+ @_before_load << block if block_given?
6
+ @_before_load
7
+ end
8
+
9
+ def after_load(&block)
10
+ @_after_load ||= []
11
+ @_after_load << block if block_given?
12
+ @_after_load
13
+ end
14
+
15
+ def perf_memusage_command
16
+ if Performance::OS.mac?
17
+ "vmmap #{$$} | tail -5"
18
+ elsif Performance::OS.linux?
19
+ "pmap #{$$} | tail -1"
20
+ elsif Performance::OS.windows?
21
+ "tasklist /FI \"PID eq #{$$}\""
22
+ end
23
+ end
24
+ end
25
+
26
+ before_load do
27
+ puts `#{perf_memusage_command}`
28
+ end
29
+
30
+ after_load do
31
+ puts `#{perf_memusage_command}`
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env gem build
2
+ # encoding: utf-8
3
+
4
+ require File.expand_path("../lib/padrino-performance/version.rb", __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "padrino-performance"
8
+ s.rubyforge_project = "padrino-performance"
9
+ s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu", "Florian Gilcher", "Darío Javier Cravero", "Igor Bochkariov"]
10
+ s.email = "padrinorb@gmail.com"
11
+ s.summary = "A gem for finding performance problems in Padrino"
12
+ s.homepage = "http://www.padrinorb.com"
13
+ s.description = "A gem for finding performance problems in Padrino by tracking loads and memory consumption."
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.version = Padrino::Performance.version
16
+ s.date = Time.now.strftime("%Y-%m-%d")
17
+
18
+ s.extra_rdoc_files = Dir["*.rdoc"]
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = ["padrino-performance"]
22
+ s.require_paths = ["lib"]
23
+ s.rdoc_options = ["--charset=UTF-8"]
24
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: padrino-performance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.7
5
+ platform: ruby
6
+ authors:
7
+ - Padrino Team
8
+ - Nathan Esquenazi
9
+ - Davide D'Agostino
10
+ - Arthur Chiu
11
+ - Florian Gilcher
12
+ - Darío Javier Cravero
13
+ - Igor Bochkariov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+ date: 2013-03-29 00:00:00.000000000 Z
18
+ dependencies: []
19
+ description: A gem for finding performance problems in Padrino by tracking loads and
20
+ memory consumption.
21
+ email: padrinorb@gmail.com
22
+ executables:
23
+ - padrino-performance
24
+ extensions: []
25
+ extra_rdoc_files: []
26
+ files:
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/padrino-performance
31
+ - lib/padrino-performance.rb
32
+ - lib/padrino-performance/os.rb
33
+ - lib/padrino-performance/version.rb
34
+ - lib/suites/json.rb
35
+ - lib/suites/mem.rb
36
+ - padrino-performance.gemspec
37
+ homepage: http://www.padrinorb.com
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.6
55
+ requirements: []
56
+ rubyforge_project: padrino-performance
57
+ rubygems_version: 2.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A gem for finding performance problems in Padrino
61
+ test_files: []
62
+ has_rdoc: