smpl_prflr 0.0.5 → 0.0.8

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: 97d77e302aa8f3e2851abaf19e1c236ca4a3445bc6d1c45607ad2a6668589d04
4
- data.tar.gz: 90dafcbd65657ad4b04df834f1c7dfc85c26db70ff0d13e94d33cf366bc5cf8b
3
+ metadata.gz: e831f2e767a19c097213f666ba1d2b4cc84b3af52e89b63fe6dafae66f96570d
4
+ data.tar.gz: 0c344feef44fe4104b7079dd97472263daff3e64fec9cd197b99ec5bf34a1f95
5
5
  SHA512:
6
- metadata.gz: 3e809adbeb7e3876dd53afda140c721ec2673e62fc67697d2f002700a5ddee1338c9085d1fff93e05b7b96fc33f71b24b86d9d1e7d8e854a0492af65752845a0
7
- data.tar.gz: 39701976729f4e937b7c8aae119197e93d50480f80bfb2ab0128d4ccbdd560ecfff0e9fdee130e6bea67fb3dbfd7a86f363a092cedecc90e82b138cd75f0ae99
6
+ metadata.gz: 30ac0c5de973a642f055f399ecb1cc2880345c8d5bd99b382f1ce94ab888a966958e2bc8150dc5bba97effbf5c157f14d54d06238759b54198bdcb7750a934dd
7
+ data.tar.gz: 56f70de2928425215e4697c7a84255d5f323eef520362e9c9a55f4e3747f06f966aabc4c6894b0bf07345aa3721d54e0e869a0a035c2d7d20e3ea6773f39f161
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .idea/
2
2
  Gemfile.lock
3
- *.gem
3
+ *.gem
4
+ /config/*
data/README.md CHANGED
@@ -23,7 +23,7 @@ requre 'smpl_prflr'
23
23
 
24
24
  include SmplPrflr
25
25
 
26
- orinitialize_profiler!
26
+ initialize_profiler!(mod: "production")
27
27
 
28
28
  p { block_of_your_own_code }
29
29
  ```
@@ -0,0 +1,7 @@
1
+ module Profiler
2
+ module Constants
3
+ DEFAULT_HOST = "127.0.0.1".freeze
4
+ DEFAULT_PORT = 6379
5
+ DEFAULT_DB = 15
6
+ end
7
+ end
data/lib/smpl_prflr.rb CHANGED
@@ -23,15 +23,35 @@
23
23
  # SOFTWARE.
24
24
 
25
25
  require 'logger'
26
- require 'profiler/profile'
26
+ require "config"
27
+ require 'ruby-prof'
28
+ require 'redis'
29
+ require 'profiler/constants'
30
+ require 'active_support/all'
27
31
 
28
32
  module SmplPrflr
29
33
  # @author KILYA
30
34
  # Init logger
31
35
  # Init Profiler
32
- def initialize_profiler!
36
+ # Load env
37
+ # Init Redis
38
+ def initialize_profiler!(mod = :development)
39
+ Config.setup do |config|
40
+ config.const_name = "Settings"
41
+ config.use_env = false
42
+ end
43
+
44
+ env = mod.to_sym
45
+ path = Dir.pwd << ("/config")
46
+ Config.load_and_set_settings(Config.setting_files(path, env))
47
+ Settings.env = env
48
+
33
49
  @logger = Logger.new($stdout)
34
- @profiler = Profiler::Profile.new
50
+ @redis = Redis.new(
51
+ host: Settings.HOST || Profiler::Constants::DEFAULT_HOST,
52
+ port: Settings.PORT || Profiler::Constants::DEFAULT_PORT,
53
+ db: Settings.DB || Profiler::Constants::DEFAULT_DB
54
+ )
35
55
  end
36
56
 
37
57
  # @author KILYA
@@ -45,10 +65,17 @@ module SmplPrflr
45
65
  # Profile block of your code
46
66
  # @return [nil]
47
67
  def p
48
- @profiler.start do
68
+ output = String.new
69
+ result = RubyProf.profile do
49
70
  yield
50
71
  end
51
- rescue Profiler::ProfilerError => e
52
- @logger.error(e.message.to_s)
72
+
73
+ printer = RubyProf::FlatPrinter.new(result)
74
+ printer.print(output, min_percent: 0)
75
+ @redis.set(:profile, output)
76
+
77
+ nil
78
+ rescue StandardError => e
79
+ @logger.error e.message.to_s
53
80
  end
54
81
  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.5'
10
+ s.version = '0.0.8'
11
11
  s.executables << 'smpl_prflr'
12
12
  s.license = 'MIT'
13
13
  s.summary = 'Profiler'
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency 'ruby-prof', '~> 1.4', '>= 1.4.3'
22
22
  s.add_dependency 'redis', '~> 4.6'
23
23
  s.add_dependency 'rack', '~> 2.2'
24
+ s.add_dependency 'config', '~> 4.0'
24
25
  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.5
4
+ version: 0.0.8
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-05 00:00:00.000000000 Z
11
+ date: 2022-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2.2'
89
+ - !ruby/object:Gem::Dependency
90
+ name: config
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '4.0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.0'
89
103
  description: SmplPrflr for profiler own code.
90
104
  email: ilyafulleveline@gmail.com
91
105
  executables:
@@ -101,7 +115,7 @@ files:
101
115
  - README.md
102
116
  - Rakefile
103
117
  - bin/smpl_prflr
104
- - lib/profiler/profile.rb
118
+ - lib/profiler/constants.rb
105
119
  - lib/smpl_prflr.rb
106
120
  - smpl_prflr.gemspec
107
121
  - test/test_ping.rb
@@ -1,59 +0,0 @@
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