timify 0.0.1 → 0.0.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/README.md +181 -0
  4. data/lib/timify.rb +48 -39
  5. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adc306de79305613ee050cea9d797ee57253ee39
4
- data.tar.gz: 838de7697e2690ff71e630e9d45b8a73257b5d6b
3
+ metadata.gz: 87e3f8e1a0aeef9369b178a6b1d7a9981df9c3dc
4
+ data.tar.gz: b10790ad239464397fa7c2d817fdfd07b8b8b6bb
5
5
  SHA512:
6
- metadata.gz: 75ffacabee4a87ec49dd97845ac15333541a10ef5d2d9c776cb9e8b43cc48caf84ec9ad019efe0337a98e15c2fecdcedd54d4378f81102912902104352ad4321
7
- data.tar.gz: aa34ac09d253c2047e289b59b24fbbd786f4573eb1d4b4243b2fed6ba65b1bbc449c7b2353a0da01b9d631747349f1bd68a7e3682b71a1aaf385bf480af145a8
6
+ metadata.gz: 80742ca97d2174ad3645fc2b267b24e2cbac846a9f6ce159ceab48e35cde71a285c43a485ea89f575d50002451cf3575cbc3bd704b0cfb1e81cf65fd14bc206b
7
+ data.tar.gz: ff925acdae4d2d6fb6912adfd378099b0e1fca3b7840c3c1a96a8dd1f5b70b0840585f12f4377bde6d68e6908ac1897e5c83f084a73a8ca42f5ea5b2a13dc4c7
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Mario Ruiz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,181 @@
1
+ # Timify
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/timify.svg)](https://rubygems.org/gems/timify)
4
+
5
+ Ruby gem to calculate the time running from one location to another inside your code and report summaries
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'timify'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install timify
22
+
23
+ ## Usage
24
+
25
+ ### initialize
26
+ You need to supply a name for your Timify instance.
27
+ You can have all the Timify instances you want at the same time.
28
+ ```ruby
29
+ t = Timify.new :create_user
30
+ t.show = false
31
+ t.min_time_to_show = 0.5
32
+ ```
33
+ min_time_to_show: minimum time to show the elapsed time when calling 'add' method
34
+
35
+ show: print out results on screen
36
+
37
+ you can supply those parameters also:
38
+
39
+ ```ruby
40
+ t = Timify.new :create_user, show: true, min_time_to_show: 0.3
41
+ ```
42
+
43
+ The scopes of the instances can be even global so you can measure the elapsed times between different classes, methods... on your code.
44
+
45
+ ### add
46
+
47
+ Adds a new point to count the time elapsed. It will count from the last 'add' call or Timify creation in case of the first 'add'.
48
+
49
+ You can supply a label that will summarize all the ones with the same label
50
+
51
+ The output of this method will be the time elapsed in seconds (float).
52
+
53
+ Examples:
54
+
55
+ ```ruby
56
+ t=Timify.new :example
57
+ t.add; run_sqls; t.add :database
58
+ t.add
59
+ #some processes
60
+ t.add
61
+ #some processes
62
+ send_email_alert if t.add > 0.2
63
+ #some processes
64
+ do_log(t.totals[:message]) if t.add > 0.5
65
+ ```
66
+
67
+ ### totals
68
+
69
+ Returns all data for this instance
70
+
71
+ In case json parameter supplied as true, the output will be in json format instead of a hash.
72
+
73
+ The output hash contains:
74
+
75
+ name: (String) name given for this instance'
76
+
77
+ total_time: (float) total elapsed time from initialization to last 'add' call
78
+
79
+ started: (Time)
80
+
81
+ finished: (Time)
82
+
83
+ message: (String) a printable friendly message giving all information
84
+
85
+ locations, labels, ranges: (Hash) the resultant hash contains:
86
+
87
+ secs: (float) number of seconds
88
+
89
+ percent: (integer) percentage in reference to the total time
90
+
91
+ count: (integer) number of times
92
+
93
+ locations: (Hash) All summary data by location where was called
94
+
95
+ labels: (Hash) All summary data by label given on 'add' method
96
+
97
+ ranges: (Hash) All summary data by ranges where was called, from last 'add' call to current 'add' call
98
+
99
+
100
+ Example of output:
101
+ ```ruby
102
+ { :name=>:add_customer_wrong,
103
+ :total_time=>4.461446,
104
+ :started=>2017-11-06 16:10:53 +0000,
105
+ :finished=>2017-11-06 16:10:57 +0000,
106
+ :locations=>{
107
+ "/add_customer.rb:509"=>{:secs=>0.0, :percent=>0, :count=>1},
108
+ "/add_customer.rb:529"=>{:secs=>0.008001, :percent=>0, :count=>1},
109
+ "/add_customer.rb:532"=>{:secs=>0.212021, :percent=>5, :count=>1},
110
+ "/add_customer.rb:569"=>{:secs=>0.006001, :percent=>0, :count=>1},
111
+ "/add_customer.rb:581"=>{:secs=>0.446045, :percent=>10, :count=>1},
112
+ "/add_customer.rb:583"=>{:secs=>3.789378, :percent=>85, :count=>1},
113
+ "/add_customer.rb:585"=>{:secs=>0.0, :percent=>0, :count=>1},
114
+ "/add_customer.rb:587"=>{:secs=>0.0, :percent=>0, :count=>1},
115
+ "/add_customer.rb:595"=>{:secs=>0.0, :percent=>0, :count=>1},
116
+ "/add_customer.rb:603"=>{:secs=>0.0, :percent=>0, :count=>1},
117
+ "/add_customer.rb:612"=>{:secs=>0.0, :percent=>0, :count=>1},
118
+ "/add_customer.rb:617"=>{:secs=>0.0, :percent=>0, :count=>1}
119
+ },
120
+ :labels=>{
121
+ :database_access=>{:secs=>4,447444, :percent=>99, :count=>3},
122
+ :checkouts=>{:secs=>0.0, :percent=>0, :count=>2},
123
+ },
124
+ :ranges=>{
125
+ "/add_customer.rb:509 - /add_customer.rb:529"=>{:secs=>0.008001, :percent=>0, :count=>1},
126
+ "/add_customer.rb:529 - /add_customer.rb:532"=>{:secs=>0.212021, :percent=>5, :count=>1},
127
+ "/add_customer.rb:532 - /add_customer.rb:569"=>{:secs=>0.006001, :percent=>0, :count=>1},
128
+ "/add_customer.rb:569 - /add_customer.rb:581"=>{:secs=>0.446045, :percent=>10, :count=>1},
129
+ "/add_customer.rb:581 - /add_customer.rb:583"=>{:secs=>3.789378, :percent=>85, :count=>1},
130
+ "/add_customer.rb:583 - /add_customer.rb:585"=>{:secs=>0.0, :percent=>0, :count=>1},
131
+ "/add_customer.rb:585 - /add_customer.rb:587"=>{:secs=>0.0, :percent=>0, :count=>1},
132
+ "/add_customer.rb:587 - /add_customer.rb:595"=>{:secs=>0.0, :percent=>0, :count=>1},
133
+ "/add_customer.rb:595 - /add_customer.rb:603"=>{:secs=>0.0, :percent=>0, :count=>1},
134
+ "/add_customer.rb:603 - /add_customer.rb:612"=>{:secs=>0.0, :percent=>0, :count=>1},
135
+ "/add_customer.rb:612 - /add_customer.rb:617"=>{:secs=>0.0, :percent=>0, :count=>1}
136
+ },
137
+ :message=>"
138
+
139
+ Total time <add_customer_wrong>:4.46
140
+ Total time by location:
141
+ /add_customer.rb:509: 0.0 (0%) #1
142
+ /add_customer.rb:529: 0.01 (0%) #1
143
+ /add_customer.rb:532: 0.21 (5%) #1
144
+ /add_customer.rb:569: 0.01 (0%) #1
145
+ /add_customer.rb:581: 0.45 (10%) #1
146
+ /add_customer.rb:583: 3.79 (85%) #1
147
+ /add_customer.rb:585: 0.0 (0%) #1
148
+ /add_customer.rb:587: 0.0 (0%) #1
149
+ /add_customer.rb:595: 0.0 (0%) #1
150
+ /add_customer.rb:603: 0.0 (0%) #1
151
+ /add_customer.rb:612: 0.0 (0%) #1
152
+ /add_customer.rb:617: 0.0 (0%) #1
153
+ Total time by label:
154
+ database_access: 4.45 (99%) #3
155
+ checkouts: 0.0 (0%) #2
156
+ Total time by range:
157
+ /add_customer.rb:509 - /add_customer.rb:529: 0.01 (0%) #1
158
+ /add_customer.rb:529 - /add_customer.rb:532: 0.21 (5%) #1
159
+ /add_customer.rb:532 - /add_customer.rb:569: 0.01 (0%) #1
160
+ /add_customer.rb:569 - /add_customer.rb:581: 0.45 (10%) #1
161
+ /add_customer.rb:581 - /add_customer.rb:583: 3.79 (85%) #1
162
+ /add_customer.rb:583 - /add_customer.rb:585: 0.0 (0%) #1
163
+ /add_customer.rb:585 - /add_customer.rb:587: 0.0 (0%) #1
164
+ /add_customer.rb:587 - /add_customer.rb:595: 0.0 (0%) #1
165
+ /add_customer.rb:595 - /add_customer.rb:603: 0.0 (0%) #1
166
+ /add_customer.rb:603 - /add_customer.rb:612: 0.0 (0%) #1
167
+ /add_customer.rb:612 - /add_customer.rb:617: 0.0 (0%) #1
168
+ "
169
+ }
170
+ ```
171
+
172
+
173
+ ## Contributing
174
+
175
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marioruiz/timify.
176
+
177
+
178
+ ## License
179
+
180
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
181
+
@@ -1,13 +1,15 @@
1
1
  ###############################################################
2
- # Calculates the time running from one location to another inside your code
3
- # attr_accessor:
4
- # min_time_to_show: minimum time to show the elapsed time when calling 'add' method
5
- # show: print out results on screen
6
- # attr_reader:
7
- # name: name given for the Timify instance
8
- # initial_time: when the instance was created
9
- # total: total time elapsed
10
- # max_time_spent: maximum time measured for this instance
2
+ # Calculates the time running from one location to another inside your code. More info: https://github.com/MarioRuiz/timify/
3
+ #
4
+ # attr_accessor:
5
+ # min_time_to_show: minimum time to show the elapsed time when calling 'add' method
6
+ # show: print out results on screen
7
+ #
8
+ # attr_reader:
9
+ # name: name given for the Timify instance
10
+ # initial_time: when the instance was created
11
+ # total: total time elapsed
12
+ # max_time_spent: maximum time measured for this instance
11
13
  ###############################################################
12
14
  class Timify
13
15
  attr_accessor :min_time_to_show, :show
@@ -18,6 +20,7 @@ class Timify
18
20
  # name: name for the instance
19
21
  # min_time_to_show: minimum time to show the elapsed time when calling 'add' method
20
22
  # show: print out results on screen
23
+ #
21
24
  # examples:
22
25
  # t = Timify.new :create_user
23
26
  # t.show = false
@@ -40,21 +43,25 @@ class Timify
40
43
  end
41
44
 
42
45
  ###############################################################
43
- # Adds a new point to count the time elapsed. It will count from the last 'add' call or Timify creation in case of the first 'add'.
44
- # input:
45
- # label: (optional) In case supplied it will summarize all the ones with the same label
46
- # output: (float)
47
- # time elapsed in seconds
48
- # examples:
49
- # t=Timify.new :example
50
- # t.add; run_sqls; t.add :database
51
- # t.add
52
- # #some processes
53
- # t.add
54
- # #some processes
55
- # send_email_alert if t.add > 0.2
56
- # #some processes
57
- # do_log(t.totals[:message]) if t.add > 0.5
46
+ # Adds a new point to count the time elapsed.
47
+ # It will count from the last 'add' call or Timify creation in case of the first 'add'.
48
+ #
49
+ # input:
50
+ # label: (optional) In case supplied it will summarize all the ones with the same label
51
+ #
52
+ # output: (float)
53
+ # time elapsed in seconds
54
+ #
55
+ # examples:
56
+ # t=Timify.new :example
57
+ # t.add; run_sqls; t.add :database
58
+ # t.add
59
+ # #some processes
60
+ # t.add
61
+ # #some processes
62
+ # send_email_alert if t.add > 0.2
63
+ # #some processes
64
+ # do_log(t.totals[:message]) if t.add > 0.5
58
65
  ###############################################################
59
66
  def add(*label)
60
67
  if !label.empty?
@@ -102,21 +109,23 @@ class Timify
102
109
 
103
110
  ###############################################################
104
111
  # returns all data for this instance
105
- # input:
106
- # json: (boolean) in case of true the output will be in json format instead of a hash
107
- # output: (Hash or json string)
108
- # name: (String) name given for this instance'
109
- # total_time: (float) total elapsed time from initialization to last 'add' call
110
- # started: (Time)
111
- # finished: (Time)
112
- # message: (String) a printable friendly message giving all information
113
- # locations, labels, ranges: (Hash) the resultant hash contains:
114
- # secs: (float) number of seconds
115
- # percent: (integer) percentage in reference to the total time
116
- # count: (integer) number of times
117
- # locations: (Hash) All summary data by location where was called
118
- # labels: (Hash) All summary data by label given on 'add' method
119
- # ranges: (Hash) All summary data by ranges where was called, from last 'add' call to current 'add' call
112
+ #
113
+ # input:
114
+ # json: (boolean) in case of true the output will be in json format instead of a hash
115
+ #
116
+ # output: (Hash or json string)
117
+ # name: (String) name given for this instance'
118
+ # total_time: (float) total elapsed time from initialization to last 'add' call
119
+ # started: (Time)
120
+ # finished: (Time)
121
+ # message: (String) a printable friendly message giving all information
122
+ # locations, labels, ranges: (Hash) the resultant hash contains:
123
+ # secs: (float) number of seconds
124
+ # percent: (integer) percentage in reference to the total time
125
+ # count: (integer) number of times
126
+ # locations: (Hash) All summary data by location where was called
127
+ # labels: (Hash) All summary data by label given on 'add' method
128
+ # ranges: (Hash) All summary data by ranges where was called, from last 'add' call to current 'add' call
120
129
  ###############################################################
121
130
  def totals(json: false)
122
131
  require 'json' if json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
@@ -15,8 +15,12 @@ description: Calculates the time running from one location to another inside you
15
15
  email: marioruizs@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
- extra_rdoc_files: []
18
+ extra_rdoc_files:
19
+ - LICENSE
20
+ - README.md
19
21
  files:
22
+ - LICENSE
23
+ - README.md
20
24
  - lib/timify.rb
21
25
  homepage: https://github.com/MarioRuiz/timify
22
26
  licenses: