perf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 22f794441547f1613d50fada9a37b0b221f562af5367bf210e024bbc1a7d0ab0
4
+ data.tar.gz: 588de6676ef530e45bfc4a482a9fea4d5dc0b0027b7e8e1e6c8dacf76635f3d5
5
+ SHA512:
6
+ metadata.gz: f77e27800bacd8b88609753add569545722960aee052e517f21d2f2888a2f61587ab5f9ef231623ac9fa1dd9dbd1045f7c65e2fafd48f892a9418a2f96421e0b
7
+ data.tar.gz: 6d7fd63da62807a503fea6860e00e117098b95cae50c4498fdc32f7f640a25136cc3eefada1c4c2330d08ed88e38cdf3b466cc2c9687ea10bbd8919bda5bea2b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ /a.rb
11
+ /perf.data*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in perf.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Takashi Kokubun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Perf
2
+
3
+ Use Linux perf for some region of Ruby code easily.
4
+
5
+ ## Usage
6
+
7
+ Run as root to use perf. Otherwise it just executes a given block.
8
+
9
+
10
+ ### perf record
11
+
12
+ ```rb
13
+ require 'erb'
14
+ require 'perf'
15
+
16
+ def bench
17
+ ERB.new('<%= 1 %>').result
18
+ end
19
+
20
+ 10000.times { bench }
21
+ if RubyVM::MJIT.enabled?
22
+ RubyVM::MJIT.pause
23
+ end
24
+
25
+ Perf.record(count: 5000) do
26
+ 50000.times { bench }
27
+ end
28
+ ```
29
+
30
+ ### perf stat
31
+
32
+ ```rb
33
+ Perf.stat(event: %w[cycles instructions branches branch-misses]) do
34
+ 50000.times { bench }
35
+ end
36
+ ```
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "perf"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require 'perf/version'
2
+
3
+ class << Perf
4
+ def record(*args, count: nil, &block)
5
+ if count
6
+ args = args.dup.push('-c', count.to_s)
7
+ end
8
+ with_perf('record', *args, &block)
9
+ end
10
+
11
+ def stat(*args, event: nil, &block)
12
+ if event
13
+ args = args.dup.push('-e', event.join(','))
14
+ end
15
+ with_perf('stat', *args, &block)
16
+ end
17
+
18
+ private
19
+
20
+ def with_perf(*args, count: nil)
21
+ if ENV['USER'] == 'root'
22
+ pid = Process.spawn('perf', *args, '-p', Process.pid.to_s)
23
+ end
24
+ yield
25
+ ensure
26
+ if pid
27
+ Process.kill(:INT, pid)
28
+ Process.wait(pid)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Perf
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'perf/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'perf'
7
+ spec.version = Perf::VERSION
8
+ spec.authors = ['Takashi Kokubun']
9
+ spec.email = ['takashikkbn@gmail.com']
10
+
11
+ spec.summary = %q{A gem to use Linux perf easily}
12
+ spec.description = %q{A gem to use Linux perf easily}
13
+ spec.homepage = 'https://github.com/k0kubun/perf'
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'rake'
27
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: perf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takashi Kokubun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A gem to use Linux perf easily
42
+ email:
43
+ - takashikkbn@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/perf.rb
56
+ - lib/perf/version.rb
57
+ - perf.gemspec
58
+ homepage: https://github.com/k0kubun/perf
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.0.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A gem to use Linux perf easily
81
+ test_files: []