meta_profiler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in meta_profiler.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Joe Fredette
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # MetaProfiler
2
+
3
+ `meta_profiler` provides a single interface to profile small chunks of code across different ruby implementations.
4
+ Presently, it supports Rubinius, JRuby, and MRI > 1.9.2. It may support older MRIs, but they have not yet been tested.
5
+
6
+ This tool was extracted from a script I used to keep lying around in my home directory to help when trying to settle
7
+ debates about whether something was faster or slower, the easiest way to run a profile is simply to install this gem,
8
+ require it, and write your code in a `profile { #code }` block, simply running your desired version of ruby on that
9
+ script will then automatically print profiling results to STDOUT.
10
+
11
+ Future plans include:
12
+
13
+ * providing a consistent report style for all implementations
14
+ * better testing (I told you it was extracted from a throwaway script, right?)
15
+ * less procedural implementation
16
+ * better documentation
17
+ * include memory profiling as an option, etc.
18
+
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ gem 'meta_profiler'
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install meta_profiler
33
+
34
+ ## Usage
35
+
36
+ TODO: Write usage instructions here
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "meta_profiler/version"
2
+ require 'meta_profiler/profile'
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+
3
+ #class MetaProfiler
4
+ #def initialize(opts)
5
+ #@use_gc = opts.delete(:no_gc)
6
+ #@title = opts.delete(:title)
7
+ #@printer = opts.delete(:printer) ||
8
+ #@times_to_execute = opts.delete(:times_to_execute)
9
+ #end
10
+
11
+ #def profile
12
+ #load_profiler!
13
+ #results = run_profile do
14
+ #yield
15
+ #end
16
+ #printer.print(results)
17
+ #end
18
+
19
+ #private
20
+
21
+ #attr_reader :times_to_execute, :title, :printer
22
+
23
+ #def gc?
24
+ #!@use_gc
25
+ #end
26
+
27
+ #def run_profile
28
+ #if @profiler_needs_false
29
+ #@profiler.profile(false) do
30
+ #yield
31
+ #end
32
+ #else
33
+ #@profiler.profile do
34
+ #yield
35
+ #end
36
+ #end
37
+ #end
38
+
39
+ #def load_profiler!
40
+ #if defined?(Rubinius)
41
+ #require 'profiler'
42
+ #@profiler = Rubinius::Profiler::Instrumenter.new
43
+ #@profiler_needs_false = true
44
+ #elsif defined?(JRuby)
45
+ #require 'jruby/profiler'
46
+ #@profiler = JRuby::Profiler
47
+ #else
48
+ #require 'ruby-prof'
49
+ #@profiler = RubyProf
50
+ #end
51
+ #end
52
+ #end
53
+
54
+
55
+ def profile_rubinius_style(opts)
56
+ require 'profiler'
57
+ profiler = Rubinius::Profiler::Instrumenter.new
58
+
59
+ profiler.profile do
60
+ 1_000_000.times do
61
+ yield
62
+ end
63
+ end
64
+ end
65
+
66
+ def profile_rubyprof_style(opts)
67
+ require 'ruby-prof'
68
+ result = RubyProf.profile do
69
+ 1_000_000.times do
70
+ yield
71
+ end
72
+ end
73
+ printer = RubyProf::FlatPrinter.new(result)
74
+ printer.print(STDOUT)
75
+ end
76
+
77
+ def profile_java_style(opts)
78
+ require 'jruby/profiler'
79
+ profile_data = JRuby::Profiler.profile do
80
+ yield
81
+ end
82
+
83
+ profile_printer = JRuby::Profiler::FlatProfilePrinter.new(profile_data)
84
+ profile_printer.printProfile(STDOUT)
85
+ end
86
+
87
+ def profile(title = nil, opts = {})
88
+ GC.disable if opts[:no_gc]
89
+ puts title if title
90
+
91
+ if defined?(Rubinius)
92
+ profile_rubinius_style(opts)
93
+ elsif defined?(JRuby)
94
+ profile_java_style(opts)
95
+ else
96
+ profile_rubyprof_style(opts)
97
+ end
98
+
99
+ puts "--------------------------------------------------------------------------------"
100
+ GC.enable if opts[:no_gc]
101
+ end
@@ -0,0 +1,3 @@
1
+ module MetaProfiler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/meta_profiler/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Joe Fredette"]
6
+ gem.email = ["jfredett@gmail.com"]
7
+ gem.description = %q{Abstracts over the interfaces to the various implementation-specific profiling tools}
8
+ gem.summary = %q{
9
+ meta_profiler provides a single interface to profile small chunks of code across different ruby implementations.
10
+ Presently, it supports Rubinius, JRuby, and MRI > 1.9.2. It may support older MRIs, but they have not yet been tested.
11
+
12
+ This tool was extracted from a script I used to keep lying around in my home directory to help when trying to settle
13
+ debates about whether something was faster or slower, the easiest way to run a profile is simply to install this gem,
14
+ require it, and write your code in a `profile { #code }` block, simply running your desired version of ruby on that
15
+ script will then automatically print profiling results to STDOUT.
16
+ }
17
+ gem.homepage = "http://github.com/jfredett/meta_profiler"
18
+
19
+ if not (defined? Rubinius or defined? JRuby)
20
+ gem.add_dependency 'ruby-prof'
21
+ end
22
+
23
+ gem.files = `git ls-files`.split($\)
24
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
25
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
+ gem.name = "meta_profiler"
27
+ gem.require_paths = ["lib"]
28
+ gem.version = MetaProfiler::VERSION
29
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta_profiler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Joe Fredette
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Abstracts over the interfaces to the various implementation-specific
15
+ profiling tools
16
+ email:
17
+ - jfredett@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/meta_profiler.rb
27
+ - lib/meta_profiler/profile.rb
28
+ - lib/meta_profiler/version.rb
29
+ - meta_profiler.gemspec
30
+ homepage: http://github.com/jfredett/meta_profiler
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ none: false
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ none: false
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: ! 'meta_profiler provides a single interface to profile small chunks of code
54
+ across different ruby implementations. Presently, it supports Rubinius, JRuby, and
55
+ MRI > 1.9.2. It may support older MRIs, but they have not yet been tested. This
56
+ tool was extracted from a script I used to keep lying around in my home directory
57
+ to help when trying to settle debates about whether something was faster or slower,
58
+ the easiest way to run a profile is simply to install this gem, require it, and
59
+ write your code in a `profile { #code }` block, simply running your desired version
60
+ of ruby on that script will then automatically print profiling results to STDOUT.'
61
+ test_files: []
62
+ has_rdoc: