schwad_performance_logger 0.4.1 → 0.5.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
2
  SHA256:
3
- metadata.gz: c8275d515aa97c0cf9367565de433698c4368bc5d3c7becb74511d676c7d27c7
4
- data.tar.gz: a2a31599f3f76e3c2a788731ded0aebc61d53b15cb6338486a7943050812e36e
3
+ metadata.gz: 1cd2043d45f57759843573942457ed5c635fb32d911d0119178c798ca162ece9
4
+ data.tar.gz: 79f240f10f256b9b04513385486b24e26da6d352dee79587ea8802ef41b517a1
5
5
  SHA512:
6
- metadata.gz: 90028de7fc8762018a7b44fdac55316c8b9f3782f4cd52ab7eaa7fbc19a0cad19fa27a63b38901d7b3703e3849d7f94cd02d35a5ca68d270b2e1ec76b5bf25a6
7
- data.tar.gz: d2675d9a2a9afe09b39f540483df8d0b9b723d0f339bb163fd0ea14c9a1740455aaf8e69092d3af7d8de778c181923089aa5b548784b6ea0c096b3bc05003b7b
6
+ metadata.gz: c2a1badb587b6c532a170a80fccef850f085ba38cfc6e9a15286eee90b97ee9f9778efd95ad166bf7978acbd4f0ba08040b2635e397749f581857c55944a7f62
7
+ data.tar.gz: 7df45a0cebe6b180a4822c8046803d99219d09a99a6841fbb9517f2204c24d955767063bf787e76f3b43406528f75deec6838bd9a1a1204ef88997ed827dbde7
data/CHANGELOG.md ADDED
File without changes
data/Gemfile.lock CHANGED
@@ -1,37 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- schwad_performance_logger (0.2.0)
4
+ schwad_performance_logger (0.5.0)
5
+ benchmark-ips
5
6
  get_process_mem
7
+ memory_profiler
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
10
- diff-lcs (1.3)
11
- get_process_mem (0.2.3)
12
- rake (10.5.0)
13
- rspec (3.8.0)
14
- rspec-core (~> 3.8.0)
15
- rspec-expectations (~> 3.8.0)
16
- rspec-mocks (~> 3.8.0)
17
- rspec-core (3.8.0)
18
- rspec-support (~> 3.8.0)
19
- rspec-expectations (3.8.2)
12
+ benchmark-ips (2.13.0)
13
+ diff-lcs (1.5.1)
14
+ ffi (1.17.0)
15
+ ffi (1.17.0-aarch64-linux-gnu)
16
+ ffi (1.17.0-aarch64-linux-musl)
17
+ ffi (1.17.0-arm-linux-gnu)
18
+ ffi (1.17.0-arm-linux-musl)
19
+ ffi (1.17.0-arm64-darwin)
20
+ ffi (1.17.0-x86-linux-gnu)
21
+ ffi (1.17.0-x86-linux-musl)
22
+ ffi (1.17.0-x86_64-darwin)
23
+ ffi (1.17.0-x86_64-linux-gnu)
24
+ ffi (1.17.0-x86_64-linux-musl)
25
+ get_process_mem (0.2.7)
26
+ ffi (~> 1.0)
27
+ memory_profiler (1.0.2)
28
+ rake (13.2.1)
29
+ rspec (3.13.0)
30
+ rspec-core (~> 3.13.0)
31
+ rspec-expectations (~> 3.13.0)
32
+ rspec-mocks (~> 3.13.0)
33
+ rspec-core (3.13.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-expectations (3.13.1)
20
36
  diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.8.0)
22
- rspec-mocks (3.8.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-mocks (3.13.1)
23
39
  diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.8.0)
25
- rspec-support (3.8.0)
40
+ rspec-support (~> 3.13.0)
41
+ rspec-support (3.13.1)
26
42
 
27
43
  PLATFORMS
44
+ aarch64-linux-gnu
45
+ aarch64-linux-musl
46
+ arm-linux-gnu
47
+ arm-linux-musl
48
+ arm64-darwin
28
49
  ruby
50
+ x86-linux-gnu
51
+ x86-linux-musl
52
+ x86_64-darwin
53
+ x86_64-linux-gnu
54
+ x86_64-linux-musl
29
55
 
30
56
  DEPENDENCIES
31
- bundler (~> 1.16)
32
- rake (~> 10.0)
57
+ rake (~> 13.0)
33
58
  rspec (~> 3.0)
34
59
  schwad_performance_logger!
35
60
 
36
61
  BUNDLED WITH
37
- 1.16.2
62
+ 2.5.11
@@ -1,27 +1,16 @@
1
- ##
2
- # Logs performance during life of the object. Defaults to a trifecta of `puts`
3
- # output as well as logging to CSV (in the root folder) and
4
- # `log/schwad_performance_logger` for traditional info-level logging. It also gives
5
- # timing and memory usage info. Options include disabling extra logging,
6
- # including a 'sleep' parameter to have the application pause at each output
7
- # (so your puts info is not drowned). This does not impact the time output
8
- #
9
- # It also puts out delta memory and time so you can see 'between-log' spikes.
10
- #
11
- # This is stored in the system as 'second_delta'
12
- #
13
- class PLogger
1
+ require 'logger'
2
+ require 'csv'
3
+ require 'get_process_mem'
14
4
 
5
+ class PLogger
15
6
  attr_accessor :initial_memory, :initial_time, :current_memory, :last_memory, :current_time, :last_time, :delta_memory, :second_delta_memory, :delta_time, :second_delta_time, :sleep_amount, :sleep_adjuster, :logger
16
-
17
7
  attr_reader :options
18
8
 
19
- def initialize( options = {} )
20
- system('mkdir log')
21
- system('mkdir log/schwad_performance_logger')
9
+ def initialize(options = {})
10
+ system('mkdir -p log/schwad_performance_logger')
22
11
  filename = "./log/schwad_performance_logger/performance-#{Time.now.strftime("%e-%m_%l:%M%p")}.log"
23
12
  File.write(filename, "")
24
- another_empty_csv_row
13
+ initialize_csv
25
14
  @logger = Logger.new(filename)
26
15
  @options = options
27
16
  @sleep_amount = options[:pause].to_i
@@ -33,33 +22,50 @@ class PLogger
33
22
  @current_time = @initial_time
34
23
  @last_time = @initial_time
35
24
  @last_memory = @initial_memory
36
- @sleep_adjuster = -@sleep_amount #This is to remove the sleeps for performance checking.
25
+ @sleep_adjuster = -@sleep_amount # This is to remove the sleeps for performance checking.
37
26
  log_performance('initialization')
38
27
  end
39
28
 
40
- def log_performance(memo=nil)
41
- update_checks
42
- puts_performance(memo) unless @options[:puts] == false
43
- logger_performance(memo) unless @options[:log] == false
44
- csv_performance(memo) unless @options[:csv] == false
29
+ def log_performance(memo = nil)
30
+ if block_given?
31
+ update_checks
32
+ yield
33
+ update_checks
34
+ puts_performance("After: #{memo}", gblock: true) unless @options[:puts] == false
35
+ logger_performance("After: #{memo}") unless @options[:log] == false
36
+ csv_performance("After: #{memo}") unless @options[:csv] == false
37
+ else
38
+ update_checks
39
+ puts_performance(memo) unless @options[:puts] == false
40
+ logger_performance(memo) unless @options[:log] == false
41
+ csv_performance(memo) unless @options[:csv] == false
42
+ end
45
43
  sleep @sleep_amount
46
44
  end
45
+ alias :log :log_performance
46
+ alias :lp :log_performance
47
47
 
48
48
  private
49
49
 
50
- def puts_performance(memo)
51
- puts '*' * 300
52
- puts "Starting #{memo}. Current memory: #{@current_memory}(Mb), difference of #{@delta_memory} (mb) since beginning and difference of #{@second_delta_memory} since last log. time passed: #{@delta_time} seconds, time since last run: #{@second_delta_time}"
53
- puts '*' * 300
50
+ def puts_performance(memo, gblock: false)
51
+ separator = '*' * 80
52
+ puts "\e[34m#{separator}\e[0m"
53
+ puts "\e[32m#{memo}\e[0m"
54
+ if gblock
55
+ puts format_output_block
56
+ else
57
+ puts format_output
58
+ end
59
+ puts "\e[34m#{separator}\e[0m"
54
60
  end
55
61
 
56
62
  def logger_performance(memo)
57
- @logger.log(1, "#{options[:full_memo]}\n----------------------\n\n#{memo}: \n\n Current Memory: #{@current_memory} \n\n Memory Since Start: #{@delta_memory}\n\n Memory Since Last Run: #{@second_delta_memory}\n\n Time Passed: #{@delta_time} \n\n Time Since Last Run: #{@second_delta_time}\n--------------------\n\n ")
63
+ @logger.info("#{options[:full_memo]}\n----------------------\n\n#{memo}:\n\n#{format_output}\n--------------------\n\n")
58
64
  end
59
65
 
60
- def another_empty_csv_row
61
- CSV.open("schwad_performance_logger_measurements.csv", "ab") do |csv|
62
- csv << []
66
+ def initialize_csv
67
+ CSV.open("schwad_performance_logger_measurements.csv", "wb") do |csv|
68
+ csv << ["Full Memo", "Memo", "Current Memory (Mb)", "Memory Since Start (Mb)", "Memory Since Last Log (Mb)", "Time Passed (s)", "Time Since Last Run (s)"]
63
69
  end
64
70
  end
65
71
 
@@ -80,4 +86,24 @@ class PLogger
80
86
  @second_delta_time = @current_time - @last_time
81
87
  @delta_time = (@current_time - @initial_time) - @sleep_adjuster
82
88
  end
89
+
90
+ def format_output_block
91
+ <<~OUTPUT
92
+ \e[33mCurrent memory:\e[0m #{@current_memory} Mb
93
+ \e[33mDifference since start:\e[0m #{@delta_memory} Mb
94
+ \e[33mMemory used within block:\e[0m #{@second_delta_memory} Mb
95
+ \e[33mTime passed:\e[0m #{@delta_time * 1000} milliseconds
96
+ \e[33mTime executing block:\e[0m #{@second_delta_time * 1000} milliseconds
97
+ OUTPUT
98
+ end
99
+
100
+ def format_output
101
+ <<~OUTPUT
102
+ \e[33mCurrent memory:\e[0m #{@current_memory} Mb
103
+ \e[33mDifference since start:\e[0m #{@delta_memory} Mb
104
+ \e[33mDifference since last log:\e[0m #{@second_delta_memory} Mb
105
+ \e[33mTime passed:\e[0m #{@delta_time * 1000} milliseconds
106
+ \e[33mTime since last run:\e[0m #{@second_delta_time * 1000} milliseconds
107
+ OUTPUT
108
+ end
83
109
  end
@@ -1,3 +1,3 @@
1
1
  module SchwadPerformanceLogger
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "benchmark-ips"
27
27
  spec.add_dependency "memory_profiler"
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.16"
30
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", "~> 13.0"
31
30
  spec.add_development_dependency "rspec", "~> 3.0"
32
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schwad_performance_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Schwaderer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-12 00:00:00.000000000 Z
11
+ date: 2024-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: get_process_mem
@@ -52,34 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.16'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.16'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: '10.0'
61
+ version: '13.0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: '10.0'
68
+ version: '13.0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +80,7 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '3.0'
97
- description:
83
+ description:
98
84
  email:
99
85
  - nicholas.schwaderer@gmail.com
100
86
  executables: []
@@ -104,6 +90,7 @@ files:
104
90
  - ".gitignore"
105
91
  - ".rspec"
106
92
  - ".travis.yml"
93
+ - CHANGELOG.md
107
94
  - CODE_OF_CONDUCT.md
108
95
  - Gemfile
109
96
  - Gemfile.lock
@@ -120,7 +107,7 @@ homepage: https://github.com/Schwad/schwad_performance_logger
120
107
  licenses:
121
108
  - MIT
122
109
  metadata: {}
123
- post_install_message:
110
+ post_install_message:
124
111
  rdoc_options: []
125
112
  require_paths:
126
113
  - lib
@@ -135,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
122
  - !ruby/object:Gem::Version
136
123
  version: '0'
137
124
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.7.8
140
- signing_key:
125
+ rubygems_version: 3.4.1
126
+ signing_key:
141
127
  specification_version: 4
142
128
  summary: Track your memory and time performance in console, csv and/or logs.
143
129
  test_files: []