opener-core 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +13 -15
- data/lib/opener/core.rb +11 -6
- data/lib/opener/core/benchmark.rb +146 -0
- data/lib/opener/core/memory_usage.rb +47 -0
- data/lib/opener/core/opt_parser.rb +0 -2
- data/lib/opener/core/resource_switcher.rb +0 -4
- data/lib/opener/core/version.rb +1 -1
- data/opener-core.gemspec +10 -9
- metadata +46 -15
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDhkOTg4NTcxYTBjODY3OTg3NmViOGRkNGJjOGRkNzFhM2UxNmE5NQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 684400e699f1c6e57874760173a14c94867c778f
|
4
|
+
data.tar.gz: 232c9cc158ff147fffcff61a97442f1add08e7cd
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MDcyZTIzMmM1ZTY5MTgyM2NjZjkxMTQxYzE4OTVhN2EzOGE4ZTM5ZjU0NzJi
|
11
|
-
YjBjYTViMzlhOGFkNmI1YTA3ZGQzN2JhMjJjYmIyNmM4MzBkNzY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzQ1ZjkzZDk2YjcyMTAyMDMwMmRhYzUwY2ZkZDVlZWNkMjBjNzIwMWQzODRj
|
14
|
-
NzgwOGE5NjFjMWQzZmU5OGYwNjU0MmEyNTM2ZjIwMDM2ZDYxZThiYzM2MGI1
|
15
|
-
N2UzYzU1YjZiMTZjMjYwZjkwYjQ0ZmNjM2EyMTFjYWJhMGIwYWI=
|
6
|
+
metadata.gz: 8e2e0c45f79e05d39f11add57e75a52ac13c3a39c023fcf0237e3792077ae89911c5289a7ef5d5bbf35792d43b0d5fcafbd1705b393cf081b82daf2a93fd183a
|
7
|
+
data.tar.gz: c41f0f6a35b60c3b3db02b4e305d014813cd06c7803841f37259985a0d41d351fee508af0311e6561e1fd7a81ac6366492b5d7a6d5186d595cb076c37ead5229
|
data/README.md
CHANGED
@@ -1,29 +1,27 @@
|
|
1
1
|
# Opener::Core
|
2
2
|
|
3
|
-
|
3
|
+
A Gem that provides commonly re-used functionality for the various OpeNER Gems.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
You can install opener-core as a Gem by running:
|
8
8
|
|
9
|
-
gem
|
9
|
+
gem install opener-core
|
10
|
+
|
11
|
+
If you're using Bundler you can add the following to your Gemfile:
|
10
12
|
|
11
|
-
|
13
|
+
gem 'opener-core'
|
12
14
|
|
13
|
-
|
15
|
+
Then run `bundle install` to install all the Gems.
|
14
16
|
|
15
|
-
|
17
|
+
## Development
|
16
18
|
|
17
|
-
|
19
|
+
Assuming you have a local copy of this repository, first install all the Gems:
|
18
20
|
|
19
|
-
|
21
|
+
bundle install
|
20
22
|
|
21
|
-
|
23
|
+
Then run the tests to make sure everything is working:
|
22
24
|
|
23
|
-
|
25
|
+
rake
|
24
26
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
27
|
+
You're now good to go!
|
data/lib/opener/core.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'benchmark'
|
2
|
+
require 'optparse'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'uri'
|
5
|
+
require 'nokogiri'
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
require_relative 'core/version'
|
8
|
+
require_relative 'core/argv_splitter'
|
9
|
+
require_relative 'core/opt_parser'
|
10
|
+
require_relative 'core/resource_switcher'
|
11
|
+
require_relative 'core/memory_usage'
|
12
|
+
require_relative 'core/benchmark'
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Opener
|
2
|
+
module Core
|
3
|
+
##
|
4
|
+
# Class for measuring and adding benchmarking information to KAF documents.
|
5
|
+
#
|
6
|
+
# Basic usage is as following:
|
7
|
+
#
|
8
|
+
# benchmark = Opener::Core::Benchmark.new('opener-property-tagger')
|
9
|
+
# document = nil
|
10
|
+
# results = benchmark.measure do
|
11
|
+
# document = some_stuff_that_emits_kaf
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # Add the data to the document. This method returns the new XML as a
|
15
|
+
# # String.
|
16
|
+
# xml = benchmark.write(document, results)
|
17
|
+
#
|
18
|
+
# ## Metrics
|
19
|
+
#
|
20
|
+
# The following metrics are gathered:
|
21
|
+
#
|
22
|
+
# * Starting memory usage
|
23
|
+
# * End memory usage
|
24
|
+
# * Memory increase (if any)
|
25
|
+
# * CPU system time
|
26
|
+
# * CPU user time
|
27
|
+
# * Real time
|
28
|
+
# * Total time
|
29
|
+
#
|
30
|
+
# @!attribute [r] name
|
31
|
+
# @return [String]
|
32
|
+
#
|
33
|
+
# @!attribute [r] results
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
class Benchmark
|
37
|
+
attr_reader :name
|
38
|
+
|
39
|
+
##
|
40
|
+
# @param [String] name The name of the benchmark.
|
41
|
+
#
|
42
|
+
def initialize(name)
|
43
|
+
@name = name
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Measures the block and returns the results as a Hash.
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# measure do
|
51
|
+
# sleep(5)
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# @return [Hash]
|
55
|
+
#
|
56
|
+
def measure
|
57
|
+
mem_usage = MemoryUsage.new
|
58
|
+
mem_start = mem_usage.usage
|
59
|
+
timings = ::Benchmark.measure do
|
60
|
+
yield
|
61
|
+
end
|
62
|
+
|
63
|
+
mem_end = mem_usage.usage
|
64
|
+
|
65
|
+
return {
|
66
|
+
:memory_start => mem_start,
|
67
|
+
:memory_end => mem_end,
|
68
|
+
:memory_increase => mem_end - mem_start,
|
69
|
+
:time_cpu_system => timings.stime,
|
70
|
+
:time_cpu_user => timings.utime,
|
71
|
+
:time_real => timings.real,
|
72
|
+
:time_total => timings.total
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Writes benchmarking results to the specified document.
|
78
|
+
#
|
79
|
+
# @param [String] xml The XML document.
|
80
|
+
# @param [Hash] results The benchmarking results to write.
|
81
|
+
# @return [String]
|
82
|
+
#
|
83
|
+
def write(xml, results)
|
84
|
+
document = Nokogiri::XML(xml)
|
85
|
+
root = document.at('KAF')
|
86
|
+
benchmarks = root.at('benchmarks')
|
87
|
+
|
88
|
+
unless benchmarks
|
89
|
+
benchmarks = Nokogiri::XML::Node.new('benchmarks', document)
|
90
|
+
|
91
|
+
root.add_child(benchmarks)
|
92
|
+
end
|
93
|
+
|
94
|
+
benchmark = create_benchmark_node(document)
|
95
|
+
|
96
|
+
results.each do |name, val|
|
97
|
+
benchmark.add_child(create_node(name, val, document))
|
98
|
+
end
|
99
|
+
|
100
|
+
benchmarks.add_child(benchmark)
|
101
|
+
|
102
|
+
return convert_document(document)
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
##
|
108
|
+
# @param [Nokogiri::XML::Document] document
|
109
|
+
# @return [String]
|
110
|
+
#
|
111
|
+
def convert_document(document)
|
112
|
+
if document.encoding and !document.encoding.empty?
|
113
|
+
return document.to_xml
|
114
|
+
else
|
115
|
+
return document.to_xml(:encoding => 'UTF-8')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# @param [Nokogiri::XML::Document] document
|
121
|
+
# @return [Nokogiri::XML::Node]
|
122
|
+
#
|
123
|
+
def create_benchmark_node(document)
|
124
|
+
node = Nokogiri::XML::Node.new('benchmark', document)
|
125
|
+
|
126
|
+
node.set_attribute('name', name)
|
127
|
+
|
128
|
+
return node
|
129
|
+
end
|
130
|
+
|
131
|
+
##
|
132
|
+
# @param [String|Symbol] name
|
133
|
+
# @param [Mixed] text
|
134
|
+
# @param [Nokogiri::XML::Document] document
|
135
|
+
# @return [Nokogiri::XML::Node]
|
136
|
+
#
|
137
|
+
def create_node(name, text, document)
|
138
|
+
node = Nokogiri::XML::Node.new(name.to_s, document)
|
139
|
+
|
140
|
+
node.inner_html = text.to_s
|
141
|
+
|
142
|
+
return node
|
143
|
+
end
|
144
|
+
end # Benchmark
|
145
|
+
end # Core
|
146
|
+
end # Opener
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Opener
|
2
|
+
module Core
|
3
|
+
##
|
4
|
+
# Class for returning the memory usage of the current process. This uses
|
5
|
+
# the `/proc` filesystem if available and falls back to `ps`.
|
6
|
+
#
|
7
|
+
class MemoryUsage
|
8
|
+
##
|
9
|
+
# Returns the RSS (aka total memory) in bytes.
|
10
|
+
#
|
11
|
+
# @return [Fixnum]
|
12
|
+
#
|
13
|
+
def usage
|
14
|
+
return has_proc? ? rss_proc : rss_ps
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# @return [TrueClass|FalseClass]
|
19
|
+
#
|
20
|
+
def has_proc?
|
21
|
+
return File.exists?('/proc')
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Returns the RSS using the `/proc` filesystem.
|
26
|
+
#
|
27
|
+
# @return [Fixnum]
|
28
|
+
#
|
29
|
+
def rss_proc
|
30
|
+
kb = File.read('/proc/self/status').match(/VmRSS:\s+(\d+)/)[1].to_i
|
31
|
+
|
32
|
+
return kb * 1024
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Returns the RSS using the `ps` command.
|
37
|
+
#
|
38
|
+
# @return [Fixnum]
|
39
|
+
#
|
40
|
+
def rss_ps
|
41
|
+
kb = `ps -o rss= #{Process.pid}`.strip.to_i
|
42
|
+
|
43
|
+
return kb * 1024
|
44
|
+
end
|
45
|
+
end # MemoryUsage
|
46
|
+
end # Core
|
47
|
+
end # Opener
|
data/lib/opener/core/version.rb
CHANGED
data/opener-core.gemspec
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
require File.expand_path('../lib/opener/core/version', __FILE__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name =
|
4
|
+
spec.name = 'opener-core'
|
6
5
|
spec.version = Opener::Core::VERSION
|
7
|
-
spec.authors = [
|
8
|
-
spec.summary =
|
6
|
+
spec.authors = ['development@olery.com']
|
7
|
+
spec.summary = 'Gem that contains some low level generic functions for all OpeNER components.'
|
9
8
|
spec.description = spec.summary
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
9
|
+
spec.homepage = 'http://opener-project.github.com'
|
10
|
+
spec.license = 'Apachev2'
|
12
11
|
|
13
12
|
spec.files = Dir.glob([
|
14
13
|
'lib/**/*',
|
@@ -17,8 +16,10 @@ Gem::Specification.new do |spec|
|
|
17
16
|
]).select { |file| File.file?(file) }
|
18
17
|
|
19
18
|
spec.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
|
20
|
-
spec.require_paths = ["lib"]
|
21
19
|
|
22
|
-
spec.
|
23
|
-
|
20
|
+
spec.add_dependency 'nokogiri'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec'
|
24
25
|
end
|
metadata
CHANGED
@@ -1,56 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opener-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- development@olery.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- -
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Gem that contains some low level generic functions for all OpeNER components.
|
42
70
|
email:
|
43
71
|
executables: []
|
44
72
|
extensions: []
|
45
73
|
extra_rdoc_files: []
|
46
74
|
files:
|
75
|
+
- README.md
|
76
|
+
- lib/opener/core.rb
|
47
77
|
- lib/opener/core/argv_splitter.rb
|
78
|
+
- lib/opener/core/benchmark.rb
|
79
|
+
- lib/opener/core/memory_usage.rb
|
48
80
|
- lib/opener/core/opt_parser.rb
|
49
81
|
- lib/opener/core/resource_switcher.rb
|
50
82
|
- lib/opener/core/version.rb
|
51
|
-
- lib/opener/core.rb
|
52
83
|
- opener-core.gemspec
|
53
|
-
- README.md
|
54
84
|
homepage: http://opener-project.github.com
|
55
85
|
licenses:
|
56
86
|
- Apachev2
|
@@ -61,18 +91,19 @@ require_paths:
|
|
61
91
|
- lib
|
62
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
93
|
requirements:
|
64
|
-
- -
|
94
|
+
- - ">="
|
65
95
|
- !ruby/object:Gem::Version
|
66
96
|
version: '0'
|
67
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
98
|
requirements:
|
69
|
-
- -
|
99
|
+
- - ">="
|
70
100
|
- !ruby/object:Gem::Version
|
71
101
|
version: '0'
|
72
102
|
requirements: []
|
73
103
|
rubyforge_project:
|
74
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.2.2
|
75
105
|
signing_key:
|
76
106
|
specification_version: 4
|
77
|
-
summary: Gem that contains some low
|
107
|
+
summary: Gem that contains some low level generic functions for all OpeNER components.
|
78
108
|
test_files: []
|
109
|
+
has_rdoc:
|