but 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/README.md +35 -2
- data/but.gemspec +3 -0
- data/lib/but/cli.rb +5 -0
- data/lib/but/dev_wrapper.rb +35 -0
- data/lib/but/home_keeper.rb +53 -5
- data/lib/but/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd129d50d267af66d41279fbb6ae787a66110f1ad1f16953a1bead04b377bc9
|
4
|
+
data.tar.gz: 23264ed3f2984516b6dee0e4580cb7310ab6776935d0499bf85153b35ba38f61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d68c15cdb023b8551ce7dce30a512662db12292eabfb8d8d7a91512b5e325739916dc9f495e43002c391599f872f8d77e94bcdbc1c9ea45906c1881f2da495
|
7
|
+
data.tar.gz: dfe73f4d8d3bda17e89b24f84b24e6039db08137e432eccc9d3bc1bdf8beca2dfce84961c2d9742630b77a88abc48b36f8cba85c3fafd774131175967a1caf2a
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
but (0.1.
|
4
|
+
but (0.1.7)
|
5
5
|
colorize
|
6
|
+
ruby-prof
|
7
|
+
ruby-progressbar
|
6
8
|
thor
|
7
9
|
|
8
10
|
GEM
|
@@ -129,6 +131,7 @@ GEM
|
|
129
131
|
unicode-display_width (>= 1.4.0, < 2.0)
|
130
132
|
rubocop-ast (0.0.3)
|
131
133
|
parser (>= 2.7.0.1)
|
134
|
+
ruby-prof (1.4.1)
|
132
135
|
ruby-progressbar (1.10.1)
|
133
136
|
shellany (0.0.1)
|
134
137
|
sys-uname (1.2.1)
|
data/README.md
CHANGED
@@ -95,9 +95,42 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
95
95
|
|
96
96
|
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).
|
97
97
|
|
98
|
+
### Benchmarking and Profiling
|
99
|
+
|
100
|
+
#### Benchmarking
|
101
|
+
|
102
|
+
Each subcommand can be benchmarked by
|
103
|
+
|
104
|
+
```
|
105
|
+
### Garbage collector enabled
|
106
|
+
but command subcommand --measure --gc
|
107
|
+
|
108
|
+
#or
|
109
|
+
|
110
|
+
### Garbage collector disabled
|
111
|
+
but command subcommand --measure --nogc
|
112
|
+
```
|
113
|
+
|
114
|
+
#### Profiling
|
115
|
+
|
116
|
+
Each subcommand can be profiled using ruby prof
|
117
|
+
|
118
|
+
```
|
119
|
+
but command --profile <MEASURING METHOD>
|
120
|
+
```
|
121
|
+
|
122
|
+
where possible options are
|
123
|
+
|
124
|
+
```
|
125
|
+
but command --profile WALL_TIME
|
126
|
+
but command --profile PROCESS_TIME
|
127
|
+
but command --profile ALLOCATIONS
|
128
|
+
but command --profile MEMORY
|
129
|
+
```
|
130
|
+
|
98
131
|
### Contributing
|
99
132
|
|
100
|
-
Bug reports and pull requests are welcome on
|
133
|
+
Bug reports and pull requests are welcome on GitLab at https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
101
134
|
|
102
135
|
### License
|
103
136
|
|
@@ -105,5 +138,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
105
138
|
|
106
139
|
### Code of Conduct
|
107
140
|
|
108
|
-
Everyone interacting in the But project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
141
|
+
Everyone interacting in the But project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools/-/blob/master/CODE_OF_CONDUCT.md).
|
109
142
|
|
data/but.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["raphael.mueller@computational.bio.uni-giessen.de"]
|
10
10
|
spec.homepage = 'https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools'
|
11
11
|
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = '>=2.6.0'
|
12
13
|
spec.summary = "Tools, to help users to improve their experience with the BCF infrastructure."
|
13
14
|
spec.description = "BCF admins have a hard live. Their user's don't keep their $HOMES and other working places clean. It appears that some users don't know that they use too much space in their home or don't clean used directories on cluster (or other) machines. This tools helps users find unused and unwanted directories, which could make BCF admins happier."
|
14
15
|
|
@@ -48,6 +49,8 @@ Gem::Specification.new do |spec|
|
|
48
49
|
|
49
50
|
spec.add_dependency 'thor'
|
50
51
|
spec.add_dependency 'colorize'
|
52
|
+
spec.add_dependency 'ruby-prof'
|
53
|
+
spec.add_dependency 'ruby-progressbar'
|
51
54
|
|
52
55
|
|
53
56
|
spec.metadata = { "source_code_uri" => "https://git.computational.bio.uni-giessen.de/rmueller/bcf_user_tools" }
|
data/lib/but/cli.rb
CHANGED
@@ -17,6 +17,7 @@ module But
|
|
17
17
|
class How < Thor
|
18
18
|
class_option :measure, :type => :boolean, :default => false
|
19
19
|
class_option :gc, :type => :boolean, :default => true
|
20
|
+
class_option :profile, :aliases => '-p', required: false, desc: 'create a ruby prof profile; Possible values: MEMORY, ALLOCATIONS, WALL_TIME, PROCESS_TIME'
|
20
21
|
|
21
22
|
desc "messy am I?", "How messed up is your home?"
|
22
23
|
def messy(*words)
|
@@ -24,6 +25,10 @@ module But
|
|
24
25
|
measure(options) do
|
25
26
|
say But::HomeKeeper.judge
|
26
27
|
end
|
28
|
+
elsif options[:profile]
|
29
|
+
profile(options) do
|
30
|
+
say But::HomeKeeper.judge
|
31
|
+
end
|
27
32
|
else
|
28
33
|
say But::HomeKeeper.judge
|
29
34
|
end
|
data/lib/but/dev_wrapper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "json"
|
2
2
|
require "benchmark"
|
3
|
+
require "rubygems"
|
4
|
+
require "ruby-prof"
|
3
5
|
|
4
6
|
#inspired by Ruby Performance Optimization: Alexander Dymo
|
5
7
|
def measure(options={}, &block)
|
@@ -31,3 +33,36 @@ def measure(options={}, &block)
|
|
31
33
|
}
|
32
34
|
}.to_json)
|
33
35
|
end
|
36
|
+
|
37
|
+
|
38
|
+
def profile(options={}, &block)
|
39
|
+
measure_mode = options[:profile].upcase
|
40
|
+
RubyProf.measure_mode = RubyProf.const_get(measure_mode)
|
41
|
+
|
42
|
+
case measure_mode
|
43
|
+
when "WALL_TIME"
|
44
|
+
GC.disable
|
45
|
+
when "PROCESS_TIME"
|
46
|
+
GC.disable
|
47
|
+
when "ALLOCATIONS"
|
48
|
+
#GC.enable_stats
|
49
|
+
when "MEMORY"
|
50
|
+
#GC.enable_stats
|
51
|
+
else
|
52
|
+
end
|
53
|
+
|
54
|
+
result = RubyProf.profile do
|
55
|
+
yield
|
56
|
+
end
|
57
|
+
|
58
|
+
printer_g = RubyProf::GraphHtmlPrinter.new(result)
|
59
|
+
printer_f = RubyProf::FlatPrinter.new(result)
|
60
|
+
printer_c = RubyProf::CallTreePrinter.new(result)
|
61
|
+
unless measure_mode == "MEMORY"
|
62
|
+
printer_g.print(File.open(measure_mode + "_graph.html","w"))
|
63
|
+
printer_f.print(File.open(measure_mode + "_flat.txt","w"))
|
64
|
+
end
|
65
|
+
printer_c.print(options)
|
66
|
+
|
67
|
+
puts "Profiles written for #{measure_mode}"
|
68
|
+
end
|
data/lib/but/home_keeper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'tempfile'
|
3
3
|
require 'colorize'
|
4
|
+
require 'ruby-progressbar'
|
4
5
|
|
5
6
|
module But
|
6
7
|
module HomeKeeper
|
8
|
+
BLOCK_SIZE = 1024
|
7
9
|
|
8
10
|
def self.info(options = {})
|
9
11
|
file = ENV['BUTHOMEKEEPER'] || create_disk_usage_file(options)
|
@@ -21,22 +23,68 @@ module But
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
26
|
+
def self.all_eof(files)
|
27
|
+
files.find { |f| !f.eof }.nil?
|
28
|
+
end
|
24
29
|
|
25
30
|
# Q: is $HOME always set?
|
26
31
|
def self.create_disk_usage_file(options = {})
|
27
32
|
tmpfile = ::Tempfile.new("diskusage")
|
28
33
|
dir = options[:dir] || ENV['HOME']
|
29
|
-
::Open3.popen3("du","-d 0", dir) do |stdin, stdout, stderr, wait_thr|
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
total_lines = `ls -d ~/.*/ ~/*/ | wc -l`.to_i
|
36
|
+
#puts total_lines
|
37
|
+
progressbar = ProgressBar.create(title: "inspecting #{dir}", total: total_lines ,
|
38
|
+
:format => "%a %c/%C %b\u{15E7}%i %p%% %t",
|
39
|
+
:progress_mark => ' ',
|
40
|
+
:remainder_mark => "\u{FF65}",
|
41
|
+
)
|
42
|
+
|
43
|
+
::Open3.popen3("du","-d 1", dir) do |stdin, stdout, stderr, wait_thr|
|
44
|
+
# inspired by from https://gist.github.com/chrisn/7450808
|
45
|
+
|
46
|
+
stdin.close_write
|
47
|
+
begin
|
48
|
+
files = [stdout, stderr]
|
49
|
+
until all_eof(files) do
|
50
|
+
ready = IO.select(files)
|
51
|
+
progressbar.refresh
|
52
|
+
|
53
|
+
if ready
|
54
|
+
readable = ready[0]
|
55
|
+
readable.each do |f|
|
56
|
+
fileno = f.fileno
|
57
|
+
|
58
|
+
begin
|
59
|
+
data = f.read_nonblock(BLOCK_SIZE)
|
60
|
+
|
61
|
+
#puts "fileno: #{fileno}, data: #{data.inspect}"
|
62
|
+
progressbar.progress += data.lines.count
|
63
|
+
progressbar.title = "just completed: %s" % data.split(/\s+/).last
|
64
|
+
tmpfile.write(data)
|
65
|
+
rescue EOFError => e
|
66
|
+
#puts "fileno: #{fileno} EOF"
|
67
|
+
files.delete f
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue IOError => e
|
73
|
+
puts "IOError: #{e}"
|
34
74
|
end
|
35
75
|
|
36
|
-
|
76
|
+
|
77
|
+
#if wait_thr.value != 0
|
78
|
+
# STDERR.write "Exitcode: #{wait_thr.value}\n".light_black
|
79
|
+
# STDERR.write stderr.gets(nil).light_black
|
80
|
+
#end
|
81
|
+
|
82
|
+
#tmpfile.write(stdout.gets(nil))
|
37
83
|
end
|
84
|
+
progressbar.finish
|
38
85
|
tmpfile.rewind
|
39
86
|
return tmpfile.path
|
40
87
|
end
|
88
|
+
|
41
89
|
end
|
42
90
|
end
|
data/lib/but/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: but
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raphael Müller
|
@@ -178,6 +178,34 @@ dependencies:
|
|
178
178
|
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: ruby-prof
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: ruby-progressbar
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
181
209
|
description: BCF admins have a hard live. Their user's don't keep their $HOMES and
|
182
210
|
other working places clean. It appears that some users don't know that they use
|
183
211
|
too much space in their home or don't clean used directories on cluster (or other)
|
@@ -229,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
229
257
|
requirements:
|
230
258
|
- - ">="
|
231
259
|
- !ruby/object:Gem::Version
|
232
|
-
version:
|
260
|
+
version: 2.6.0
|
233
261
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
262
|
requirements:
|
235
263
|
- - ">="
|