Packages
membrane_core
0.7.0
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.7
1.2.6
1.2.5
retired
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.2.0-rc1
1.1.2
1.1.1
1.1.0
1.1.0-rc1
1.1.0-rc0
1.0.1
1.0.0
1.0.0-rc1
1.0.0-rc0
0.12.9
0.12.8
0.12.7
0.12.6
0.12.5
0.12.4
0.12.3
0.12.2
0.12.1
0.12.0
retired
0.11.5
0.11.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.9.0
0.8.2
0.8.1
0.8.0
0.7.0
0.6.1
0.6.0
0.5.3
0.5.2
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Membrane Multimedia Framework (Core)
Current section
Files
Jump to
Current section
Files
lib/membrane/core/telemetry.ex
defmodule Membrane.Core.Telemetry do
@moduledoc false
alias Membrane.ComponentPath
alias Membrane.Core.Parent.Link.Endpoint
alias Membrane.Telemetry
require Membrane.Pad
@enable_telemetry Application.compile_env(:membrane_core, :enable_telemetry, false)
@doc """
Macro for reporting metrics.
Provided `calculate_measurement` is a function.
Metrics are reported only when it is enabled in the application using Membrane Core.
"""
defmacro report_measurement(event_name, calculate_measurement) do
if @enable_telemetry do
quote do
:telemetry.execute(
unquote(event_name),
unquote(calculate_measurement).(),
%{}
)
end
else
# A hack to suppress the 'unused variable' warnings
quote do
fn ->
_unused = unquote(event_name)
_unused = unquote(calculate_measurement)
end
:ok
end
end
end
@doc """
Reports metrics such as input buffer's size inside functions, incoming events and received caps.
"""
@spec report_metric(String.t(), integer(), String.t()) :: :ok
def report_metric(metric, value, log_tag) do
calculate_measurement = fn ->
component_path = ComponentPath.get_formatted() <> "/" <> (log_tag || "")
%{
component_path: component_path,
metric: metric,
value: value
}
end
report_measurement(
Telemetry.metric_event_name(),
calculate_measurement
)
end
@doc """
Reports new link connection being initialized in pipeline.
"""
@spec report_new_link(Endpoint.t(), Endpoint.t()) :: :ok
def report_new_link(from, to) do
calculate_measurement = fn ->
%Endpoint{child: from_child, pad_ref: from_pad} = from
%Endpoint{child: to_child, pad_ref: to_pad} = to
%{
parent_path: Membrane.ComponentPath.get_formatted(),
from: "#{inspect(from_child)}",
to: "#{inspect(to_child)}",
pad_from: "#{inspect(get_public_pad_name(from_pad))}",
pad_to: "#{inspect(get_public_pad_name(to_pad))}"
}
end
report_measurement(
Telemetry.new_link_event_name(),
calculate_measurement
)
end
defp get_public_pad_name(pad) do
case pad do
{:private, direction} -> direction
{Membrane.Pad, {:private, direction}, ref} -> {Membrane.Pad, direction, ref}
_pad -> pad
end
end
end