pry-stackprofiler 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b84a467aa4f568357d73d130ee367ed2ea378059
4
+ data.tar.gz: 0134619b03e9eba56602f241a8bd770b0d283819
5
+ SHA512:
6
+ metadata.gz: 8d3ea456c5f5e3fb0db2010ede0cad959c9b622ea419b58df99504a0bd315c12470b011e6e777f718e7b9cd577edda288441cd70b05edab2f2600752a8c4488f
7
+ data.tar.gz: bb4dcb7e55ad7c768e15633bb4600bcd0c0db0a90b45bee7a34d919c3c8fee087e12ea7365e77d447d656d00050c40cce5683b9b7cc5621e5a67384d48cbed6d
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pry-pry-stackprofiler.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Aidan Steele
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.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Pry-Stackprofiler
2
+
3
+ Please read the [`stackprofiler`][1] gem README for background on Stackprofiler
4
+ in general.
5
+
6
+ This is a [Pry][2] plugin that makes benchmarking of code using Stackprofiler a
7
+ much more fluid experience and provide a quicker turn-around time. It does
8
+ this by passing along Pry's linebuffer to the Stackprofiler server so that
9
+ code needn't be stored in the file system for Stackprofiler to annotate.
10
+
11
+ ## Installation
12
+
13
+ $ gem install pry-stackprofiler
14
+
15
+ Once installed, Pry should autoload the plugin. No `require` necessary. There is
16
+ some setup required on the plugin side; specifically, the plugin needs to be told
17
+ where to send profile data. This can be done either by means of an environment
18
+ variable or in `~/.pryrc`.
19
+
20
+ ```ruby
21
+ # ~/.pryrc
22
+ Pry.config.pry_stackprofiler_ui_url = "http://localhost:9292/__stackprofiler/receive"
23
+ ```
24
+
25
+ or
26
+
27
+ ```bash
28
+ # ~/.bashrc
29
+ export PRY_STACKPROFILER_UI_URL=http://localhost:9292/__stackprofiler/receive
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ Start up Stackprofiler on the command line:
35
+
36
+ $ stackprofiler
37
+
38
+ In another tab, start up a Pry session:
39
+
40
+ $ pry
41
+ [1] pry(main)> Pry.profile do
42
+ [1] pry(main)* sleep 0.3
43
+ [1] pry(main)* sleep 0.4
44
+ [1] pry(main)* sleep 0.1
45
+ [1] pry(main)* end
46
+
47
+ Now navigate to Stackprofiler (probably at [http://localhost:9292/__stackprofiler][3])
48
+ and see which lines were slowest!
49
+
50
+ You can pass an options hash to `Pry::profile` if desired. The most useful key is `interval`
51
+ and specifies how often the code should be sampled in microseconds. The default is 1000.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/glassechidna/pry-stackprofiler/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
60
+
61
+ [1]: https://github.com/glassechidna/stackprofiler
62
+ [2]: https://github.com/pry/pry
63
+ [3]: http://localhost:9292/__stackprofiler
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,48 @@
1
+ require 'net/http'
2
+ require 'stackprof'
3
+
4
+ module PryStackprofiler
5
+ class << self
6
+ @last_profile = nil
7
+ @needs_send = false
8
+ @blk_obj_id = 0
9
+
10
+ def profile opts={}, &blk
11
+ # todo: pass through options perhaps?
12
+ opts.merge!({mode: :wall, raw: true})
13
+ @last_profile = StackProf.run(opts) { blk.call }
14
+ @blk_obj_id = RubyVM::InstructionSequence::of(blk).object_id
15
+ @needs_send = true
16
+ end
17
+
18
+ def try_send
19
+ return unless @needs_send
20
+ @needs_send = false
21
+
22
+ pry_file = Pry.line_buffer.join
23
+ @last_profile[:files] = {'(pry)' => pry_file}
24
+ @last_profile[:suggested_rebase] = @blk_obj_id
25
+
26
+ url = URI::parse ui_url
27
+ headers = {'Content-Type' => 'application/x-ruby-marshal'}
28
+ req = Net::HTTP::Post.new(url.to_s, headers)
29
+ req.body = Marshal.dump @last_profile
30
+
31
+ response = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
32
+ end
33
+
34
+ def ui_url
35
+ Pry.config.pry_stackprofiler_ui_url ||= ENV['PRY_STACKPROFILER_UI_URL']
36
+ end
37
+ end
38
+ end
39
+
40
+ class Pry
41
+ Pry.config.hooks.add_hook :after_eval, :stackprofiler do |t|
42
+ PryStackprofiler::try_send
43
+ end
44
+
45
+ def self.profile opts={}, &blk
46
+ PryStackprofiler::profile opts, &blk
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ require 'pry-stackprofiler'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'pry-stackprofiler'
5
+ spec.version = '0.0.1'
6
+ spec.authors = ['Aidan Steele']
7
+ spec.email = ['aidan.steele@glassechidna.com.au']
8
+ spec.summary = %q{A pry plugin to facilitate easy benchmarking of Ruby code.}
9
+ spec.homepage = 'https://github.com/glassechidna/pry-stackprofiler'
10
+ spec.license = 'MIT'
11
+
12
+ spec.files = `git ls-files -z`.split("\x0")
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.required_ruby_version = '>= 2.1.0'
18
+
19
+ spec.add_dependency 'pry', '~> 0.10'
20
+ spec.add_dependency 'stackprof', '~> 0.2'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-stackprofiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aidan Steele
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: stackprof
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - aidan.steele@glassechidna.com.au
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/pry-stackprofiler.rb
82
+ - lib/pry/stackprofiler.rb
83
+ - pry-stackprofiler.gemspec
84
+ homepage: https://github.com/glassechidna/pry-stackprofiler
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: A pry plugin to facilitate easy benchmarking of Ruby code.
108
+ test_files: []
109
+ has_rdoc: