Skip to content

Commit dc77a13

Browse files
authored
Merge pull request #310 from membraneframework/release/v0.7.0
Release membrane_core v0.7.0
2 parents 72401b0 + 9b6ce64 commit dc77a13

27 files changed

+207
-140
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.0
22
jobs:
33
test:
44
docker:
5-
- image: membrane/membrane:latest
5+
- image: membraneframeworklabs/docker_membrane
66
environment:
77
MIX_ENV: test
88

@@ -17,7 +17,7 @@ jobs:
1717

1818
lint:
1919
docker:
20-
- image: membrane/bionic-membrane:latest
20+
- image: membraneframeworklabs/docker_membrane
2121
environment:
2222
MIX_ENV: dev
2323

@@ -29,6 +29,7 @@ jobs:
2929
- run: mix format --check-formatted
3030
- run: mix compile
3131
- run: mix credo
32+
- run: mix dialyzer
3233
- run: mix docs && mix docs 2>&1 | (! grep -q "warning:")
3334

3435
workflows:

lib/membrane/bin/action.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule Membrane.Bin.Action do
6565
was previously set to `:no_interval`.
6666
6767
If the `interval` is `:no_interval`, the timer won't issue any ticks until
68-
another `t:set_interval_t/0` action. Otherwise, the timer will issue ticks every
68+
another `t:timer_interval_t/0` action. Otherwise, the timer will issue ticks every
6969
new `interval`. The next tick after interval change is scheduled at
7070
`new_interval + previous_time`, where previous_time is the time of the latest
7171
tick or the time of returning `t:start_timer_t/0` action if no tick has been

lib/membrane/core/bin/state.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule Membrane.Core.Bin.State do
1414
alias Membrane.Core.Parent.Link
1515
alias Membrane.Core.Parent.ChildrenModel
1616
alias Membrane.{Child, Clock, Sync}
17+
alias Membrane.Core.Parent.CrashGroup
1718

1819
@type t :: %__MODULE__{
1920
internal_state: Membrane.Bin.state_t() | nil,

lib/membrane/core/callback_handler.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ defmodule Membrane.Core.CallbackHandler do
2424
{:ok, internal_state}
2525
| {{:ok, [action]}, internal_state}
2626
| {{:error, any}, internal_state}
27+
| {:error, any}
2728

2829
@type callback_return_t :: callback_return_t(any, any)
2930

lib/membrane/core/element/caps_controller.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Membrane.Core.Element.CapsController do
66
use Bunch
77

88
alias Membrane.{Caps, Pad}
9-
alias Membrane.Core.{CallbackHandler, InputBuffer}
9+
alias Membrane.Core.{CallbackHandler, InputBuffer, Telemetry}
1010
alias Membrane.Core.Child.PadModel
1111
alias Membrane.Core.Element.{ActionHandler, State}
1212
alias Membrane.Element.CallbackContext
@@ -19,6 +19,8 @@ defmodule Membrane.Core.Element.CapsController do
1919
"""
2020
@spec handle_caps(Pad.ref_t(), Caps.t(), State.t()) :: State.stateful_try_t()
2121
def handle_caps(pad_ref, caps, state) do
22+
Telemetry.report_metric("caps", 1, inspect(pad_ref))
23+
2224
PadModel.assert_data!(state, pad_ref, %{direction: :input})
2325
data = PadModel.get_data!(state, pad_ref)
2426

lib/membrane/core/element/demand_handler.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ defmodule Membrane.Core.Element.DemandHandler do
166166
else
167167
{{:error, reason}, state} ->
168168
Membrane.Logger.error("""
169-
Error while supplying demand on pad #{inspect(pad_ref)} of size #{
170-
inspect(pad_data.demand)
171-
}
169+
Error while supplying demand on pad #{inspect(pad_ref)} of size #{inspect(pad_data.demand)}
172170
""")
173171

174172
{{:error, {:supply_demand, reason}}, %State{state | supplying_demand?: false}}

lib/membrane/core/element/event_controller.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Membrane.Core.Element.EventController do
66
use Bunch
77

88
alias Membrane.{Event, Pad, Sync}
9-
alias Membrane.Core.{CallbackHandler, Events, InputBuffer, Message}
9+
alias Membrane.Core.{CallbackHandler, Events, InputBuffer, Message, Telemetry}
1010
alias Membrane.Core.Child.PadModel
1111
alias Membrane.Core.Element.{ActionHandler, State}
1212
alias Membrane.Element.CallbackContext
@@ -27,6 +27,8 @@ defmodule Membrane.Core.Element.EventController do
2727
"""
2828
@spec handle_event(Pad.ref_t(), Event.t(), State.t()) :: State.stateful_try_t()
2929
def handle_event(pad_ref, event, state) do
30+
Telemetry.report_metric("event", 1, inspect(pad_ref))
31+
3032
pad_data = PadModel.get_data!(state, pad_ref)
3133

3234
if not Event.async?(event) && pad_data.mode == :pull && pad_data.direction == :input &&
@@ -158,9 +160,7 @@ defmodule Membrane.Core.Element.EventController do
158160
{{:ok, :ignore}, state}
159161

160162
playback: %{state: playback_state} ->
161-
raise "Received end of stream event in an incorrect state. State: #{
162-
inspect(playback_state, pretty: true)
163-
}, on pad: #{inspect(pad_ref)}"
163+
raise "Received end of stream event in an incorrect state. State: #{inspect(playback_state, pretty: true)}, on pad: #{inspect(pad_ref)}"
164164
end
165165
end
166166

lib/membrane/core/element/lifecycle_controller.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ defmodule Membrane.Core.Element.LifecycleController do
7070
Membrane.Logger.debug("Terminating element, reason: #{inspect(reason)}")
7171
else
7272
Membrane.Logger.warn("""
73-
Terminating element possibly not prepared for termination as it was in state #{
74-
inspect(playback_state)
75-
}.
73+
Terminating element possibly not prepared for termination as it was in state #{inspect(playback_state)}.
7674
Reason: #{inspect(reason)}",
7775
State: #{inspect(state, pretty: true)}
7876
""")

lib/membrane/core/element/playback_buffer.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,11 @@ defmodule Membrane.Core.Element.PlaybackBuffer do
115115
pad_ref = Message.for_pad(msg)
116116

117117
with :ok <- PadModel.assert_data(state, pad_ref, %{direction: :output}) do
118-
Membrane.Logger.debug_verbose(
119-
"Received #{
120-
if size == 0 do
121-
"dumb demand"
122-
else
123-
"demand of size #{inspect(size)}"
124-
end
125-
} on pad #{inspect(pad_ref)}"
126-
)
118+
Membrane.Logger.debug_verbose("Received #{if size == 0 do
119+
"dumb demand"
120+
else
121+
"demand of size #{inspect(size)}"
122+
end} on pad #{inspect(pad_ref)}")
127123

128124
DemandController.handle_demand(pad_ref, size, state)
129125
end

lib/membrane/core/input_buffer.ex

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ defmodule Membrane.Core.InputBuffer do
1010
use Bunch
1111

1212
alias Membrane.Buffer
13-
alias Membrane.Core.Message
13+
alias Membrane.Core.{Message, Telemetry}
1414
alias Membrane.Pad
15-
alias Membrane.Telemetry
16-
alias Membrane.ComponentPath
1715

1816
require Membrane.Core.Message
1917
require Membrane.Logger
@@ -326,17 +324,7 @@ defmodule Membrane.Core.InputBuffer do
326324
end
327325

328326
defp report_buffer_size(method, size, %__MODULE__{log_tag: log_tag}) do
329-
:telemetry.execute(
330-
Telemetry.input_buffer_size_event_name(),
331-
%{
332-
element_path:
333-
ComponentPath.get_formatted() <>
334-
"/" <> (log_tag || ""),
335-
method: method,
336-
value: size
337-
},
338-
%{}
339-
)
327+
Telemetry.report_metric(method, size, log_tag)
340328
end
341329

342330
@spec empty?(t()) :: boolean()

lib/membrane/core/options_specs.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ defmodule Membrane.Core.OptionsSpecs do
138138
quote do
139139
"""
140140
- #{unquote(header)} \n
141-
#{
142-
unquote([spec, default_val_desc, desc])
143-
|> Enum.map_join(" \n", &Markdown.indent/1)
144-
}
141+
#{unquote([spec, default_val_desc, desc]) |> Enum.map_join(" \n", &Markdown.indent/1)}
145142
"""
146143
end
147144
end

lib/membrane/core/parent/child_life_controller.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ defmodule Membrane.Core.Parent.ChildLifeController do
103103

104104
if already_removing != [] do
105105
Membrane.Logger.warn("""
106-
Trying to remove children that are already being removed: #{
107-
Enum.map_join(already_removing, ", ", &inspect(&1.name))
108-
}. This may lead to 'unknown child' errors.
106+
Trying to remove children that are already being removed: #{Enum.map_join(already_removing, ", ", &inspect(&1.name))}. This may lead to 'unknown child' errors.
109107
""")
110108
end
111109

lib/membrane/core/parent/child_life_controller/crash_group_handler.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupHandler do
2-
@moduledoc """
3-
A module responsible for managing crash groups inside the state of pipeline.
4-
"""
2+
@moduledoc false
3+
# A module responsible for managing crash groups inside the state of pipeline.
54

65
alias Membrane.ParentSpec
6+
alias Membrane.Core.Parent
77
alias Membrane.Core.Pipeline
88
alias Membrane.Core.Parent.CrashGroup
99

@@ -65,7 +65,8 @@ defmodule Membrane.Core.Parent.ChildLifeController.CrashGroupHandler do
6565
)
6666
end
6767

68-
@spec get_group_by_member_pid(pid(), Parent.state_t()) :: {:ok, CrashGroup.t()} | :error
68+
@spec get_group_by_member_pid(pid(), Parent.state_t()) ::
69+
{:ok, CrashGroup.t()} | {:error, :not_member}
6970
def get_group_by_member_pid(member_pid, state) do
7071
crash_group =
7172
state.crash_groups

lib/membrane/core/parent/child_life_controller/link_handler.ex

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkHandler do
33

44
use Bunch
55

6-
alias Membrane.Core.{Bin, Child, Message, Parent}
6+
alias Membrane.Core.{Bin, Child, Message, Parent, Telemetry}
77
alias Membrane.Core.Child.PadModel
88
alias Membrane.Core.Parent.{CrashGroup, Link, LinkParser}
99
alias Membrane.Core.Parent.Link.Endpoint
@@ -104,9 +104,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkHandler do
104104

105105
ref: {:error, :invalid_availability} ->
106106
raise LinkError,
107-
"Dynamic pad ref #{inspect(pad_spec)} passed for static pad of bin #{
108-
inspect(state.name)
109-
}"
107+
"Dynamic pad ref #{inspect(pad_spec)} passed for static pad of bin #{inspect(state.name)}"
110108
end
111109
end
112110

@@ -127,9 +125,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkHandler do
127125

128126
ref: {:error, :invalid_availability} ->
129127
raise LinkError,
130-
"Dynamic pad ref #{inspect(pad_spec)} passed for static pad of child #{
131-
inspect(child)
132-
}"
128+
"Dynamic pad ref #{inspect(pad_spec)} passed for static pad of child #{inspect(child)}"
133129
end
134130
end
135131

@@ -142,36 +138,12 @@ defmodule Membrane.Core.Parent.ChildLifeController.LinkHandler do
142138
end
143139
end
144140

145-
defp get_public_pad_name(pad) do
146-
case pad do
147-
{:private, direction} -> direction
148-
{Membrane.Pad, {:private, direction}, ref} -> {Membrane.Pad, direction, ref}
149-
_pad -> pad
150-
end
151-
end
152-
153-
defp report_new_link(from, to) do
154-
%Endpoint{child: from_child, pad_ref: from_pad} = from
155-
%Endpoint{child: to_child, pad_ref: to_pad} = to
156-
157-
:telemetry.execute(
158-
Membrane.Telemetry.new_link_event_name(),
159-
%{
160-
parent_path: Membrane.ComponentPath.get_formatted(),
161-
from: "#{inspect(from_child)}",
162-
to: "#{inspect(to_child)}",
163-
pad_from: "#{inspect(get_public_pad_name(from_pad))}",
164-
pad_to: "#{inspect(get_public_pad_name(to_pad))}"
165-
}
166-
)
167-
end
168-
169141
defp link(%Link{from: %Endpoint{child: child}, to: %Endpoint{child: child}}, _state) do
170142
raise LinkError, "Tried to link element #{inspect(child)} with itself"
171143
end
172144

173145
defp link(%Link{from: from, to: to}, state) do
174-
report_new_link(from, to)
146+
Telemetry.report_new_link(from, to)
175147
do_link(from, to, state)
176148
end
177149

lib/membrane/core/parent/clock_handler.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ defmodule Membrane.Core.Parent.ClockHandler do
6262

6363
components ->
6464
raise ParentError, """
65-
Cannot choose clock for the parent, as multiple components provide one, namely: #{
66-
components |> Enum.map(& &1.name) |> Enum.join(", ")
67-
}. Please explicitly select the clock by setting `ParentSpec.clock_provider` parameter.
65+
Cannot choose clock for the parent, as multiple components provide one, namely: #{components |> Enum.map(& &1.name) |> Enum.join(", ")}. Please explicitly select the clock by setting `ParentSpec.clock_provider` parameter.
6866
"""
6967
end
7068
end

lib/membrane/core/telemetry.ex

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
defmodule Membrane.Core.Telemetry do
2+
@moduledoc false
3+
4+
alias Membrane.ComponentPath
5+
alias Membrane.Core.Parent.Link.Endpoint
6+
alias Membrane.Telemetry
7+
8+
require Membrane.Pad
9+
10+
@enable_telemetry Application.compile_env(:membrane_core, :enable_telemetry, false)
11+
12+
@doc """
13+
Macro for reporting metrics.
14+
15+
Provided `calculate_measurement` is a function.
16+
17+
Metrics are reported only when it is enabled in the application using Membrane Core.
18+
"""
19+
defmacro report_measurement(event_name, calculate_measurement) do
20+
if @enable_telemetry do
21+
quote do
22+
:telemetry.execute(
23+
unquote(event_name),
24+
unquote(calculate_measurement).(),
25+
%{}
26+
)
27+
end
28+
else
29+
# A hack to suppress the 'unused variable' warnings
30+
quote do
31+
fn ->
32+
_unused = unquote(event_name)
33+
_unused = unquote(calculate_measurement)
34+
end
35+
36+
:ok
37+
end
38+
end
39+
end
40+
41+
@doc """
42+
Reports metrics such as input buffer's size inside functions, incoming events and received caps.
43+
"""
44+
@spec report_metric(String.t(), integer(), String.t()) :: :ok
45+
def report_metric(metric, value, log_tag) do
46+
calculate_measurement = fn ->
47+
component_path = ComponentPath.get_formatted() <> "/" <> (log_tag || "")
48+
49+
%{
50+
component_path: component_path,
51+
metric: metric,
52+
value: value
53+
}
54+
end
55+
56+
report_measurement(
57+
Telemetry.metric_event_name(),
58+
calculate_measurement
59+
)
60+
end
61+
62+
@doc """
63+
Reports new link connection being initialized in pipeline.
64+
"""
65+
@spec report_new_link(Endpoint.t(), Endpoint.t()) :: :ok
66+
def report_new_link(from, to) do
67+
calculate_measurement = fn ->
68+
%Endpoint{child: from_child, pad_ref: from_pad} = from
69+
%Endpoint{child: to_child, pad_ref: to_pad} = to
70+
71+
%{
72+
parent_path: Membrane.ComponentPath.get_formatted(),
73+
from: "#{inspect(from_child)}",
74+
to: "#{inspect(to_child)}",
75+
pad_from: "#{inspect(get_public_pad_name(from_pad))}",
76+
pad_to: "#{inspect(get_public_pad_name(to_pad))}"
77+
}
78+
end
79+
80+
report_measurement(
81+
Telemetry.new_link_event_name(),
82+
calculate_measurement
83+
)
84+
end
85+
86+
defp get_public_pad_name(pad) do
87+
case pad do
88+
{:private, direction} -> direction
89+
{Membrane.Pad, {:private, direction}, ref} -> {Membrane.Pad, direction, ref}
90+
_pad -> pad
91+
end
92+
end
93+
end

lib/membrane/crash_group.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule Membrane.CrashGroup do
2+
@moduledoc """
3+
Module containing types and functions for operating on crash groups.
4+
"""
5+
6+
@type name_t() :: any()
7+
end

0 commit comments

Comments
 (0)