polyphony 0.58 → 0.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Gemfile.lock +15 -29
  4. data/examples/core/message_based_supervision.rb +51 -0
  5. data/examples/io/echo_server.rb +16 -7
  6. data/ext/polyphony/backend_common.c +160 -7
  7. data/ext/polyphony/backend_common.h +34 -2
  8. data/ext/polyphony/backend_io_uring.c +119 -40
  9. data/ext/polyphony/backend_io_uring_context.c +10 -1
  10. data/ext/polyphony/backend_io_uring_context.h +5 -3
  11. data/ext/polyphony/backend_libev.c +109 -31
  12. data/ext/polyphony/extconf.rb +2 -2
  13. data/ext/polyphony/fiber.c +1 -34
  14. data/ext/polyphony/polyphony.c +12 -19
  15. data/ext/polyphony/polyphony.h +9 -20
  16. data/ext/polyphony/polyphony_ext.c +0 -4
  17. data/ext/polyphony/queue.c +12 -12
  18. data/ext/polyphony/runqueue.c +21 -98
  19. data/ext/polyphony/runqueue.h +26 -0
  20. data/ext/polyphony/thread.c +6 -113
  21. data/lib/polyphony/core/timer.rb +2 -2
  22. data/lib/polyphony/extensions/fiber.rb +102 -82
  23. data/lib/polyphony/extensions/io.rb +10 -9
  24. data/lib/polyphony/extensions/openssl.rb +14 -4
  25. data/lib/polyphony/extensions/socket.rb +15 -15
  26. data/lib/polyphony/extensions/thread.rb +1 -1
  27. data/lib/polyphony/version.rb +1 -1
  28. data/polyphony.gemspec +0 -7
  29. data/test/test_backend.rb +46 -9
  30. data/test/test_ext.rb +1 -1
  31. data/test/test_fiber.rb +106 -18
  32. data/test/test_global_api.rb +1 -1
  33. data/test/test_io.rb +29 -0
  34. data/test/test_supervise.rb +100 -100
  35. data/test/test_thread.rb +5 -11
  36. data/test/test_thread_pool.rb +1 -1
  37. data/test/test_trace.rb +28 -49
  38. metadata +5 -109
  39. data/ext/polyphony/tracing.c +0 -11
  40. data/lib/polyphony/adapters/trace.rb +0 -138
@@ -1,11 +0,0 @@
1
- #include "polyphony.h"
2
-
3
- int __tracing_enabled__ = 0;
4
-
5
- VALUE __fiber_trace__(int argc, VALUE *argv, VALUE self) {
6
- return rb_ary_new4(argc, argv);
7
- }
8
-
9
- void Init_Tracing() {
10
- rb_define_global_function("__fiber_trace__", __fiber_trace__, -1);
11
- }
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../polyphony'
4
-
5
- STOCK_EVENTS = %i[line call return c_call c_return b_call b_return].freeze
6
-
7
- module Polyphony
8
- # Tracing functionality for Polyphony
9
- module Trace
10
- class << self
11
- def new(*events)
12
- start_stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
13
- events = STOCK_EVENTS if events.empty?
14
- ::TracePoint.new(*events) { |tp| yield trace_record(tp, start_stamp) }
15
- end
16
-
17
- def trace_record(trp, start_stamp)
18
- stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - start_stamp
19
-
20
- { stamp: stamp, event: trp.event, location: "#{trp.path}:#{trp.lineno}",
21
- self: trp.self, binding: trp.binding, fiber: tp_fiber(trp),
22
- lineno: trp.lineno, method_id: trp.method_id,
23
- path: trp.path, parameters: tp_params(trp),
24
- return_value: tp_return_value(trp), schedule_value: tp_schedule_value(trp),
25
- exception: tp_raised_exception(trp) }
26
- end
27
-
28
- def tp_fiber(trp)
29
- trp.is_a?(FiberTracePoint) ? trp.fiber : Fiber.current
30
- end
31
-
32
- PARAMS_EVENTS = %i[call c_call b_call].freeze
33
-
34
- def tp_params(trp)
35
- PARAMS_EVENTS.include?(trp.event) ? trp.parameters : nil
36
- end
37
-
38
- RETURN_VALUE_EVENTS = %i[return c_return b_return].freeze
39
-
40
- def tp_return_value(trp)
41
- RETURN_VALUE_EVENTS.include?(trp.event) ? trp.return_value : nil
42
- end
43
-
44
- SCHEDULE_VALUE_EVENTS = %i[fiber_schedule fiber_run].freeze
45
-
46
- def tp_schedule_value(trp)
47
- SCHEDULE_VALUE_EVENTS.include?(trp.event) ? trp.value : nil
48
- end
49
-
50
- def tp_raised_exception(trp)
51
- trp.event == :raise && trp.raised_exception
52
- end
53
-
54
- def analyze(records)
55
- by_fiber = Hash.new { |h, f| h[f] = [] }
56
- records.each_with_object(by_fiber) { |r, h| h[r[:fiber]] << r }
57
- { by_fiber: by_fiber }
58
- end
59
-
60
- # Implements fake TracePoint instances for fiber-related events
61
- class FiberTracePoint
62
- attr_reader :event, :fiber, :value
63
-
64
- def initialize(tpoint)
65
- @tp = tpoint
66
- @event = tpoint.return_value[0]
67
- @fiber = tpoint.return_value[1]
68
- @value = tpoint.return_value[2]
69
- end
70
-
71
- def lineno
72
- @tp.lineno
73
- end
74
-
75
- def method_id
76
- @tp.method_id
77
- end
78
-
79
- def path
80
- @tp.path
81
- end
82
-
83
- def self
84
- @tp.self
85
- end
86
-
87
- def binding
88
- @tp.binding
89
- end
90
- end
91
-
92
- class << ::TracePoint
93
- POLYPHONY_FILE_REGEXP = /^#{::Exception::POLYPHONY_DIR}/.freeze
94
-
95
- alias_method :orig_new, :new
96
- def new(*args, &block)
97
- events_mask, fiber_events_mask = event_masks(args)
98
-
99
- orig_new(*events_mask) do |tp|
100
- handle_tp_event(tp, fiber_events_mask, &block)
101
- end
102
- end
103
-
104
- def handle_tp_event(tpoint, fiber_events_mask)
105
- # next unless !$watched_fiber || Fiber.current == $watched_fiber
106
-
107
- if tpoint.method_id == :__fiber_trace__
108
- return if tpoint.event != :c_return
109
- return unless fiber_events_mask.include?(tpoint.return_value[0])
110
-
111
- tpoint = FiberTracePoint.new(tpoint)
112
- elsif tpoint.path =~ POLYPHONY_FILE_REGEXP
113
- return
114
- end
115
-
116
- yield tpoint
117
- end
118
-
119
- ALL_FIBER_EVENTS = %i[
120
- fiber_create fiber_terminate fiber_schedule fiber_switchpoint fiber_run
121
- fiber_event_poll_enter fiber_event_poll_leave
122
- ].freeze
123
-
124
- def event_masks(events)
125
- events.each_with_object([[], []]) do |e, masks|
126
- case e
127
- when /^fiber_/
128
- masks[1] += e == :fiber_all ? ALL_FIBER_EVENTS : [e]
129
- masks[0] << :c_return unless masks[0].include?(:c_return)
130
- else
131
- masks[0] << e
132
- end
133
- end
134
- end
135
- end
136
- end
137
- end
138
- end