furia 0.0.3 → 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: b918eefd85e857f9a867d493589a36a3515ae3ce99e8e853ebfc9aeec0762ea2
4
- data.tar.gz: dfb82bf985fb4d8a2c2a30ad3c3adb2ce183b644f337f094191c7756effcff03
3
+ metadata.gz: ca7eee5b4b9ba91aaca06c16f5c2a25f4422c971c2d6810701fd1fca735ea00a
4
+ data.tar.gz: b47f5cc0f15156600a260e3255f108daa639025375ca051226866526f4cdc7c4
5
5
  SHA512:
6
- metadata.gz: 855368d7e83ebc3b7daad06c0622670294ff3af5bdc69436a0a7868dfcc795bad0ebe3676b23d1b38edc1981a97c982b332a14ac38089a034948074dbc8d161a
7
- data.tar.gz: 796e6d32869c0ac251e55e91d9b3d4cc83e4fcc383316e8243c33fd4f67c07fef88afca2eb100fc07649dc5b432a6f18efa9889a9728346412a5f4ed5b50f5d7
6
+ metadata.gz: aeeb7d75e1457e2f16a237fa5af34b7ca7724ef3da786ddbf97de6ce4036599e5e72aad0471b63b67b4e28484fdd82c4f1b41a6a137a14cfaa970db2ec4821c3
7
+ data.tar.gz: 99393bc6b233badffe7f3892db956db5d21cb206d5172eb648bc39e8dff3fcbfb557f39e09becd42e5b3698f90e4962244b4fd93fd1199dc4deabb40b284644e
data/lib/furia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Furia
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/furia.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "furia/engine"
2
- require "furia/observer"
3
2
 
4
3
  module Furia
5
4
  Group =
@@ -29,4 +28,68 @@ module Furia
29
28
  raise "Unsupported type: `#{symbolized[:type]}'"
30
29
  end
31
30
  end
31
+
32
+ def self.wrap(scope)
33
+ parent_group = store[:current_group]
34
+ if parent_group
35
+ store[:current_group] = { uid: SecureRandom.hex(16), type: "group", scope: scope, total_duration_ms: 0, entries: [] }
36
+ parent_group[:entries] << store[:current_group]
37
+ else
38
+ store[:root_group] = { uid: "root", type: "group", scope: scope, total_queries_num: 0, total_duration_ms: 0, entries: [] }
39
+ store[:current_group] = store[:root_group]
40
+ end
41
+
42
+ subscriber = create_subscriber unless parent_group
43
+
44
+ yield.tap do
45
+ if parent_group
46
+ parent_group[:total_duration_ms] += store[:current_group][:total_duration_ms]
47
+ store[:current_group] = parent_group
48
+ else
49
+ Furia::Sample.create!(data: store[:root_group])
50
+ end
51
+ end
52
+ ensure
53
+ if subscriber
54
+ ActiveSupport::Notifications.unsubscribe(subscriber)
55
+ clear_store
56
+ end
57
+ end
58
+
59
+ def self.create_subscriber
60
+ ActiveSupport::Notifications.subscribe("sql.active_record") do |_, started, finished, _, payload|
61
+ next if payload[:name] == "SCHEMA"
62
+
63
+ duration_ms = (finished - started) * 1000
64
+ entry = {
65
+ uid: SecureRandom.hex(16),
66
+ type: "query",
67
+ sql: payload[:sql],
68
+ cached: payload[:name] == "CACHE",
69
+ duration_ms: duration_ms,
70
+ stacktrace: trace_cleaner.clean(caller),
71
+ }.freeze
72
+
73
+ store[:current_group][:entries] << entry
74
+ store[:current_group][:total_duration_ms] += duration_ms
75
+ store[:root_group][:total_queries_num] += 1
76
+ end
77
+ end
78
+
79
+ def self.trace_cleaner
80
+ @trace_cleaner ||=
81
+ ActiveSupport::BacktraceCleaner.new.tap do |c|
82
+ c.add_silencer { |line| line.include?("/gems/") }
83
+ c.add_silencer { |line| line.include?("/ruby/") }
84
+ c.add_silencer { |line| line.include?("/active_record/") }
85
+ end
86
+ end
87
+
88
+ def self.store
89
+ Thread.current[:furia_store] ||= {}
90
+ end
91
+
92
+ def self.clear_store
93
+ Thread.current[:furia_store] = {}
94
+ end
32
95
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viacheslav Alekseev
@@ -45,7 +45,6 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - MIT-LICENSE
48
- - README.rdoc
49
48
  - Rakefile
50
49
  - app/assets/javascripts/furia/application.js
51
50
  - app/assets/stylesheets/furia/application.css
@@ -62,7 +61,6 @@ files:
62
61
  - db/migrate/20251228160822_create_furia_samples.rb
63
62
  - lib/furia.rb
64
63
  - lib/furia/engine.rb
65
- - lib/furia/observer.rb
66
64
  - lib/furia/version.rb
67
65
  - lib/tasks/furia_tasks.rake
68
66
  homepage: https://github.com/alexeevit/furia
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = Furia
2
-
3
- This project rocks and uses MIT-LICENSE.
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Furia
4
- module Observer
5
- def self.wrap(scope)
6
- @root_scope ||= { uid: "root", type: "group", scope: scope, total_queries_num: 0, total_duration_ms: 0, entries: [] }
7
- parent_scope = @current_scope
8
- @current_scope =
9
- if parent_scope
10
- { uid: SecureRandom.hex(16), type: "group", scope: scope, total_duration_ms: 0, entries: [] }.tap do |new_scope|
11
- parent_scope[:entries] << new_scope
12
- end
13
- else
14
- @root_scope
15
- end
16
-
17
- subscriber =
18
- ActiveSupport::Notifications.subscribe("sql.active_record") do |_, started, finished, _, payload|
19
- next if payload[:name] == "SCHEMA"
20
-
21
- duration_ms = (finished - started) * 1000
22
- @current_scope[:total_duration_ms] += duration_ms
23
- entry = {
24
- uid: SecureRandom.hex(16),
25
- type: "query",
26
- sql: payload[:sql],
27
- cached: payload[:name] == "CACHE",
28
- duration_ms: duration_ms,
29
- stacktrace: trace_cleaner.clean(caller),
30
- }.freeze
31
-
32
- @current_scope[:entries] << entry
33
- @root_scope[:total_queries_num] += 1
34
- end
35
-
36
- yield.tap do
37
- if parent_scope
38
- parent_scope[:total_duration_ms] += @current_scope[:total_duration_ms]
39
- @current_scope = parent_scope
40
- else
41
- Furia::Sample.create!(data: @root_scope)
42
- end
43
- end
44
- ensure
45
- ActiveSupport::Notifications.unsubscribe(subscriber)
46
- end
47
-
48
- def self.trace_cleaner
49
- @trace_cleaner ||=
50
- ActiveSupport::BacktraceCleaner.new.tap do |c|
51
- c.add_silencer { |line| line.include?("/gems/") }
52
- c.add_silencer { |line| line.include?("/ruby/") }
53
- c.add_silencer { |line| line.include?("/active_record/") }
54
- end
55
- end
56
- end
57
- end