mtracker 0.2.1 → 0.3.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: 90e8063b53163220acd819735d1194e7d8d7e030
4
- data.tar.gz: c530dd1ba1a8bce385c0d83efd298b85a7fc6895
2
+ SHA256:
3
+ metadata.gz: 73943a13acb609f4322b896b560c2e05a0370cf8b4d710c0977ca7f31e68b8a4
4
+ data.tar.gz: 6acee35937485416e6fba60e1e0de2f99185f33763e6e7f63eb6c7b2e34801a5
5
5
  SHA512:
6
- metadata.gz: 96df25185481cb05ac6ac402ed41cb29b4e20e7b855971573f57f1c047ba516278be40391e45ad2324679f4a183e8bbe0e5fd17529062843492e2784b1dfce14
7
- data.tar.gz: 1e416e2f5fcce9d551764c35709fc317fe91d39ca9cf7d0b2efb6d92f229aec0005976bee0e8dcf3c27edad178dfe746e0ddaf034cc915feac8cbcc548f2333a
6
+ metadata.gz: ec58b393903efca3cb3b42595671c3baff6074c04adfd0791d59d7a335c143cda434a21d4f647929368d1cb9d25d57cf19b6faef32a05b6f20351dbd7247b427
7
+ data.tar.gz: c99e921c14d9633c49cbed484495a64095841752a47bdda9c1810fbee0bfe22d3b72d5231b4b9a29eb6c01f39c417124d92e0eb72c872fea8623b3aa52c4ec74
data/lib/mtracker.rb CHANGED
@@ -2,14 +2,51 @@ require 'mtracker/version'
2
2
 
3
3
  # module for tracking time
4
4
  module Mtracker
5
+ attr_accessor :mtracker_log_pid_and_tid
6
+
5
7
  def track(label)
6
8
  start_time = Time.now
7
- put_track_info "[start] #{label}"
9
+ increment_nest_level
10
+
11
+ put_track_info "#{indent}[start#{pid_and_tid}] #{label}"
8
12
  result = yield
9
- put_track_info "[end] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
13
+ put_track_info "#{indent}[end #{pid_and_tid}] #{label} (#{sprintf('%.3f', Time.now - start_time)} sec)"
14
+
15
+ decrement_nest_level
10
16
  result
11
17
  end
12
18
 
19
+ private
20
+
21
+ def indent
22
+ ' ' * nest_level
23
+ end
24
+
25
+ def pid_and_tid
26
+ mtracker_log_pid_and_tid ? " #{nest_level_key}" : ''
27
+ end
28
+
29
+ def nest_level
30
+ @mtracker_nest_levels ||= {}
31
+ @mtracker_nest_levels[nest_level_key] ||= 0
32
+ end
33
+
34
+ def nest_level_key
35
+ process_id = Process.pid
36
+ thread_id = syscall(186)
37
+ "#{process_id}_#{thread_id}"
38
+ end
39
+
40
+ def increment_nest_level
41
+ @mtracker_nest_levels ||= {}
42
+ @mtracker_nest_levels[nest_level_key] = @mtracker_nest_levels[nest_level_key] ? @mtracker_nest_levels[nest_level_key] + 1 : 0
43
+ end
44
+
45
+ def decrement_nest_level
46
+ @mtracker_nest_levels ||= {}
47
+ @mtracker_nest_levels[nest_level_key] = @mtracker_nest_levels[nest_level_key] ? @mtracker_nest_levels[nest_level_key] - 1 : 0
48
+ end
49
+
13
50
  def put_track_info(msg)
14
51
  if respond_to?(:logger)
15
52
  logger.info(msg)
@@ -1,3 +1,3 @@
1
1
  module Mtracker
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  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.0
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-04-21 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: []