stackprof-run 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2c1842303afdf634f199e95a98780d6ca35839c3
4
- data.tar.gz: a2ed797d123ad3aa575a74c6894f31d2fb505ada
2
+ SHA256:
3
+ metadata.gz: 143390d783d006f15b7393c89ebae02fd7acbcd21553e917175e96ece2983e2c
4
+ data.tar.gz: 8636d68289c4fbf75063f50c36a8f8fd91f4e27b30dc184b48c644787cec4dec
5
5
  SHA512:
6
- metadata.gz: a4e707b5b17158becbd13aec31cd47e35ee8e793b1d982ac9029d300d189c87e296a59d90422e826d13cd8c33afb5a8f940c5a7380c88ddbb5ef3c21ce44a3fb
7
- data.tar.gz: 4accf086e95249cdcc044de4cf3b0d9510aeedbc92cc91c97854610437ebf04ca37ddffa104dbfebfcc99617a62db287921987d7684e9c3a51b02669495d7cfe
6
+ metadata.gz: 6d185403afaf176507dcf47100a52ff794edf7d2c0b9c19b96b09fe73d39c6130d942adf9c76eb9e9aaa5291f14f26debf468c0619adb9a4015f9536c4b037a6
7
+ data.tar.gz: 44d6424601a697ffeb6f0a1b03a52ccc438a7c835cf9bb323fb6f5ed727c55f3ff6018dc33232503e529d81e03737b425b53969771974d707d11daa7e20e74b6
data/exe/stackprof-run CHANGED
@@ -3,39 +3,71 @@
3
3
  require 'optparse'
4
4
  require 'stackprof'
5
5
 
6
- opt = OptionParser.new
7
-
8
- mode = ENV['STACKPROF_MODE']&.to_sym || :cpu
9
- out = ENV['STACKPROF_OUT'] || 'stackprof-out'
10
- interval = nil
11
- aggregate = true
12
- raw = false
13
-
14
- opt.banner = 'Usage: stackprof-run [options] command [command options]'
15
- opt.on('-m MODE', '--mode=MODE', ':cpu(default), :wall, :object'){|v| mode = v.to_sym}
16
- opt.on('-o FILE', '--out=FILE', 'Output file name. (default: stackprof-out)'){|v| out = v}
17
- opt.on('-i INTERVAL', '--interval=INTERVAL'){|v| interval = v.to_i}
18
- opt.on('-no-aggregate'){|v| aggregate = false}
19
- opt.on('-r', '--raw'){|v| raw = true}
20
-
21
- opt.order!(ARGV)
22
-
23
- cmd = ARGV.shift
24
- unless cmd
25
- puts opt.help
26
- exit 1
6
+ def main
7
+ opt = OptionParser.new
8
+
9
+ params = {
10
+ mode: ENV['STACKPROF_MODE']&.to_sym || :cpu,
11
+ out: ENV['STACKPROF_OUT'] || 'stackprof-out'
12
+ }
13
+
14
+ opt.banner = 'Usage: stackprof-run [options] command [command options]'
15
+ opt.on('-m MODE', '--mode=MODE', ':cpu(default), :wall, :object', &:to_sym)
16
+ opt.on('-o FILE', '--out=FILE', 'Output file name. (default: stackprof-out)')
17
+ opt.on('-i INTERVAL', '--interval=INTERVAL', &:to_i)
18
+ opt.on('-no-aggregate')
19
+ opt.on('-r', '--raw')
20
+ opt.on('-e command')
21
+
22
+ opt.order!(ARGV, into: params)
23
+
24
+ if params[:e]
25
+ exec_code params
26
+ else
27
+ exec_command opt, params
28
+ end
27
29
  end
28
30
 
29
- path = `which #{cmd}`.chomp
31
+ def exec_command(opt, params)
32
+ cmd = ARGV.shift
33
+ unless cmd
34
+ puts opt.help
35
+ exit 1
36
+ end
37
+
38
+ path =
39
+ if File.exist?(cmd)
40
+ cmd
41
+ else
42
+ `which #{cmd}`.chomp
43
+ end
30
44
 
31
- $PROGRAM_NAME = cmd
45
+ $PROGRAM_NAME = cmd
32
46
 
33
- ex = nil
34
- StackProf.run(mode: mode, out: out, interval: interval, aggregate: aggregate, raw: raw) do
35
- begin
47
+ exec(params) do
36
48
  load path
37
- rescue Exception => ex
38
49
  end
39
50
  end
40
51
 
41
- raise ex if ex
52
+ def exec_code(params)
53
+ exec(params) do
54
+ eval params[:e]
55
+ end
56
+ end
57
+
58
+ def exec(params)
59
+ opt = params.slice(:mode, :out, :interval, :raw).tap do |o|
60
+ o[:aggregate] = !!params[:'no-aggregate']
61
+ end
62
+ ex = nil
63
+ StackProf.run(opt) do
64
+ begin
65
+ yield
66
+ rescue Exception => ex
67
+ end
68
+ end
69
+
70
+ raise ex if ex
71
+ end
72
+
73
+ main
@@ -1,5 +1,5 @@
1
1
  module Stackprof
2
2
  module Run
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
  spec.licenses = ['CC0-1.0']
23
23
 
24
- spec.required_ruby_version = '>= 2.3.0'
24
+ spec.required_ruby_version = '>= 2.4.0'
25
25
 
26
26
  spec.add_runtime_dependency 'stackprof', ' >= 0.2.10'
27
27
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackprof-run
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Kuwabara
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stackprof
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="
85
85
  - !ruby/object:Gem::Version
86
- version: 2.3.0
86
+ version: 2.4.0
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.6.10
94
+ rubygems_version: 2.7.7
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Run a ruby script with stackprof.