smpl_prflr 0.0.4 → 0.0.5

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: 4aa1604560c3f6c646b15211198c683537c74896a312c96befbd675caad9c02b
4
- data.tar.gz: dc74c4b885f3edded7964add212c8a8063714fc6c7bda30c3a0129fb2795bb16
3
+ metadata.gz: 97d77e302aa8f3e2851abaf19e1c236ca4a3445bc6d1c45607ad2a6668589d04
4
+ data.tar.gz: 90dafcbd65657ad4b04df834f1c7dfc85c26db70ff0d13e94d33cf366bc5cf8b
5
5
  SHA512:
6
- metadata.gz: 03f4ee75268ef2a8c3870b002d2ddf55f6f217c788f719540ea7f6bc8a469bbd2d5fbcb10484d5654f9867bfe21a46aaa5635d9bb0428ae73863c4b58eaf55cf
7
- data.tar.gz: 5af5cca8a5e42bbaa947c7f36997a64ddd16f971ee6b07c69ba599aecdd4e26b289b17441c4c538b32dbeeaac6fc274b407e6563b30a4e5063f38014e930a199
6
+ metadata.gz: 3e809adbeb7e3876dd53afda140c721ec2673e62fc67697d2f002700a5ddee1338c9085d1fff93e05b7b96fc33f71b24b86d9d1e7d8e854a0492af65752845a0
7
+ data.tar.gz: 39701976729f4e937b7c8aae119197e93d50480f80bfb2ab0128d4ccbdd560ecfff0e9fdee130e6bea67fb3dbfd7a86f363a092cedecc90e82b138cd75f0ae99
data/README.md CHANGED
@@ -4,31 +4,35 @@
4
4
  ## Dependencies:
5
5
  ```sh
6
6
  ruby '2.7.2'
7
- gem 'redis' '~> 4.6'
8
- gem 'ruby-prof' '~>1.4'
9
- gem 'rack'
7
+ ...
8
+ gem 'redis' '4.6'
9
+ gem 'ruby-prof' '1.4'
10
+ gem 'rubocop' '1.26'
11
+ gem 'rack' '2.2'
10
12
  ```
11
13
  ## Install:
12
14
  ```sh
13
15
  bundle install smpl_prflr
14
16
 
15
17
  requre 'smpl_prflr'
16
- ```
17
- ## As web:
18
- ```sh
19
- gem install smpl_prflr
20
18
 
21
- smpl_prflr
22
19
  ```
23
20
  ## How is it works?:
24
21
  ```sh
25
22
  require 'smpl_prflr'
23
+
24
+ include SmplPrflr
25
+
26
+ orinitialize_profiler!
26
27
 
27
- SmplPrflr.new.p do
28
- 'your own code'
29
- end
30
-
31
- after that you should start web server smpl_prflr
28
+ p { block_of_your_own_code }
29
+ ```
30
+
31
+ ## As web:
32
+ ```sh
33
+ user@mac$ gem install smpl_prflr
34
+ ...
35
+ user@mac$ smpl_prflr
36
+ ...
32
37
  get request: 127.0.0.1:9292/
33
-
34
38
  ```
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) 2019-2022 Kondratev Ilya
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included
15
+ # in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ require 'ruby-prof'
26
+ require 'redis'
27
+
28
+ module Profiler
29
+ class Profile
30
+ class ProfilerError < StandardError; end
31
+
32
+ # @author KILYA
33
+ # Initialise redis
34
+ def initialize
35
+ @redis = Redis.new(
36
+ host: "127.0.0.1",
37
+ port: 6379,
38
+ db: 15
39
+ )
40
+ end
41
+
42
+ # @author KILYA
43
+ # main point
44
+ def start
45
+ output = String.new
46
+ result = RubyProf.profile do
47
+ yield
48
+ end
49
+
50
+ printer = RubyProf::FlatPrinter.new(result)
51
+ printer.print(output, min_percent: 0)
52
+ @redis.set(:profile, output)
53
+
54
+ nil
55
+ rescue StandardError => e
56
+ raise ProfilerError.new e.message.to_s
57
+ end
58
+ end
59
+ end
data/lib/smpl_prflr.rb CHANGED
@@ -22,50 +22,33 @@
22
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  # SOFTWARE.
24
24
 
25
- require 'ruby-prof'
26
- require 'redis'
27
25
  require 'logger'
26
+ require 'profiler/profile'
28
27
 
29
- class SmplPrflr
30
- class ProfilerError < StandardError; end
31
-
28
+ module SmplPrflr
32
29
  # @author KILYA
33
- # @param [String] host
34
- # @param [Integer] port
35
- # @param [Integer] db
36
- # @example self.new(host: "http:/your.path", port: 555, db:1)
37
- def initialize(host: "127.0.0.1", port: 6379, db: 15)
30
+ # Init logger
31
+ # Init Profiler
32
+ def initialize_profiler!
38
33
  @logger = Logger.new($stdout)
39
- @redis = Redis.new(
40
- host: host,
41
- port: port,
42
- db: db
43
- )
34
+ @profiler = Profiler::Profile.new
44
35
  end
45
36
 
46
37
  # @author KILYA
47
- # @param nil
48
- #
49
38
  # @example PONG
50
39
  # @return [String] PONG
51
- def self.ping
40
+ def ping
52
41
  "PONG"
53
42
  end
54
43
 
55
44
  # @author KILYA
56
45
  # Profile block of your code
57
46
  # @return [nil]
58
- def p(prof: "")
59
- result = RubyProf.profile do
47
+ def p
48
+ @profiler.start do
60
49
  yield
61
50
  end
62
-
63
- printer = RubyProf::FlatPrinter.new(result)
64
- printer.print(prof, min_percent: 0)
65
- @redis.set(:profile, prof)
66
-
67
- nil
68
- rescue StandardError => e
51
+ rescue Profiler::ProfilerError => e
69
52
  @logger.error(e.message.to_s)
70
53
  end
71
54
  end
data/smpl_prflr.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.rubygems_version = '2.7'
8
8
  s.required_ruby_version = '>=2.2'
9
9
  s.name = 'smpl_prflr'
10
- s.version = '0.0.4'
10
+ s.version = '0.0.5'
11
11
  s.executables << 'smpl_prflr'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Profiler'
data/test/test_ping.rb CHANGED
@@ -2,8 +2,9 @@ require 'minitest/autorun'
2
2
  require 'smpl_prflr'
3
3
 
4
4
  class TestPing < Minitest::Test
5
+ include SmplPrflr
6
+
5
7
  def test_reverse_string
6
- ping = SmplPrflr.ping
7
8
  assert_equal("PONG", ping)
8
9
  end
9
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smpl_prflr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Kondratev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-04 00:00:00.000000000 Z
11
+ date: 2022-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -101,6 +101,7 @@ files:
101
101
  - README.md
102
102
  - Rakefile
103
103
  - bin/smpl_prflr
104
+ - lib/profiler/profile.rb
104
105
  - lib/smpl_prflr.rb
105
106
  - smpl_prflr.gemspec
106
107
  - test/test_ping.rb