Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional telemetry events #879

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/membrane/bin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ defmodule Membrane.Bin do

Membrane.Core.Child.PadsSpecs.ensure_default_membrane_pads()

@doc false
@spec membrane_component_type() :: :pipeline | :bin | :element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NIT] Technically speaking, Membrane.Bin.membrane_component_type() always returns :bin, so the typespec should be slightly different

def membrane_component_type, do: :bin

@doc false
@spec membrane_bin?() :: true
def membrane_bin?, do: true
Expand Down
17 changes: 16 additions & 1 deletion lib/membrane/core/callback_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,22 @@ defmodule Membrane.Core.CallbackHandler do

callback_result =
try do
apply(module, callback, args)
telemetry_metadata = %{
callback_args: args,
component_state: state
}

:telemetry.execute([:membrane, callback, :start], %{}, telemetry_metadata)

{duration, result} = :timer.tc(module, callback, args)

:telemetry.execute(
[:membrane, callback, :stop],
%{duration: duration},
telemetry_metadata
)

result
rescue
e in UndefinedFunctionError ->
_ignored =
Expand Down
61 changes: 55 additions & 6 deletions lib/membrane/core/parent/child_life_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,14 @@ defmodule Membrane.Core.Parent.ChildLifeController do
end)
end

do_proceed_spec_startup(spec_ref, %{spec_data | status: :initializing}, state)
spec_data = %{spec_data | status: :initializing}

:telemetry.execute([:membrane, :spec, :initializing], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
end

defp do_proceed_spec_startup(spec_ref, %{status: :initializing} = spec_data, state) do
Expand All @@ -346,7 +353,14 @@ defmodule Membrane.Core.Parent.ChildLifeController do
Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to initialized")

state = handle_children_setup_completed(spec_data.children_names, state)
do_proceed_spec_startup(spec_ref, %{spec_data | status: :initialized}, state)
spec_data = %{spec_data | status: :initialized}

:telemetry.execute([:membrane, :spec, :initialized], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
else
{spec_data, state}
end
Expand Down Expand Up @@ -374,6 +388,12 @@ defmodule Membrane.Core.Parent.ChildLifeController do
}

Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to linking internally")

:telemetry.execute([:membrane, :spec, :linking_internally], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
end

Expand All @@ -385,7 +405,15 @@ defmodule Membrane.Core.Parent.ChildLifeController do
|> Enum.reduce(state, &LinkUtils.link/2)

Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to linked internally")
do_proceed_spec_startup(spec_ref, %{spec_data | status: :linked_internally}, state)

spec_data = %{spec_data | status: :linked_internally}

:telemetry.execute([:membrane, :spec, :linked_internally], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
else
{spec_data, state}
end
Expand All @@ -398,7 +426,14 @@ defmodule Membrane.Core.Parent.ChildLifeController do
) do
Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to ready")
state = remove_spec_from_dependencies(spec_ref, state)
do_proceed_spec_startup(spec_ref, %{spec_data | status: :ready}, state)
spec_data = %{spec_data | status: :ready}

:telemetry.execute([:membrane, :spec, :ready], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
end

defp do_proceed_spec_startup(
Expand All @@ -409,7 +444,14 @@ defmodule Membrane.Core.Parent.ChildLifeController do
state = Bin.PadController.respond_links(spec_ref, state)
state = remove_spec_from_dependencies(spec_ref, state)
Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to linking externally")
do_proceed_spec_startup(spec_ref, %{spec_data | status: :linking_externally}, state)
spec_data = %{spec_data | status: :linking_externally}

:telemetry.execute([:membrane, :spec, :linking_externally], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
end

defp do_proceed_spec_startup(
Expand All @@ -419,7 +461,14 @@ defmodule Membrane.Core.Parent.ChildLifeController do
) do
if Bin.PadController.all_pads_linked?(spec_ref, state) do
Membrane.Logger.debug("Spec #{inspect(spec_ref)} status changed to ready")
do_proceed_spec_startup(spec_ref, %{spec_data | status: :ready}, state)
spec_data = %{spec_data | status: :ready}

:telemetry.execute([:membrane, :spec, :ready], %{}, %{
spec_data: spec_data,
component_state: state
})

do_proceed_spec_startup(spec_ref, spec_data, state)
else
{spec_data, state}
end
Expand Down
1 change: 1 addition & 0 deletions lib/membrane/core/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ defmodule Membrane.Core.Pipeline do

state = %State{
module: params.module,
name: params.name,
synchronization: %{
clock_proxy: clock_proxy,
clock_provider: %{clock: nil, provider: nil},
Expand Down
2 changes: 2 additions & 0 deletions lib/membrane/core/pipeline/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule Membrane.Core.Pipeline.State do

@type t :: %__MODULE__{
module: module,
name: term(),
playback: Membrane.Playback.t(),
internal_state: Membrane.Pipeline.state() | nil,
children: ChildrenModel.children(),
Expand Down Expand Up @@ -45,6 +46,7 @@ defmodule Membrane.Core.Pipeline.State do
# importance and possibly near other related fields.

defstruct module: nil,
name: nil,
playback: :stopped,
internal_state: nil,
children: %{},
Expand Down
4 changes: 4 additions & 0 deletions lib/membrane/element/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ defmodule Membrane.Element.Base do

unquote(bring_pad)

@doc false
@spec membrane_component_type() :: :pipeline | :bin | :element
def membrane_component_type, do: :element

@doc false
@spec membrane_element?() :: true
def membrane_element?, do: true
Expand Down
5 changes: 5 additions & 0 deletions lib/membrane/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ defmodule Membrane.Pipeline do
name =
case Keyword.fetch(process_options, :name) do
{:ok, name} when is_atom(name) -> Atom.to_string(name)
{:ok, {:via, Registry, {_registry, name}}} -> name
_other -> nil
end
|> case do
Expand Down Expand Up @@ -512,6 +513,10 @@ defmodule Membrane.Pipeline do
}
end

@doc false
@spec membrane_component_type() :: :pipeline | :bin | :element
def membrane_component_type, do: :pipeline

@doc false
@spec membrane_pipeline?() :: true
def membrane_pipeline?, do: true
Expand Down
Loading