stream_count 1.0.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/stream_count +6 -0
- data/lib/stream_count/version.rb +3 -0
- data/lib/stream_count.rb +58 -0
- data/stream_count.gemspec +26 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25598f94168334a3167006a9f146aee1a06c4eec
|
4
|
+
data.tar.gz: b418501e0d1399972082bb5c62f5a68c2978f223
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d247c6a3acc882209cb7cdf2e8a99ac83b46e8b6a124e22b7765c597480c8f7a82dc73ee4f3a1d1b429c61b0bb84446851bef3d57d2af4c96d4ca99a4a7ef51
|
7
|
+
data.tar.gz: 2b468f4c5e25fed8ee30db5043f2668feb8b760c4bc79612ca140adf12b6e2214c576b59f133071bc3d8b6c3004a795b1bbf356a40cf1e89c93f5e7c1ee09af5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Scott Pierce
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# StreamCount
|
2
|
+
|
3
|
+
Output statistics about data from stdin while redirecting the data to stdout.
|
4
|
+
The statistics are bytes read, bytes read per second, lines read, lines read per
|
5
|
+
second and total seconds.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```sh
|
10
|
+
cat /dev/random | stream_count > /dev/null
|
11
|
+
|
12
|
+
gunzip -c /path/to/file.gz | stream_count > /path/to/unzipped
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Install to local system
|
18
|
+
|
19
|
+
$ gem install stream_count
|
20
|
+
|
21
|
+
When using `rbenv` remember to `rbenv rehash`
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/stream_count.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'stream_count'
|
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__)
|
data/bin/setup
ADDED
data/exe/stream_count
ADDED
data/lib/stream_count.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'stream_count/version'
|
2
|
+
require 'English'
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
# Collects IO stats from stdin and prints the stats to stderr.
|
6
|
+
# Original stdin is output to stdout.
|
7
|
+
#
|
8
|
+
# rubocop:disable all
|
9
|
+
module StreamCount
|
10
|
+
module_function
|
11
|
+
|
12
|
+
BUFFER_SIZE = 1024
|
13
|
+
TICK_DURATION = 0.2
|
14
|
+
|
15
|
+
# Do the work
|
16
|
+
def run(io = ARGF)
|
17
|
+
@start_time = Time.now.to_f
|
18
|
+
bytes = 0
|
19
|
+
lines = 0
|
20
|
+
output(bytes: bytes, lines: lines, throttle: false)
|
21
|
+
while (data = io.read(BUFFER_SIZE))
|
22
|
+
$stdout.print(data)
|
23
|
+
bytes += data.size
|
24
|
+
lines += data.count($INPUT_RECORD_SEPARATOR)
|
25
|
+
output(bytes: bytes, lines: lines, throttle: true)
|
26
|
+
end
|
27
|
+
output(bytes: bytes, lines: lines, throttle: false)
|
28
|
+
end
|
29
|
+
|
30
|
+
# output formatted stats to stderr.
|
31
|
+
# Using throttle will limit how often we print to stderr to 5/second.
|
32
|
+
def output(bytes:, lines:, throttle: true)
|
33
|
+
throttler(force: !throttle) do
|
34
|
+
msg = "\e[1G\e[2K%s seconds | %s bytes [ %s kb/sec ] | %s lines [ %s lines/sec ]"
|
35
|
+
duration = Time.now.to_f - @start_time
|
36
|
+
if duration > 0
|
37
|
+
$stderr.print(msg % [number_with_delimiter(duration.to_i),
|
38
|
+
number_with_delimiter(bytes),
|
39
|
+
number_with_delimiter((bytes / duration / 1024).to_i),
|
40
|
+
number_with_delimiter(lines),
|
41
|
+
number_with_delimiter((lines / duration).to_i)])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def throttler(force:, threshold: TICK_DURATION, &block)
|
47
|
+
@last_tick ||= Time.now.to_f
|
48
|
+
if force || Time.now.to_f > (@last_tick + threshold)
|
49
|
+
block.call
|
50
|
+
@last_tick = Time.now.to_f
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Thanks ActiveSupport::NumberHelper
|
55
|
+
def number_with_delimiter(number, delimiter = ',')
|
56
|
+
number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stream_count/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'stream_count'
|
8
|
+
spec.version = StreamCount::VERSION
|
9
|
+
spec.authors = ['Scott Pierce']
|
10
|
+
spec.email = ['ddrscott@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Prints stats from stdin to stderr and while redirecting stdin back to stdout'
|
13
|
+
spec.homepage = 'https://github.com/ddrscott/stream_count'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stream_count
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Pierce
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-25 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: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ddrscott@gmail.com
|
58
|
+
executables:
|
59
|
+
- stream_count
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- exe/stream_count
|
73
|
+
- lib/stream_count.rb
|
74
|
+
- lib/stream_count/version.rb
|
75
|
+
- stream_count.gemspec
|
76
|
+
homepage: https://github.com/ddrscott/stream_count
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.11
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Prints stats from stdin to stderr and while redirecting stdin back to stdout
|
100
|
+
test_files: []
|