ben 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +42 -0
- data/README.md +54 -0
- data/Ragfile +5 -0
- data/ben.gemspec +20 -0
- data/ben.watchr +23 -0
- data/bin/1ben +6 -0
- data/bin/ben +14 -0
- data/lib/ben.rb +24 -0
- data/lib/ben/cli.rb +26 -0
- data/lib/ben/disk.rb +59 -0
- data/lib/ben/rc.rb +8 -0
- data/lib/ben/ui.rb +61 -0
- data/lib/ben/version.rb +3 -0
- data/spec/spec_helper.rb +48 -0
- metadata +65 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.1.3)
|
5
|
+
multi_json (~> 1.0)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
hike (1.2.1)
|
8
|
+
i18n (0.6.0)
|
9
|
+
multi_json (1.1.0)
|
10
|
+
optimism (3.1.2)
|
11
|
+
hike (~> 1.2.0)
|
12
|
+
pa (1.2.3)
|
13
|
+
rag (1.2.1)
|
14
|
+
optimism (~> 3.1.0)
|
15
|
+
pa (~> 1.2.0)
|
16
|
+
tagen (~> 1.1.0)
|
17
|
+
thor
|
18
|
+
rspec (2.8.0)
|
19
|
+
rspec-core (~> 2.8.0)
|
20
|
+
rspec-expectations (~> 2.8.0)
|
21
|
+
rspec-mocks (~> 2.8.0)
|
22
|
+
rspec-core (2.8.0)
|
23
|
+
rspec-expectations (2.8.0)
|
24
|
+
diff-lcs (~> 1.1.2)
|
25
|
+
rspec-mocks (2.8.0)
|
26
|
+
tagen (1.1.5)
|
27
|
+
activesupport (~> 3.1.0)
|
28
|
+
i18n
|
29
|
+
thor (0.14.6)
|
30
|
+
watchr (0.7)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
optimism
|
37
|
+
pa
|
38
|
+
rag
|
39
|
+
rspec
|
40
|
+
tagen
|
41
|
+
thor
|
42
|
+
watchr
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
ben, hello world
|
2
|
+
========================
|
3
|
+
|
4
|
+
| Homepage: | https://github.com/GutenYe/ben |
|
5
|
+
|----------------|------------------------------------------------------ |
|
6
|
+
| Author: | Guten |
|
7
|
+
| License: | MIT-LICENSE |
|
8
|
+
| Documentation: | http://rubydoc.info/gems/ben/frames |
|
9
|
+
| Issue Tracker: | https://github.com/GutenYe/ben/issues |
|
10
|
+
|
11
|
+
descripe your prjoect here.
|
12
|
+
|
13
|
+
Getting started
|
14
|
+
---------------
|
15
|
+
|
16
|
+
how to use
|
17
|
+
|
18
|
+
Install
|
19
|
+
-------
|
20
|
+
|
21
|
+
gem install ben
|
22
|
+
|
23
|
+
Note on Patches/Pull Requests
|
24
|
+
-----------------------------
|
25
|
+
|
26
|
+
1. Fork the project.
|
27
|
+
2. Make your feature addition or bug fix.
|
28
|
+
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
|
29
|
+
4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
30
|
+
5. Send me a pull request. Bonus points for topic branches.
|
31
|
+
6. Coding Style Guide: https://gist.github.com/1105334
|
32
|
+
|
33
|
+
Credits
|
34
|
+
-------
|
35
|
+
|
36
|
+
* [Contributors](https://github.com/GutenYe/ben/contributors)
|
37
|
+
|
38
|
+
Resources
|
39
|
+
---------
|
40
|
+
|
41
|
+
some related resources to help each other.
|
42
|
+
|
43
|
+
Copyright
|
44
|
+
---------
|
45
|
+
|
46
|
+
(the MIT License)
|
47
|
+
|
48
|
+
Copyright (c) 2011 Guten
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
51
|
+
|
52
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Ragfile
ADDED
data/ben.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Kernel.load File.expand_path("../lib/ben/version.rb", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "ben"
|
5
|
+
s.version = Ben::VERSION
|
6
|
+
s.summary = "hello world"
|
7
|
+
s.description = <<-EOF
|
8
|
+
hello world
|
9
|
+
EOF
|
10
|
+
|
11
|
+
s.author = "Guten"
|
12
|
+
s.email = "ywzhaifei@gmail.com"
|
13
|
+
s.homepage = "http://github.com/GutenYe/ben"
|
14
|
+
s.rubyforge_project = "xx"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.executables = ["ben"]
|
18
|
+
|
19
|
+
#s.add_dependency "x"
|
20
|
+
end
|
data/ben.watchr
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# lib/**/*.rb
|
2
|
+
watch %r~lib/(.*)\.rb~ do |m|
|
3
|
+
test "spec/#{m[1]}_spec.rb"
|
4
|
+
end
|
5
|
+
|
6
|
+
# spec/**/*_spec.rb
|
7
|
+
watch %r~spec/.*_spec\.rb~ do |m|
|
8
|
+
test m[0]
|
9
|
+
end
|
10
|
+
|
11
|
+
# Ctrl-\
|
12
|
+
Signal.trap('QUIT') do
|
13
|
+
puts "--- Running all tests ---\n\n"
|
14
|
+
test "spec"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test(path)
|
18
|
+
system "clear"
|
19
|
+
cmd = "rspec #{path}"
|
20
|
+
puts cmd
|
21
|
+
system cmd
|
22
|
+
end
|
23
|
+
|
data/bin/1ben
ADDED
data/bin/ben
ADDED
data/lib/ben.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
libdir = File.dirname(__FILE__); $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
2
|
+
|
3
|
+
require "tagen/core"
|
4
|
+
require "optimism"
|
5
|
+
require "pa"
|
6
|
+
|
7
|
+
module Ben
|
8
|
+
autoload :VERSION, "ben/version"
|
9
|
+
autoload :UI, "ben/ui"
|
10
|
+
autoload :CLI, "ben/cli"
|
11
|
+
autoload :Disk, "ben/disk"
|
12
|
+
|
13
|
+
Error = Class.new Exception
|
14
|
+
EFatal = Class.new Exception
|
15
|
+
Rc = Optimism.require "ben/rc", "~/.benrc"
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_accessor :ui
|
19
|
+
|
20
|
+
def ui
|
21
|
+
@ui ||= UI.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ben/cli.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module Ben
|
4
|
+
class CLI < Thor
|
5
|
+
|
6
|
+
class_option "no-color", :banner => "Disable colorization in output", :type => :boolean
|
7
|
+
class_option "verbose", :aliases => "-V", :banner => "Enable verbose output mode", :type => :boolean
|
8
|
+
|
9
|
+
attr_reader :o
|
10
|
+
|
11
|
+
def initialize(*)
|
12
|
+
super
|
13
|
+
o = @o = options.dup
|
14
|
+
the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
|
15
|
+
Ben.ui = UI::Shell.new(the_shell)
|
16
|
+
Ben.ui.debug! if options["verbose"]
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "disk [disk_path]", "run benchmark for disk"
|
20
|
+
def disk(p_disk=nil)
|
21
|
+
p_disk ||= Rc.disk.disk
|
22
|
+
|
23
|
+
Disk.run(p_disk.dup)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/ben/disk.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Ben
|
2
|
+
class Disk
|
3
|
+
class << self
|
4
|
+
def run(p_disk)
|
5
|
+
Disk.new(p_disk).run
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# /dev/sda
|
10
|
+
attr_reader :p_disk
|
11
|
+
|
12
|
+
def initialize(p_disk)
|
13
|
+
@p_disk = p_disk
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_model_number
|
17
|
+
`hdparm -I #{p_disk} | grep 'Model Number' | awk -F: '{print $2}'`.strip.downcase
|
18
|
+
end
|
19
|
+
|
20
|
+
# once
|
21
|
+
def benchmark
|
22
|
+
read, unit = dd_result(`dd if=/dev/zero of=a.bin bs=1M count=1024 conv=fdatasync,notrunc 2>&1`)
|
23
|
+
read = read.to_i
|
24
|
+
|
25
|
+
`su root -c 'echo 3 > /proc/sys/vm/drop_caches'`
|
26
|
+
write, unit1 = dd_result(`dd if=a.bin of=/dev/null bs=1M count=1024 2>&1`)
|
27
|
+
write = write.to_i
|
28
|
+
|
29
|
+
Ben.ui.say "This Time: #{read}#{unit} #{write}#{unit}"
|
30
|
+
|
31
|
+
[read, write, unit]
|
32
|
+
end
|
33
|
+
|
34
|
+
# run n times
|
35
|
+
def run
|
36
|
+
rst = Rc.disk.counts.times.map { benchmark }
|
37
|
+
unit = rst[0][2]
|
38
|
+
|
39
|
+
read, write = rst.transpose[0..1].map {|v|
|
40
|
+
v.inject(:+)/v.length.to_f
|
41
|
+
}
|
42
|
+
|
43
|
+
Ben.ui.say "Average: #{read}#{unit} #{write}#{unit}"
|
44
|
+
|
45
|
+
today = Date.today.strftime("%Y-%m-%d")
|
46
|
+
p_log = Pa("~/.ben/disk.#{get_model_number}")
|
47
|
+
File.append(p_log.p, "#{today}: #{read}#{unit} #{write}#{unit}\n")
|
48
|
+
rescue => e
|
49
|
+
Pa.rm "a.bin"
|
50
|
+
raise e
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def dd_result(result)
|
55
|
+
_, speed, unit = result.split("\n")[-1].match(/, (\d+) (.+)$/).to_a
|
56
|
+
[speed, unit]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/ben/rc.rb
ADDED
data/lib/ben/ui.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Ben
|
2
|
+
class UI
|
3
|
+
def warn(message)
|
4
|
+
end
|
5
|
+
|
6
|
+
def debug(message)
|
7
|
+
end
|
8
|
+
|
9
|
+
def error(message)
|
10
|
+
end
|
11
|
+
|
12
|
+
def info(message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def confirm(message)
|
16
|
+
end
|
17
|
+
|
18
|
+
# alias to info.
|
19
|
+
def say(*args, &blk)
|
20
|
+
info(*args, &blk)
|
21
|
+
end
|
22
|
+
|
23
|
+
class Shell < UI
|
24
|
+
attr_writer :shell
|
25
|
+
|
26
|
+
def initialize(shell)
|
27
|
+
@shell = shell
|
28
|
+
@quiet = false
|
29
|
+
@debug = ENV['DEBUG']
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug(msg)
|
33
|
+
@shell.say(msg) if @debug && !@quiet
|
34
|
+
end
|
35
|
+
|
36
|
+
def info(msg)
|
37
|
+
@shell.say(msg) if !@quiet
|
38
|
+
end
|
39
|
+
|
40
|
+
def confirm(msg)
|
41
|
+
@shell.say(msg, :green) if !@quiet
|
42
|
+
end
|
43
|
+
|
44
|
+
def warn(msg)
|
45
|
+
@shell.say(msg, :yellow)
|
46
|
+
end
|
47
|
+
|
48
|
+
def error(msg)
|
49
|
+
@shell.say(msg, :red)
|
50
|
+
end
|
51
|
+
|
52
|
+
def be_quiet!
|
53
|
+
@quiet = true
|
54
|
+
end
|
55
|
+
|
56
|
+
def debug!
|
57
|
+
@debug = true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/ben/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "ben"
|
2
|
+
|
3
|
+
$spec_dir = File.expand_path("..", __FILE__)
|
4
|
+
$spec_data = File.expand_path("../data", __FILE__)
|
5
|
+
|
6
|
+
Rc = Ben::Rc
|
7
|
+
#Rc._merge! Optimism <<EOF
|
8
|
+
# ...
|
9
|
+
#EOF
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
def capture(stream)
|
13
|
+
begin
|
14
|
+
stream = stream.to_s
|
15
|
+
eval "$#{stream} = StringIO.new"
|
16
|
+
yield
|
17
|
+
result = eval("$#{stream}").string
|
18
|
+
ensure
|
19
|
+
eval("$#{stream} = #{stream.upcase}")
|
20
|
+
end
|
21
|
+
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
alias :silence :capture
|
26
|
+
end
|
27
|
+
|
28
|
+
module Kernel
|
29
|
+
private
|
30
|
+
|
31
|
+
def xdescribe(*args, &blk)
|
32
|
+
describe *args do
|
33
|
+
pending "xxxxxxxxx"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def xcontext(*args, &blk)
|
38
|
+
context *args do
|
39
|
+
pending "xxxxxxxxx"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def xit(*args, &blk)
|
44
|
+
it *args do
|
45
|
+
pending "xxxxxxxx"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ben
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guten
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! 'hello world
|
15
|
+
|
16
|
+
'
|
17
|
+
email: ywzhaifei@gmail.com
|
18
|
+
executables:
|
19
|
+
- ben
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- .rspec
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- README.md
|
28
|
+
- Ragfile
|
29
|
+
- ben.gemspec
|
30
|
+
- ben.watchr
|
31
|
+
- bin/1ben
|
32
|
+
- bin/ben
|
33
|
+
- lib/ben.rb
|
34
|
+
- lib/ben/cli.rb
|
35
|
+
- lib/ben/disk.rb
|
36
|
+
- lib/ben/rc.rb
|
37
|
+
- lib/ben/ui.rb
|
38
|
+
- lib/ben/version.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
homepage: http://github.com/GutenYe/ben
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: xx
|
60
|
+
rubygems_version: 1.8.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: hello world
|
64
|
+
test_files: []
|
65
|
+
has_rdoc:
|