perfetto 0.1.6 → 0.1.7

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: 336d2d67b2921461a66687b0a06fca3ef0e925cbdc83e028bdbf2863ef3012d4
4
- data.tar.gz: 3dc3d8b63d9029dcc10d5250f156663d5248da727652aa0b3cce42a55ac856af
3
+ metadata.gz: 7384eed21d076be3de57b5afa9fc886e979ccc4d89e167afc61e2800314d61f4
4
+ data.tar.gz: f6c71a99835e93c07734bfd790aba1d80fa86879327f2357007c184edbd0a619
5
5
  SHA512:
6
- metadata.gz: c2771fce6b5aa3b804f6c79d7e64fde0af8238ba25d6325707634d5612a05254df7c6dbf0b34d78d8c2f9c9f502f331e0dd954805167993378f28540cc474c57
7
- data.tar.gz: 2a006c86b49bad07a0a0d7117c65a5813dd9a957cb24992aee9b419efe0ac3644a92f6d63338a994b97e9ef800b25dc2bc941d0434a42c20443eb04c5b7aad5d
6
+ metadata.gz: c77bd5af96cb578659982e03d292893426a64d7d8ef7618ea5ab782005c519c6e2244b4d6cd7885fc2b9f2e76f6551e1fb3bd67b803552df3c8b8e861f671c38
7
+ data.tar.gz: e33c6fe69f65d1dcd2ed3a81ba6e2e699b85b89932511233638900514921d310dbf305f17bb0bb899fe39ac2593bac48667fcca452fa53f9fdf0467cf7a90923
data/README.md CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  https://ui.perfetto.dev/
6
6
 
7
- # Usage
7
+ ## Usage
8
+
9
+ ### Basic
8
10
 
9
11
  ```ruby
10
12
  require "perfetto"
@@ -83,3 +85,26 @@ Perfetto.stop_tracing "example.pftrace"
83
85
  ```
84
86
 
85
87
  ![example](./example/example.png)
88
+
89
+ ### Rack Middleware
90
+
91
+ ```ruby
92
+ # frozen_string_literal: true
93
+
94
+ require "sinatra/base"
95
+ require "perfetto"
96
+
97
+ Perfetto.setup enable_tracing: true
98
+
99
+ class Server < Sinatra::Base
100
+ use Perfetto::Middleware
101
+
102
+ get "/" do
103
+ "Hello World"
104
+ end
105
+ end
106
+
107
+ Perfetto.start_tracing
108
+ Server.run!
109
+ Perfetto.stop_tracing "middleware.pftrace"
110
+ ```
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Metrics/AbcSize
4
+ # rubocop:disable Metrics/MethodLength
5
+
3
6
  module Perfetto
4
7
  # To intercept method calls in other classes
5
8
  module Interceptor
@@ -39,7 +42,6 @@ module Perfetto
39
42
  def perfetto_trace_instance_method(method_name)
40
43
  return if method_name.to_s.start_with? "_pfi_"
41
44
 
42
- # warn "Perfetto[InstanceMethod]: #{name}##{method_name}"
43
45
  perfetto_traced_instance_methods << method_name
44
46
 
45
47
  original_method = instance_method(method_name)
@@ -56,17 +58,16 @@ module Perfetto
56
58
  end
57
59
 
58
60
  def perfetto_trace_class_method(method_name)
59
- return if method_name.to_s == "singleton_method_added" || method_name.to_s.start_with?("_pfc_")
61
+ return if method_name.to_s.start_with? "_pfc_"
60
62
 
61
- # warn "Perfetto[ClassMethod]: #{name}.#{method_name}"
62
63
  perfetto_traced_class_methods << method_name
63
64
 
64
65
  original_method = method(method_name)
65
66
  singleton_class.send(:alias_method, "_pfc_#{method_name}", method_name)
66
67
 
67
68
  define_singleton_method(method_name) do |*args, **kwargs, &block|
68
- category = self.name
69
- task_name = "#{self.name}.#{method_name}"
69
+ category = name
70
+ task_name = "#{name}.#{method_name}"
70
71
  Perfetto.trace_event_begin category, task_name
71
72
  original_method.call(*args, **kwargs, &block)
72
73
  ensure
@@ -106,3 +107,5 @@ module Perfetto
106
107
  end
107
108
  end
108
109
  end
110
+ # rubocop:enable Metrics/AbcSize
111
+ # rubocop:enable Metrics/MethodLength
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Perfetto
6
+ # Rack middleware
7
+ class Middleware
8
+ def initialize(app, options = {})
9
+ @app = app
10
+ @options = options
11
+ end
12
+
13
+ if Perfetto::Configure.enable_tracing
14
+ def call(env)
15
+ category = "RackMiddleware"
16
+ method = env["REQUEST_METHOD"] || "UNKNOWN"
17
+ path = env["PATH_INFO"] || "UNKNOWN PATH"
18
+ task_name = "#{method} #{path}"
19
+ Perfetto.trace_event_begin_with_debug_info category, task_name, "env", env.to_json
20
+ begin
21
+ @app.call(env)
22
+ ensure
23
+ Perfetto.trace_event_end category
24
+ end
25
+ end
26
+ else # Stub methods
27
+ def call(env)
28
+ @app.call(env)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -13,7 +13,7 @@ module Perfetto
13
13
  start_tracing_native Configure.buffer_size_kb
14
14
  end
15
15
 
16
- def self.stop_tracing(trace_file_name = "#{Time.now.strftime("%Y%m%d%H%M%S")}.pftrace")
16
+ def self.stop_tracing(trace_file_name = "#{Time.now.strftime("%Y%m%d-%H-%M-%S")}.pftrace")
17
17
  stop_tracing_native trace_file_name
18
18
  end
19
19
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Perfetto
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/perfetto.rb CHANGED
@@ -20,5 +20,7 @@ module Perfetto
20
20
  require_relative "perfetto/perfetto"
21
21
  # Instrumentation Helper
22
22
  require_relative "perfetto/interceptor"
23
+ # Rack middleware
24
+ require_relative "perfetto/middleware"
23
25
  end
24
26
  end
data/perfetto.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/perfetto/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "perfetto"
7
+ spec.version = Perfetto::VERSION
8
+ spec.authors = ["Kowalski Dark"]
9
+ spec.email = ["github@akenonet.com"]
10
+
11
+ spec.summary = "Yet another event tracing library for Ruby."
12
+ spec.description = "Yet another event tracing library for Ruby."
13
+ spec.homepage = "https://github.com/yet-another-ai/perfetto.rb"
14
+ spec.required_ruby_version = ">= 3.3.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(__dir__) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (File.expand_path(f) == __FILE__) ||
23
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = %w[lib ext]
29
+ spec.extensions = ["ext/perfetto/extconf.rb"]
30
+
31
+ # For more information and examples about making a new gem, check out our
32
+ # guide at: https://bundler.io/guides/creating_gem.html
33
+ spec.metadata["rubygems_mfa_required"] = "true"
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perfetto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kowalski Dark
@@ -35,8 +35,10 @@ files:
35
35
  - lib/perfetto/configure.rb
36
36
  - lib/perfetto/core_ext/configurable.rb
37
37
  - lib/perfetto/interceptor.rb
38
+ - lib/perfetto/middleware.rb
38
39
  - lib/perfetto/perfetto.rb
39
40
  - lib/perfetto/version.rb
41
+ - perfetto.gemspec
40
42
  - sig/perfetto.rbs
41
43
  homepage: https://github.com/yet-another-ai/perfetto.rb
42
44
  licenses: []