Browse Source

MT#61625 refactor stats chain code

Change-Id: Iaf7c59d94e645ab8d8516baa38445868cb818c01
pull/1918/head
Richard Fuchs 10 months ago
parent
commit
8399b36d28
3 changed files with 44 additions and 25 deletions
  1. +40
    -23
      daemon/codec.c
  2. +2
    -2
      daemon/statistics.c
  3. +2
    -0
      include/codec.h

+ 40
- 23
daemon/codec.c View File

@ -378,6 +378,9 @@ static void __handler_shutdown(struct codec_handler *handler) {
g_free(handler->stats_chain); g_free(handler->stats_chain);
handler->stats_chain = NULL; handler->stats_chain = NULL;
} }
handler->stats_chain_suffix = NULL;
handler->stats_chain_suffix_brief = NULL;
} }
static void __codec_handler_free(struct codec_handler *h) { static void __codec_handler_free(struct codec_handler *h) {
@ -450,6 +453,37 @@ static void __convert_passthrough_ssrc(struct codec_handler *handler) {
} }
static void __handler_stats_entry(struct codec_handler *handler) {
g_free(handler->stats_chain);
handler->stats_chain = g_strdup_printf(STR_FORMAT " -> " STR_FORMAT "%s",
STR_FMT(&handler->source_pt.encoding_with_params),
STR_FMT(&handler->dest_pt.encoding_with_params),
handler->stats_chain_suffix ?: "");
__auto_type stats_entry = handler->stats_entry;
if (stats_entry)
__atomic_fetch_add(&stats_entry->num_transcoders, -1, __ATOMIC_RELAXED);
{
LOCK(&rtpe_codec_stats_lock);
stats_entry = t_hash_table_lookup(rtpe_codec_stats, handler->stats_chain);
if (!stats_entry) {
stats_entry = g_new0(struct codec_stats, 1);
stats_entry->chain = g_strdup(handler->stats_chain);
t_hash_table_insert(rtpe_codec_stats, stats_entry->chain, stats_entry);
stats_entry->chain_brief = g_strdup_printf(STR_FORMAT "_" STR_FORMAT "%s",
STR_FMT(&handler->source_pt.encoding_with_params),
STR_FMT(&handler->dest_pt.encoding_with_params),
handler->stats_chain_suffix_brief ?: "");
}
handler->stats_entry = stats_entry;
}
__atomic_fetch_add(&stats_entry->num_transcoders, 1, __ATOMIC_RELAXED);
}
static void __reset_sequencer(void *p, void *dummy) { static void __reset_sequencer(void *p, void *dummy) {
struct ssrc_entry_call *s = p; struct ssrc_entry_call *s = p;
if (s->sequencers) if (s->sequencers)
@ -522,31 +556,14 @@ reset:
handler->ssrc_hash = create_ssrc_hash_full(ssrc_handler_new_func, handler); handler->ssrc_hash = create_ssrc_hash_full(ssrc_handler_new_func, handler);
const char *stats_suffix = "";
if (handler->ssrc_hash->precreat && ((struct codec_ssrc_handler *) handler->ssrc_hash->precreat)->chain)
stats_suffix = " (GPU)";
// stats entry
if (!handler->stats_chain)
handler->stats_chain = g_strdup_printf(STR_FORMAT " -> " STR_FORMAT "%s",
STR_FMT(&handler->source_pt.encoding_with_params),
STR_FMT(&dest->encoding_with_params), stats_suffix);
mutex_lock(&rtpe_codec_stats_lock);
struct codec_stats *stats_entry =
t_hash_table_lookup(rtpe_codec_stats, handler->stats_chain);
if (!stats_entry) {
stats_entry = g_slice_alloc0(sizeof(*stats_entry));
stats_entry->chain = strdup(handler->stats_chain);
t_hash_table_insert(rtpe_codec_stats, stats_entry->chain, stats_entry);
stats_entry->chain_brief = g_strdup_printf(STR_FORMAT "_" STR_FORMAT,
STR_FMT(&handler->source_pt.encoding_with_params),
STR_FMT(&dest->encoding_with_params));
if (handler->ssrc_hash->precreat
&& ((struct codec_ssrc_handler *) handler->ssrc_hash->precreat)->chain)
{
handler->stats_chain_suffix = " (GPU)";
handler->stats_chain_suffix_brief = "_gpu";
} }
handler->stats_entry = stats_entry;
mutex_unlock(&rtpe_codec_stats_lock);
__atomic_fetch_add(&stats_entry->num_transcoders, 1, __ATOMIC_RELAXED);
__handler_stats_entry(handler);
ssrc_hash_foreach(handler->media->monologue->ssrc_hash, __reset_sequencer, NULL); ssrc_hash_foreach(handler->media->monologue->ssrc_hash, __reset_sequencer, NULL);


+ 2
- 2
daemon/statistics.c View File

@ -941,9 +941,9 @@ void statistics_free(void) {
} }
static void codec_stats_free(struct codec_stats *stats_entry) { static void codec_stats_free(struct codec_stats *stats_entry) {
free(stats_entry->chain);
g_free(stats_entry->chain);
g_free(stats_entry->chain_brief); g_free(stats_entry->chain_brief);
g_slice_free1(sizeof(*stats_entry), stats_entry);
g_free(stats_entry);
} }
TYPED_GHASHTABLE_IMPL(codec_stats_ht, c_str_hash, c_str_equal, NULL, codec_stats_free) TYPED_GHASHTABLE_IMPL(codec_stats_ht, c_str_hash, c_str_equal, NULL, codec_stats_free)


+ 2
- 0
include/codec.h View File

@ -62,6 +62,8 @@ struct codec_handler {
struct delay_buffer *delay_buffer; struct delay_buffer *delay_buffer;
// stats entry // stats entry
const char *stats_chain_suffix;
const char *stats_chain_suffix_brief;
char *stats_chain; char *stats_chain;
struct codec_stats *stats_entry; struct codec_stats *stats_entry;
}; };


Loading…
Cancel
Save