-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
120 lines (96 loc) · 2.27 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require 'rake/testtask'
desc "Run tests"
Rake::TestTask.new :test do |t|
t.pattern = 'test/*.rb'
t.warning = true
end
task default: :test
#
# METRICS
#
metrics_tasks = []
begin
require 'flog_task'
# we want: flog --all --methods-only lib
# but: FlogTask doesn't support the equivalent of --all; oh well
methods_only = true
FlogTask.new(:flog, 200, ['lib'], nil, methods_only) do |t|
t.verbose = true
end
metrics_tasks << :flog
rescue LoadError
warn 'flog_task unavailable'
end
begin
require 'flay_task'
# we want: flay --liberal lib
# but: FlayTask doesn't support the equivalent of --liberal; oh well
FlayTask.new do |t|
t.dirs = ['lib']
t.verbose = true
end
metrics_tasks << :flay
rescue LoadError
warn 'flay_task unavailable'
end
begin
require 'roodi_task'
RoodiTask.new patterns: ['lib/**/*.rb']
metrics_tasks << :roodi
rescue LoadError
warn 'roodi_task unavailable'
end
desc "Generate code metrics reports"
task :code_metrics => metrics_tasks
#
# PROFILING
#
desc "Show current system load"
task "loadavg" do
puts File.read "/proc/loadavg"
end
# make sure command is run against lib/ on the filesystem, not an installed gem
def lib_sh(cmd)
sh "RUBYLIB=lib #{cmd}"
end
# set up script, args, and rprof_args the way ruby-prof wants them
def rprof_sh(script, args, rprof_args = '')
lib_sh ['ruby-prof', rprof_args, script, '--', args].join(' ')
end
rprof_options = {
min_percent: 2,
printer: :graph,
mode: :process,
sort: :self,
}.inject('') { |memo, (flag,val)| memo + "--#{flag}=#{val} " }
evdump_options = {
count: 9999,
print: 'off',
}.inject('') { |memo, (flag,val)| memo + "--#{flag} #{val} " } + '/dev/zero'
desc "Run ruby-prof on bin/evdump (9999 events)"
task "ruby-prof" => "loadavg" do
puts
rprof_sh 'bin/evdump', evdump_options, rprof_options
end
desc "Run ruby-prof with --exclude-common-cycles"
task "ruby-prof-exclude" => "ruby-prof" do
puts
rprof_sh 'bin/evdump', evdump_options,
"#{rprof_options} --exclude-common-cycles"
end
task "no-prof" do
lib_sh "bin/evdump #{evdump_options}"
end
#
# GEM BUILD / PUBLISH
#
begin
require 'buildar'
Buildar.new do |b|
b.gemspec_file = 'device_input.gemspec'
b.version_file = 'VERSION'
b.use_git = true
end
rescue LoadError
# ok
end