execution_time 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -3
- data/lib/execution_time/version.rb +1 -1
- data/lib/execution_time.rb +20 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db79ec20431ed5134a18fb0b21029400df60851760d2bf4e5390d4f22a3d0b69
|
4
|
+
data.tar.gz: 1f6a6575fba8d55758c9a2a6b591d3084f418b390ef9ec1884e7e67399f7315f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4efa6a6e4482fc17fcdcf8637c2f835e8fddf5f10446f21288bd6da669e66fc20611e2dbe3f2d136d61f42caa833d148727fcb9824f032499a0c9c070d6a751d
|
7
|
+
data.tar.gz: be78c6409bf4ce01056a367a0921db07a44af8738f242a404949d1654a9e72aae10158b0c9e3db16fd866cb6a3fa81bad6d3ace7b9640bd91a120af46256ad7b
|
data/README.md
CHANGED
@@ -1,14 +1,29 @@
|
|
1
1
|
# ExecutionTime
|
2
2
|
|
3
|
-
|
3
|
+
Monitor execution time and other metrics directly in `rails console`, similar to what you see after each request.
|
4
4
|
|
5
5
|
`[METRICS] Completed in 908.3ms | Allocations: 2894 | ActiveRecord: 0.9ms (queries: 13)`
|
6
6
|
|
7
|
+
<img src="https://github.com/igorkasyanchuk/execution_time/blob/master/docs/execution_time_new.gif?raw=true" width="90%" />
|
8
|
+
|
7
9
|
## Usage
|
8
10
|
|
9
11
|
Just add this gem to the Gemfile and start `rails c`. After this try to do something like `User.first`.
|
10
12
|
|
11
|
-
If you want to measure few lines of code just wrap it with `begin/end
|
13
|
+
If you want to measure few lines of code just wrap it with `begin/end`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
[4] pry(main)> begin
|
17
|
+
[4] pry(main)* User.first.first_name.size
|
18
|
+
[4] pry(main)* a = User.count + 1
|
19
|
+
[4] pry(main)* b = User.second.last_name.size
|
20
|
+
[4] pry(main)* end
|
21
|
+
User Load (0.4ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 1]]
|
22
|
+
(3.6ms) SELECT COUNT(*) FROM "users"
|
23
|
+
User Load (0.3ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1], ["OFFSET", 1]]
|
24
|
+
[METRICS] Completed in 6.8ms | Allocations: 839 | ActiveRecord: 4.3ms (queries: 3)
|
25
|
+
=> 5
|
26
|
+
```
|
12
27
|
|
13
28
|
## Installation
|
14
29
|
|
@@ -20,11 +35,22 @@ gem 'execution_time'
|
|
20
35
|
|
21
36
|
## First run
|
22
37
|
|
23
|
-
Sometime you can see that there are more SQL queries or allocated objects because Ruby just loading objects in memory or verifying connection to the DB.
|
38
|
+
Sometime you can see that there are more SQL queries or allocated objects because Ruby is just loading objects in memory or verifying connection to the DB.
|
39
|
+
|
40
|
+
## How to disable/enable metrics output in the console
|
41
|
+
|
42
|
+
If you need to disable gem in the console you can do it by `ExecutionTime.disable!`. And later enable with `ExecutionTime.enable!`.
|
43
|
+
|
44
|
+
By default gem is enabled.
|
45
|
+
|
24
46
|
|
25
47
|
## Contributing
|
26
48
|
|
27
49
|
You are welcome to contribute.
|
28
50
|
|
51
|
+
## Contributos
|
52
|
+
|
53
|
+
- https://github.com/nbulaj
|
54
|
+
|
29
55
|
## License
|
30
56
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/execution_time.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
require "execution_time/railtie"
|
2
2
|
|
3
3
|
module ExecutionTime
|
4
|
+
mattr_accessor :enabled
|
5
|
+
@@enabled = true
|
6
|
+
|
7
|
+
def ExecutionTime.enable!
|
8
|
+
@@enabled = true
|
9
|
+
end
|
10
|
+
|
11
|
+
def ExecutionTime.disable!
|
12
|
+
@@enabled = false
|
13
|
+
end
|
14
|
+
|
4
15
|
class AppMetrics
|
5
16
|
@@counter = 0
|
6
17
|
|
@@ -32,16 +43,18 @@ module ExecutionTime
|
|
32
43
|
|
33
44
|
class Measurer
|
34
45
|
def Measurer.watch
|
46
|
+
return yield unless ExecutionTime.enabled
|
47
|
+
|
35
48
|
AppMetrics.reset
|
36
49
|
|
37
|
-
start =
|
50
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
38
51
|
before = GC.stat(:total_allocated_objects)
|
39
52
|
ActiveRecord::LogSubscriber.reset_runtime
|
40
53
|
|
41
54
|
result = yield
|
42
55
|
|
43
56
|
after = GC.stat(:total_allocated_objects)
|
44
|
-
duration = (
|
57
|
+
duration = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start)
|
45
58
|
db_after = ActiveRecord::LogSubscriber.reset_runtime
|
46
59
|
|
47
60
|
info = "Completed in #{(duration * 1000).round(1)}ms | Allocations: #{after - before}"
|
@@ -59,7 +72,11 @@ module ExecutionTime
|
|
59
72
|
module IrbContextExt
|
60
73
|
def evaluate(*args)
|
61
74
|
Measurer.watch do
|
62
|
-
|
75
|
+
if RUBY_VERSION.to_s =~ /^3/
|
76
|
+
super(args[0], args[1], **args[2])
|
77
|
+
else
|
78
|
+
super(*args)
|
79
|
+
end
|
63
80
|
end
|
64
81
|
end
|
65
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execution_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -56,7 +56,7 @@ homepage: https://github.com/igorkasyanchuk
|
|
56
56
|
licenses:
|
57
57
|
- MIT
|
58
58
|
metadata: {}
|
59
|
-
post_install_message:
|
59
|
+
post_install_message:
|
60
60
|
rdoc_options: []
|
61
61
|
require_paths:
|
62
62
|
- lib
|
@@ -71,8 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
75
|
-
signing_key:
|
74
|
+
rubygems_version: 3.2.3
|
75
|
+
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: Measure execution time in Rails console
|
78
78
|
test_files: []
|