mtracker 0.2.1 → 0.3.3

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: 90e8063b53163220acd819735d1194e7d8d7e030
4
- data.tar.gz: c530dd1ba1a8bce385c0d83efd298b85a7fc6895
2
+ SHA256:
3
+ metadata.gz: beef150afdf62af78d7560e92d3a4b370a661d17e9895182f1efa4cf22d031c6
4
+ data.tar.gz: c282b2acca5e650c79b0c177156f02817d846d6ac4bbd3f41b6cbfd3cdc6f2bb
5
5
  SHA512:
6
- metadata.gz: 96df25185481cb05ac6ac402ed41cb29b4e20e7b855971573f57f1c047ba516278be40391e45ad2324679f4a183e8bbe0e5fd17529062843492e2784b1dfce14
7
- data.tar.gz: 1e416e2f5fcce9d551764c35709fc317fe91d39ca9cf7d0b2efb6d92f229aec0005976bee0e8dcf3c27edad178dfe746e0ddaf034cc915feac8cbcc548f2333a
6
+ metadata.gz: cb3f1de3069dfc1acfdcb42890a330a8301173900de4169639e1307ffede9864c18d24a387bad49a3565d575d205700bef327512b1d5a494b90c7895744b37f5
7
+ data.tar.gz: 57cf493ce4fae06dcb82188d46cde18f51eb7fd392672281e61b50082f90a4cd534cc958a5a368f34c89b9ab590e479b120ec39838f04a442c3827931941c8b4
@@ -1,3 +1,3 @@
1
1
  module Mtracker
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.3'
3
3
  end
data/lib/mtracker.rb CHANGED
@@ -2,15 +2,58 @@ require 'mtracker/version'
2
2
 
3
3
  # module for tracking time
4
4
  module Mtracker
5
- def track(label)
5
+ attr_accessor :mtracker_log_pid_and_tid, :mtracker_slack_url
6
+
7
+ def track(label, options = {})
8
+ slack = options[:slack]
9
+
6
10
  start_time = Time.now
7
- put_track_info "[start] #{label}"
11
+ increment_nest_level
12
+
13
+ start_msg = "#{indent}[start#{pid_and_tid}] #{label}"
14
+ put_track_info start_msg, slack
15
+
8
16
  result = yield
9
- put_track_info "[end] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
17
+
18
+ finish_msg = "#{indent}[end #{pid_and_tid}] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
19
+ put_track_info finish_msg, slack
20
+
21
+ decrement_nest_level
10
22
  result
11
23
  end
12
24
 
13
- def put_track_info(msg)
25
+ private
26
+
27
+ def indent
28
+ '| ' * nest_level
29
+ end
30
+
31
+ def pid_and_tid
32
+ mtracker_log_pid_and_tid ? " #{nest_level_key}" : ''
33
+ end
34
+
35
+ def nest_level
36
+ @mtracker_nest_levels ||= {}
37
+ @mtracker_nest_levels[nest_level_key] ||= 0
38
+ end
39
+
40
+ def nest_level_key
41
+ process_id = Process.pid
42
+ thread_id = syscall(186)
43
+ "#{process_id}_#{thread_id}"
44
+ end
45
+
46
+ def increment_nest_level
47
+ @mtracker_nest_levels ||= {}
48
+ @mtracker_nest_levels[nest_level_key] = @mtracker_nest_levels[nest_level_key] ? @mtracker_nest_levels[nest_level_key] + 1 : 0
49
+ end
50
+
51
+ def decrement_nest_level
52
+ @mtracker_nest_levels ||= {}
53
+ @mtracker_nest_levels[nest_level_key] = @mtracker_nest_levels[nest_level_key] ? @mtracker_nest_levels[nest_level_key] - 1 : 0
54
+ end
55
+
56
+ def put_track_info(msg, slack = false)
14
57
  if respond_to?(:logger)
15
58
  logger.info(msg)
16
59
  elsif Rails
@@ -18,5 +61,15 @@ module Mtracker
18
61
  else
19
62
  puts msg
20
63
  end
64
+
65
+ send_to_slack(msg) if slack
66
+ end
67
+
68
+ def send_to_slack(msg)
69
+ return unless mtracker_slack_url
70
+
71
+ uri = URI.parse(mtracker_slack_url)
72
+ data = { text: msg }
73
+ Net::HTTP.post_form(uri, payload: data.to_json)
21
74
  end
22
75
  end
data/mtracker.gemspec CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "bundler", "~> 2.2"
22
22
  spec.add_development_dependency "rake"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Murata
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '2.2'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ homepage: https://github.com/muratayusuke/mtracker
58
58
  licenses:
59
59
  - MIT
60
60
  metadata: {}
61
- post_install_message:
61
+ post_install_message:
62
62
  rdoc_options: []
63
63
  require_paths:
64
64
  - lib
@@ -73,9 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.5.2
78
- signing_key:
76
+ rubygems_version: 3.2.15
77
+ signing_key:
79
78
  specification_version: 4
80
79
  summary: Simple time tracker better than benchmark.
81
80
  test_files: []