Skip to content

Commit

Permalink
Add logs about duration of SDK initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
varsill committed Nov 29, 2024
1 parent 203741e commit 38c775d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
21 changes: 19 additions & 2 deletions lib/agora/agora_sink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Membrane.Agora.Sink do
"""
use Membrane.Sink

require Membrane.Logger
require Membrane.Pad, as: Pad

alias Membrane.Agora.Sink.Native
Expand Down Expand Up @@ -62,9 +63,25 @@ defmodule Membrane.Agora.Sink do

@impl true
def handle_setup(_ctx, state) do
{:ok, native_state} =
native_state =
try do
Native.create(state.app_id, state.token, state.channel_name, state.user_id)
start_time = Membrane.Time.os_time()

{:ok, native_state} =
Native.create(state.app_id, state.token, state.channel_name, state.user_id)

duration = Membrane.Time.os_time() - start_time
duration_ms = Membrane.Time.as_milliseconds(duration, :round)
Membrane.Logger.info("Agora SDK initialization took: #{duration_ms} ms")

if duration_ms > 500 do
Membrane.Logger.warning("""
Agora SDK initialization took #{duration_ms} ms which is longer than expected.
The initial demand made by this sink might be delayed.
""")
end

native_state
rescue
_e in UndefinedFunctionError ->
reraise(
Expand Down
22 changes: 20 additions & 2 deletions lib/agora/agora_source.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule Membrane.Agora.Source do
"""
use Membrane.Source

require Membrane.Logger

alias Membrane.Agora.Source.Native
alias Membrane.Buffer

Expand Down Expand Up @@ -62,9 +64,25 @@ defmodule Membrane.Agora.Source do

@impl true
def handle_playing(_ctx, state) do
{:ok, native_state} =
native_state =
try do
Native.create(state.app_id, state.token, state.channel_name, state.user_id, self())
start_time = Membrane.Time.os_time()

{:ok, native_state} =
Native.create(state.app_id, state.token, state.channel_name, state.user_id)

duration = Membrane.Time.os_time() - start_time
duration_ms = Membrane.Time.as_milliseconds(duration, :round)
Membrane.Logger.info("Agora SDK initialization took: #{duration_ms} ms")

if duration_ms > 500 do
Membrane.Logger.warning("""
Agora SDK initialization took #{duration_ms} ms which is longer than expected.
The initial demand made by this sink might be delayed.
""")
end

native_state
rescue
_e in UndefinedFunctionError ->
reraise(
Expand Down

0 comments on commit 38c775d

Please sign in to comment.