ruby_event_store-profiler 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44b9166cd97804c540e3a9988c5b75383782044dae4df8058c2095a760168c12
4
+ data.tar.gz: 9183d616252bec8b76a15fda81cccadb063ad5a3491db380577117221139c626
5
+ SHA512:
6
+ metadata.gz: ccb550ce08bc021e04a8230a5a1e8bf7794f3ff053e938901ec5a4bd6395206faece2b8dcc3c04f24bb09250440a302375070cf8cf844738e9443007a00bea6e
7
+ data.tar.gz: 59f20277f476de955569c2fb3ca0555ff187864067428634597dd2ccbe61d38c75ae118c3e9c40d2bf35663f568a9d2087ff2e5236c6a3c8f8733815a31c937d
@@ -0,0 +1,39 @@
1
+ # RubyEventStore::Profiler
2
+
3
+ Simplistic profiler hooking into RubyEventStore instrumenation infrastructure.
4
+
5
+
6
+ ```ruby
7
+ DummyEvent = Class.new(RubyEventStore::Event)
8
+
9
+ instrumenter =
10
+ ActiveSupport::Notifications
11
+ event_store =
12
+ RubyEventStore::Client.new(
13
+ repository: RubyEventStore::InstrumentedRepository.new(RubyEventStore::InMemoryRepository.new, instrumenter),
14
+ mapper: RubyEventStore::Mappers::InstrumentedMapper.new(RubyEventStore::Mappers::Default.new, instrumenter),
15
+ dispatcher: RubyEventStore::InstrumentedDispatcher.new(RubyEventStore::Dispatcher.new, instrumenter)
16
+ )
17
+
18
+ repository =
19
+ AggregateRoot::InstrumentedRepository.new(AggregateRoot::Repository.new(event_store), instrumenter)
20
+
21
+ class Bazinga
22
+ include AggregateRoot
23
+
24
+ def do_the_dummy
25
+ apply(DummyEvent.new)
26
+ end
27
+
28
+ on DummyEvent do |event|
29
+ end
30
+ end
31
+
32
+ profiler =
33
+ RubyEventStore::Profiler.new(instrumenter)
34
+ profiler.measure do
35
+ aggregate = repository.load(Bazinga.new, "bazinga")
36
+ aggregate.do_the_dummy
37
+ repository.store(aggregate, "bazinga")
38
+ end
39
+ ```
@@ -0,0 +1,49 @@
1
+ module RubyEventStore
2
+ class Profiler
3
+ METRICS = [
4
+ /rails_event_store/,
5
+ /aggregate_root/,
6
+ "total"
7
+ ].freeze
8
+ private_constant :METRICS
9
+
10
+ def initialize(instrumenter)
11
+ @instrumenter = instrumenter
12
+ end
13
+
14
+ def measure(&block)
15
+ output =
16
+ Hash.new { 0 }
17
+ subscribers =
18
+ METRICS.map do |name|
19
+ @instrumenter.subscribe(name) do |name, start, finish|
20
+ metric_name = name.split('.').first
21
+ duration = 1000.0 * (finish - start)
22
+ output[metric_name] += duration
23
+ end
24
+ end
25
+
26
+ @instrumenter.instrument('total') do
27
+ block.call
28
+ end
29
+
30
+ subscribers.each do |name|
31
+ @instrumenter.unsubscribe(name)
32
+ end
33
+
34
+ total = output.delete('total')
35
+
36
+ puts "%s %s %s" % ["metric".ljust(18), "ms".rjust(7), "%".rjust(6)]
37
+ puts "\u2500" * 33
38
+
39
+ output.each do |metric, duration|
40
+ puts "%s %7.2f %6.2f" % [metric.ljust(18), duration, (duration/total * 100)]
41
+ end
42
+
43
+ puts
44
+ puts "%s %7.2f %6.2f" % ["total".ljust(18), total, 100]
45
+
46
+ output.merge("total" => total)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module RubyEventStore
2
+ class Profiler
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_event_store-profiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arkency
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby_event_store
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ description:
34
+ email: dev@arkency.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files:
38
+ - README.md
39
+ files:
40
+ - README.md
41
+ - lib/ruby_event_store/profiler.rb
42
+ - lib/ruby_event_store/profiler/version.rb
43
+ homepage: https://railseventstore.org
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://railseventstore.org
48
+ source_code_uri: https://github.com/RailsEventStore/rails_event_store
49
+ bug_tracker_uri: https://github.com/RailsEventStore/rails_event_store/issues
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '2.5'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.1.4
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Dead-simple profiling based on instrumentation built into RubyEventStore
69
+ test_files: []