smpl_prflr 0.0.1 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6565230b4fcc96ffabea3468e83fc88a5f154e658c9cd51def13ff9c41d955f0
4
- data.tar.gz: 7bf1bf8271d889aa031c4b49a465867976fae11d82fb32dbdfce7746340c74e1
3
+ metadata.gz: 4aa1604560c3f6c646b15211198c683537c74896a312c96befbd675caad9c02b
4
+ data.tar.gz: dc74c4b885f3edded7964add212c8a8063714fc6c7bda30c3a0129fb2795bb16
5
5
  SHA512:
6
- metadata.gz: f81675a1c2d92df34396583e9dea524ef868d84ac39ecad33a8d213b5f80b511ae79d0b4190e545d45f2bac56aefca8dd389302ab7862a22694f2096701a958c
7
- data.tar.gz: 64e8ae3790723745e2a7708ba1d13c5c3bf580bfd7d78864872d8e1f5614c4ea38e7c22dfcbf9e412029624ba33d32337ce9b32c2e185d6e9a7d079f788c7ed7
6
+ metadata.gz: 03f4ee75268ef2a8c3870b002d2ddf55f6f217c788f719540ea7f6bc8a469bbd2d5fbcb10484d5654f9867bfe21a46aaa5635d9bb0428ae73863c4b58eaf55cf
7
+ data.tar.gz: 5af5cca8a5e42bbaa947c7f36997a64ddd16f971ee6b07c69ba599aecdd4e26b289b17441c4c538b32dbeeaac6fc274b407e6563b30a4e5063f38014e930a199
data/.rubocop.yml CHANGED
@@ -5,7 +5,6 @@ AllCops:
5
5
  - Rakefile
6
6
  - smpl_prflr.gemspec
7
7
  - bin/*
8
- - config.ru
9
8
 
10
9
  Style/FrozenStringLiteralComment:
11
10
  Enabled: false
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source 'https://rubygems.org/'
2
2
  ruby '2.7.2'
3
- gemspec
4
-
5
- gem 'rack', '~> 2.2'
6
- gem 'require_all', '~> 2.0'
7
- gem 'activesupport', '~> 6.1.1'
8
- gem 'config', '~> 3.1'
3
+ gemspec
data/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  ruby '2.7.2'
7
7
  gem 'redis' '~> 4.6'
8
8
  gem 'ruby-prof' '~>1.4'
9
+ gem 'rack'
9
10
  ```
10
11
  ## Install:
11
12
  ```sh
@@ -13,6 +14,12 @@ bundle install smpl_prflr
13
14
 
14
15
  requre 'smpl_prflr'
15
16
  ```
17
+ ## As web:
18
+ ```sh
19
+ gem install smpl_prflr
20
+
21
+ smpl_prflr
22
+ ```
16
23
  ## How is it works?:
17
24
  ```sh
18
25
  require 'smpl_prflr'
@@ -20,4 +27,8 @@ requre 'smpl_prflr'
20
27
  SmplPrflr.new.p do
21
28
  'your own code'
22
29
  end
30
+
31
+ after that you should start web server smpl_prflr
32
+ get request: 127.0.0.1:9292/
33
+
23
34
  ```
data/bin/smpl_prflr CHANGED
@@ -1,5 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- Dir.chdir(File.join(File.dirname(__FILE__), ".."))
4
2
 
5
- load ::File.expand_path("../../config.ru", __FILE__)
3
+ require 'rack'
4
+ require 'redis'
5
+
6
+ # @author KILYA
7
+ # View profile by redis
8
+ # port: 9292
9
+ # url: 127.0.0.1
10
+ # method GET
11
+ def my_method env
12
+ redis = Redis.new host: "127.0.0.1", port: 6379, db: 15
13
+ result = redis.get(:profile) || "Nothing to profile"
14
+ [200, {}, [result]]
15
+ rescue StandardError
16
+ [500, {}, ["Redis not available"]]
17
+ end
18
+
19
+ Rack::Handler::WEBrick.run method(:my_method), :Port => 9292
20
+
data/lib/smpl_prflr.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The MIT License (MIT)
2
4
  #
3
5
  # Copyright (c) 2019-2022 Kondratev Ilya
@@ -26,14 +28,13 @@ require 'logger'
26
28
 
27
29
  class SmplPrflr
28
30
  class ProfilerError < StandardError; end
29
- DEFAULT_HOST = "127.0.0.1".freeze
30
31
 
31
32
  # @author KILYA
32
33
  # @param [String] host
33
34
  # @param [Integer] port
34
35
  # @param [Integer] db
35
36
  # @example self.new(host: "http:/your.path", port: 555, db:1)
36
- def initialize(host: DEFAULT_HOST, port: 6379, db: 15)
37
+ def initialize(host: "127.0.0.1", port: 6379, db: 15)
37
38
  @logger = Logger.new($stdout)
38
39
  @redis = Redis.new(
39
40
  host: host,
@@ -53,15 +54,15 @@ class SmplPrflr
53
54
 
54
55
  # @author KILYA
55
56
  # Profile block of your code
56
- def p
57
- profiled = ""
57
+ # @return [nil]
58
+ def p(prof: "")
58
59
  result = RubyProf.profile do
59
60
  yield
60
61
  end
61
62
 
62
63
  printer = RubyProf::FlatPrinter.new(result)
63
- printer.print(profiled, min_percent: 0)
64
- @redis.set(:profile, profiled)
64
+ printer.print(prof, min_percent: 0)
65
+ @redis.set(:profile, prof)
65
66
 
66
67
  nil
67
68
  rescue StandardError => e
data/smpl_prflr.gemspec CHANGED
@@ -7,7 +7,8 @@ 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.1'
10
+ s.version = '0.0.4'
11
+ s.executables << 'smpl_prflr'
11
12
  s.license = 'MIT'
12
13
  s.summary = 'Profiler'
13
14
  s.description = 'SmplPrflr for profiler own code.'
@@ -19,4 +20,5 @@ Gem::Specification.new do |s|
19
20
  s.add_dependency 'rubocop-rake'
20
21
  s.add_dependency 'ruby-prof', '~> 1.4', '>= 1.4.3'
21
22
  s.add_dependency 'redis', '~> 4.6'
23
+ s.add_dependency 'rack', '~> 2.2'
22
24
  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.1
4
+ version: 0.0.4
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-03 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -72,9 +72,24 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '4.6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.2'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.2'
75
89
  description: SmplPrflr for profiler own code.
76
90
  email: ilyafulleveline@gmail.com
77
- executables: []
91
+ executables:
92
+ - smpl_prflr
78
93
  extensions: []
79
94
  extra_rdoc_files: []
80
95
  files:
@@ -85,15 +100,7 @@ files:
85
100
  - LICENSE.txt
86
101
  - README.md
87
102
  - Rakefile
88
- - app/controllers/base_controller.rb
89
- - app/controllers/services_controller.rb
90
- - app/services/profile_service.rb
91
103
  - bin/smpl_prflr
92
- - config.ru
93
- - config/app/app.rb
94
- - config/app/router.rb
95
- - config/application.rb
96
- - config/initializers/001_settings.rb
97
104
  - lib/smpl_prflr.rb
98
105
  - smpl_prflr.gemspec
99
106
  - test/test_ping.rb
@@ -1,38 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
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
13
- # in all 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 NON-INFRINGEMENT. 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.
22
-
23
- class BaseController
24
- def initialize(request)
25
- @request = request
26
- @response = Services::ProfileService.new
27
- end
28
-
29
- def not_found
30
- build_response("not_found", status: 404)
31
- end
32
-
33
- private
34
-
35
- def build_response(body, status: 200)
36
- [status, { "Content-Type" => "text/json" }, [body]]
37
- end
38
- end
@@ -1,33 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
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
13
- # in all 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 NON-INFRINGEMENT. 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.
22
-
23
- class ServicesController < BaseController
24
- def ping
25
- result = "PONG"
26
- build_response(result)
27
- end
28
-
29
- def profile
30
- result = @response.load_profile
31
- build_response(result)
32
- end
33
- end
@@ -1,37 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
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
13
- # in all 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 NON-INFRINGEMENT. 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.
22
-
23
- module Services
24
- class ProfileService
25
- def initialize
26
- @redis = Redis.new(
27
- host: "127.0.0.1",
28
- port: 6379,
29
- db: 15
30
- )
31
- end
32
-
33
- def load_profile
34
- @redis.get(:profile)
35
- end
36
- end
37
- end
data/config/app/app.rb DELETED
@@ -1,32 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
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
13
- # in all 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 NON-INFRINGEMENT. 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.
22
-
23
- class App
24
- def call(env)
25
- request = Rack::Request.new(env)
26
- serve_request(request)
27
- end
28
-
29
- def serve_request(request)
30
- Router.new(request).route!
31
- end
32
- end
data/config/app/router.rb DELETED
@@ -1,50 +0,0 @@
1
- # The MIT License (MIT)
2
- #
3
- # Copyright (c) 2019-2022 Kondratev Ilya
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
13
- # in all 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 NON-INFRINGEMENT. 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.
22
-
23
- class Router
24
- def initialize(request)
25
- @request = request
26
- end
27
-
28
- def route!
29
- return controller.not_found unless @request.get?
30
-
31
- case @request.path
32
- when "/ping"
33
- controller.ping
34
- when "/profile"
35
- controller.profile
36
- else
37
- controller.not_found
38
- end
39
- end
40
-
41
- private
42
-
43
- def controller
44
- @controller ||= ServicesController.new(@request)
45
- end
46
-
47
- def params
48
- JSON.parse(@request.body.read)
49
- end
50
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # require gems
4
- require 'bundler'
5
-
6
- Bundler.require(:default, ENV["RACK_ENV"] || "development")
7
-
8
- # require additional gem files
9
- require "active_support/all"
10
-
11
- # initialize application, logger, gems, etc.
12
- require_all "config/initializers"
13
-
14
- # require application
15
- require_all "app"
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "config"
4
-
5
- Config.setup do |config|
6
- config.const_name = "Settings"
7
- config.use_env = false
8
- end
9
-
10
- env = ::ActiveSupport::StringInquirer.new(ENV["RACK_ENV"] || "development")
11
- path = Dir.pwd << ("/config")
12
- Config.load_and_set_settings(Config.setting_files(path, env))
13
-
14
- Settings.env = env
data/config.ru DELETED
@@ -1,4 +0,0 @@
1
- require_relative "config/application"
2
- require_all "./config/app"
3
-
4
- run Rack::URLMap.new('/' => Rack::Builder.new { run App.new })