polyphony 0.55.0 → 0.59.1
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 +4 -4
- data/CHANGELOG.md +26 -0
- data/Gemfile.lock +1 -1
- data/examples/core/idle_gc.rb +21 -0
- data/examples/io/pipe.rb +11 -0
- data/examples/io/splice_chunks.rb +29 -0
- data/ext/polyphony/backend_common.c +288 -0
- data/ext/polyphony/backend_common.h +49 -130
- data/ext/polyphony/backend_io_uring.c +263 -54
- data/ext/polyphony/backend_io_uring_context.c +2 -3
- data/ext/polyphony/backend_libev.c +466 -84
- data/ext/polyphony/fiber.c +0 -2
- data/ext/polyphony/polyphony.c +17 -22
- data/ext/polyphony/polyphony.h +8 -16
- data/ext/polyphony/polyphony_ext.c +0 -4
- data/ext/polyphony/runqueue.c +17 -82
- data/ext/polyphony/runqueue.h +27 -0
- data/ext/polyphony/thread.c +10 -94
- data/lib/polyphony/core/timer.rb +2 -2
- data/lib/polyphony/extensions/fiber.rb +2 -2
- data/lib/polyphony/extensions/thread.rb +8 -0
- data/lib/polyphony/version.rb +1 -1
- data/test/test_backend.rb +91 -0
- data/test/test_thread.rb +57 -11
- data/test/test_timer.rb +7 -7
- data/test/test_trace.rb +27 -49
- metadata +7 -4
- data/ext/polyphony/tracing.c +0 -11
- data/lib/polyphony/adapters/trace.rb +0 -138
@@ -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
|