howlong 0.0.1
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +16 -0
- data/bin/howlong +10 -0
- data/howlong.gemspec +24 -0
- data/lib/howlong.rb +66 -0
- data/lib/howlong/version.rb +3 -0
- metadata +98 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0758ed1eaa5aa03c8e55ea63085ac9c943491e71
|
|
4
|
+
data.tar.gz: 80869a140b7317ad14791a4e991c764d691e9bc1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d0755b4f7b3472f804ad3c9c8ec32bf9dc74420e8475fb8f4b6fd0ae7bfcf782fbc8b6658e976e561ce7cbbed4bb3856a89ff75da99fea40c78a25f1e55c35aa
|
|
7
|
+
data.tar.gz: c585487b2d250dcc205a0679e4e98e2010dcb9b7ccd63eaf359572c5077c44c745786aacd6929391f21d59ce5e5c50feb18610427937260e83057294a74ae398
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014-2015 Fernando Briano
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# How long
|
|
2
|
+
|
|
3
|
+
Ruby script to search for a running process and tell you how long it's been running:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
$ howlong emacs
|
|
7
|
+
Process /usr/bin/emacs24 has been active for 2 days, 2 hours, 12 minutes and 37 seconds
|
|
8
|
+
$ howlong iceweasel
|
|
9
|
+
Process iceweasel has been active for 13 hours, 58 minutes and 21 seconds
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
With IRB:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ rake console
|
|
17
|
+
2.1.2 :001 > Howlong.run "emacs"
|
|
18
|
+
Process emacs has been active for 33 minutes and 25 seconds
|
|
19
|
+
=> nil
|
|
20
|
+
2.1.2 :002 >
|
|
21
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require 'rake/testtask'
|
|
3
|
+
|
|
4
|
+
Rake::TestTask.new("test") do |t|
|
|
5
|
+
t.pattern = "test/**/*_test.rb"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
task :console do
|
|
9
|
+
require 'irb'
|
|
10
|
+
require 'irb/completion'
|
|
11
|
+
require 'howlong'
|
|
12
|
+
ARGV.clear
|
|
13
|
+
IRB.start
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
task :default => 'test'
|
data/bin/howlong
ADDED
data/howlong.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'howlong/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "howlong"
|
|
8
|
+
spec.version = Howlong::VERSION
|
|
9
|
+
spec.authors = ["Fernando Briano"]
|
|
10
|
+
spec.email = ["fernando@picandocodigo.net"]
|
|
11
|
+
spec.summary = %q{ Search for a process and display how long it's been running on your system in a friendly way}
|
|
12
|
+
spec.description = %q{ A simple gem which allows you to see how long a process has been running on your system in a friendly way}
|
|
13
|
+
spec.homepage = "https://github.com/picandocodigo/howlong"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
|
23
|
+
spec.add_development_dependency "byebug"
|
|
24
|
+
end
|
data/lib/howlong.rb
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require "howlong/version"
|
|
2
|
+
require 'date'
|
|
3
|
+
|
|
4
|
+
module Howlong
|
|
5
|
+
def self.find_processes(search)
|
|
6
|
+
processes = `ps -eo lstart,args | grep #{search}`.split(/\n/)
|
|
7
|
+
names = []
|
|
8
|
+
processes.each do |p|
|
|
9
|
+
process = p.match(/\S+#{search}/)
|
|
10
|
+
# Make sure the first executable contains the search string, so we
|
|
11
|
+
# won't catch processes such as grep `parameter` or this script:
|
|
12
|
+
if process
|
|
13
|
+
time = elapsed_time(p)
|
|
14
|
+
names << [process[0], time]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
names
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.show(process, delayed)
|
|
21
|
+
unless delayed == nil
|
|
22
|
+
print = "Process #{process} has been active for "
|
|
23
|
+
if delayed[:days] > 0
|
|
24
|
+
print += "#{delayed[:days]} days, #{(delayed[:seconds].to_int / 86_400) % 24} hours, #{delayed[:minutes] % 60} minutes "
|
|
25
|
+
elsif delayed[:hours] > 0
|
|
26
|
+
print += "#{delayed[:hours]} hours, #{delayed[:minutes] % 60} minutes "
|
|
27
|
+
else
|
|
28
|
+
print += "#{delayed[:minutes]} minutes "
|
|
29
|
+
end
|
|
30
|
+
puts print + "and #{delayed[:seconds] % delayed[:minutes]} seconds"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.run(process)
|
|
35
|
+
processes = find_processes(process)
|
|
36
|
+
processes.each do |p|
|
|
37
|
+
show(p[0], p[1])
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
def self.elapsed_time(process)
|
|
44
|
+
p = process.split(/\s/)[6]
|
|
45
|
+
# We need the current offset so we can make time operations in the
|
|
46
|
+
# same timezone, yey timezones!
|
|
47
|
+
offset = Time.now.gmt_offset / 3600
|
|
48
|
+
# Get the date from ps in the "Day Mon %m hh:mm:ss yyyy" format,
|
|
49
|
+
# substract offset and pass it to time
|
|
50
|
+
start = (DateTime.parse(process.match(/[a-zA-Z\s0-9:]+[0-9]{4}/)[0]) - (offset / 24.0)).to_time
|
|
51
|
+
length = Time.now - start
|
|
52
|
+
|
|
53
|
+
seconds = length.to_int
|
|
54
|
+
minutes = seconds / 60
|
|
55
|
+
hours = seconds / 3_600
|
|
56
|
+
days = seconds / 86_400
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
seconds: length.to_int,
|
|
60
|
+
minutes: minutes,
|
|
61
|
+
hours: hours,
|
|
62
|
+
days: days
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: howlong
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Fernando Briano
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-02-10 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.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
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.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: byebug
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: " A simple gem which allows you to see how long a process has been running
|
|
56
|
+
on your system in a friendly way"
|
|
57
|
+
email:
|
|
58
|
+
- fernando@picandocodigo.net
|
|
59
|
+
executables:
|
|
60
|
+
- howlong
|
|
61
|
+
extensions: []
|
|
62
|
+
extra_rdoc_files: []
|
|
63
|
+
files:
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- Gemfile
|
|
66
|
+
- LICENSE.txt
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- bin/howlong
|
|
70
|
+
- howlong.gemspec
|
|
71
|
+
- lib/howlong.rb
|
|
72
|
+
- lib/howlong/version.rb
|
|
73
|
+
homepage: https://github.com/picandocodigo/howlong
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata: {}
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 2.4.5
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Search for a process and display how long it's been running on your system
|
|
97
|
+
in a friendly way
|
|
98
|
+
test_files: []
|