get_process_start_time 0.1.1 → 0.1.2
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +14 -2
- data/lib/get_process_start_time/cli.rb +68 -15
- data/lib/get_process_start_time/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab5bf73c6fac856eb2b9ed2abf44c46d98a430e8
|
4
|
+
data.tar.gz: b6b02b5dab02ff52c7e1a03946131bc40dfed296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7bc517a92ab95f76a8d8c5c15e6682d484e6f9143b22233a2a02a17194cca41857c6262b0fc767eb15ee3faf013fe402c83450eb9cc2d74573feb987138c9e3
|
7
|
+
data.tar.gz: 324b4166daa71cd5ddee30bbe5fd387fcb8c9417f596dfec354c1cc70cbb290aea8636145e8df862a452cc3b7df091e08fef3c922a15d9aedc5578c5ff87ee06
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -23,8 +23,20 @@ Or install it yourself as:
|
|
23
23
|
### CLI
|
24
24
|
|
25
25
|
```
|
26
|
-
|
27
|
-
<
|
26
|
+
Usage: get_process_start_time <PID>
|
27
|
+
Or: get_process_start_time test <PID> <COMPARTOR> <SECONDS>
|
28
|
+
|
29
|
+
Get starting time of a process with unix timestamp
|
30
|
+
|
31
|
+
$ get_process_start_time <PID>
|
32
|
+
<unix timestamp>
|
33
|
+
|
34
|
+
Test living duration of a process is less than (or greater than) a given seconds
|
35
|
+
|
36
|
+
$ get_process_start_time test_duration <PID> <COMPARTOR> <SECONDS>
|
37
|
+
$ echo $? # 0 or 1
|
38
|
+
|
39
|
+
COMPARTOR: -lt (less than) or -gt (greater than)
|
28
40
|
```
|
29
41
|
|
30
42
|
### Library
|
@@ -4,35 +4,88 @@ require 'optparse'
|
|
4
4
|
class GetProcessStartTime
|
5
5
|
class CLI
|
6
6
|
def parse_options(argv = ARGV)
|
7
|
-
op = OptionParser.new
|
8
|
-
|
9
7
|
self.class.module_eval do
|
10
8
|
define_method(:usage) do |msg = nil|
|
11
|
-
puts
|
12
|
-
puts "
|
9
|
+
puts "Usage: get_process_start_time <PID>"
|
10
|
+
puts "Or: get_process_start_time test <PID> <COMPARTOR> <SECONDS>"
|
11
|
+
puts ""
|
12
|
+
puts "Get starting time of a process with unix timestamp"
|
13
|
+
puts ""
|
14
|
+
puts " $ get_process_start_time <PID>"
|
15
|
+
puts " <unix timestamp>"
|
16
|
+
puts ""
|
17
|
+
puts "Test living duration of a process is less than (or greater than) a given seconds"
|
18
|
+
puts ""
|
19
|
+
puts " $ get_process_start_time test_duration <PID> <COMPARTOR> <SECONDS>"
|
20
|
+
puts " $ echo $? # 0 or 1"
|
21
|
+
puts ""
|
22
|
+
puts "COMPARTOR: -lt (less than) or -gt (greater than)"
|
23
|
+
if msg
|
24
|
+
puts ""
|
25
|
+
puts "ERROR: #{msg}"
|
26
|
+
end
|
13
27
|
exit 1
|
14
28
|
end
|
15
29
|
end
|
16
30
|
|
17
|
-
opts = {}
|
18
|
-
op.banner += ' PID'
|
19
31
|
begin
|
20
|
-
|
21
|
-
|
32
|
+
case argv[0]
|
33
|
+
when '-h', '--help'
|
34
|
+
usage
|
35
|
+
when 'test_duration'
|
36
|
+
if argv.size < 4
|
37
|
+
usage 'number of arguments must be 4'
|
38
|
+
end
|
39
|
+
@subcommand = :test_duration
|
40
|
+
@pid = Integer(argv[1])
|
41
|
+
@comparator = validate_comparator!(argv[2])
|
42
|
+
@seconds = Float(argv[3])
|
43
|
+
else
|
44
|
+
if argv.size < 1
|
45
|
+
usage 'number of arguments must be at least 1'
|
46
|
+
end
|
47
|
+
@subcommand = :show
|
48
|
+
@pid = Integer(argv[0])
|
49
|
+
end
|
50
|
+
rescue => e
|
22
51
|
usage e.message
|
23
52
|
end
|
53
|
+
end
|
24
54
|
|
25
|
-
|
26
|
-
|
55
|
+
def run
|
56
|
+
parse_options
|
57
|
+
case @subcommand
|
58
|
+
when :show
|
59
|
+
show
|
60
|
+
when :test_duration
|
61
|
+
test_duration
|
62
|
+
else
|
63
|
+
assert(false)
|
27
64
|
end
|
65
|
+
end
|
28
66
|
|
29
|
-
|
67
|
+
def show
|
68
|
+
puts GetProcessStartTime.start_time(@pid).to_f
|
30
69
|
end
|
31
70
|
|
32
|
-
def
|
33
|
-
|
34
|
-
|
35
|
-
|
71
|
+
def test_duration
|
72
|
+
start_time = GetProcessStartTime.start_time(@pid).to_f
|
73
|
+
living_duration = Time.now - start_time
|
74
|
+
case @comparator
|
75
|
+
when '-lt'
|
76
|
+
exit 0 if living_duration.to_f < @seconds
|
77
|
+
when '-gt'
|
78
|
+
exit 0 if living_duration.to_f > @seconds
|
79
|
+
end
|
80
|
+
$stderr.puts "test_duration failed (living duration:#{living_duration.to_f} sec)"
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_comparator!(comparator)
|
85
|
+
unless %w[-lt -gt].include?(comparator)
|
86
|
+
raise "COMPARATOR must be -lt (less than) or -gt (greater than): #{comparator}"
|
87
|
+
end
|
88
|
+
comparator
|
36
89
|
end
|
37
90
|
end
|
38
91
|
end
|