diff --git a/daemon/call.c b/daemon/call.c index 48c012f85..5a881c516 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -58,6 +58,9 @@ struct iterator_helper { GSList *del_timeout; GSList *del_scheduled; uint64_t transcoded_media; + uint64_t user_streams; + uint64_t kernel_streams; + uint64_t user_kernel_streams; }; struct xmlrpc_helper { enum xmlrpc_format fmt; @@ -200,6 +203,18 @@ static void call_timer_iterator(call_t *c, struct iterator_helper *hlp) { if (css == CSS_ICE) timestamp = atomic64_get_na(&ps->media->ice_agent->last_activity); + if (PS_ISSET(ps, RTP)) { + if (rtpe_now.tv_sec - atomic64_get_na(&ps->stats_in->last_packet) < 2) { + // kernel activity + if (rtpe_now.tv_sec - atomic64_get_na(&ps->last_packet) < 2) + hlp->user_kernel_streams++; // user activity + else + hlp->kernel_streams++; + } + else if (rtpe_now.tv_sec - atomic64_get_na(&ps->last_packet) < 2) + hlp->user_streams++; // user activity + } + no_sfd: if (good) goto next; @@ -511,6 +526,10 @@ enum thread_looper_action call_timer(void) { /* stats derived while iterating calls */ RTPE_GAUGE_SET(transcoded_media, hlp.transcoded_media); /* TODO: move out from here? */ + RTPE_GAUGE_SET(userspace_streams, hlp.user_streams); + RTPE_GAUGE_SET(kernel_only_streams, hlp.kernel_streams); + RTPE_GAUGE_SET(kernel_user_streams, hlp.user_kernel_streams); + kill_calls_timer(hlp.del_scheduled, NULL); kill_calls_timer(hlp.del_timeout, rtpe_config.b2b_url); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index a2812981a..ddf996001 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1389,18 +1389,6 @@ static int __rtp_stats_pt_sort(const void *ap, const void *bp) { } -static void reset_ps_kernel_stats(struct packet_stream *ps) { - if (bf_clear(&ps->stats_flags, PS_STATS_KERNEL_COUNTED)) - RTPE_GAUGE_DEC(kernel_only_streams); - if (bf_clear(&ps->stats_flags, PS_STATS_USERSPACE_COUNTED)) - RTPE_GAUGE_DEC(userspace_streams); - if (bf_clear(&ps->stats_flags, PS_STATS_MIXED_COUNTED)) - RTPE_GAUGE_DEC(kernel_user_streams); - - bf_clear(&ps->stats_flags, PS_STATS_KERNEL | PS_STATS_USERSPACE); -} - - /** * The linkage between userspace and kernel module is in the kernelize_one(). * @@ -1657,8 +1645,6 @@ void kernelize(struct packet_stream *stream) { if (PS_ISSET(stream, KERNELIZED)) return; - reset_ps_kernel_stats(stream); - if (call->recording != NULL && !selected_recording_method->kernel_support) goto no_kernel; if (!kernel.is_wanted) @@ -1816,8 +1802,6 @@ static void __stream_update_stats(struct packet_stream *ps) { /* must be called with in_lock held or call->master_lock held in W */ void __unkernelize(struct packet_stream *p, const char *reason) { - reset_ps_kernel_stats(p); - if (!p->selected_sfd) return; @@ -2639,55 +2623,6 @@ static int media_packet_queue_dup(codec_packet_q *q) { return 0; } -/** - * reverse of count_stream_stats_kernel() - */ -static void count_stream_stats_userspace(struct packet_stream *ps) { - if (!PS_ISSET(ps, RTP)) - return; - if (bf_set(&ps->stats_flags, PS_STATS_USERSPACE)) - return; // flag was already set, nothing to do - - if (bf_isset(&ps->stats_flags, PS_STATS_KERNEL)) { - // mixed stream. count as only mixed stream. - if (bf_clear(&ps->stats_flags, PS_STATS_USERSPACE_COUNTED)) - RTPE_GAUGE_DEC(userspace_streams); - if (bf_clear(&ps->stats_flags, PS_STATS_KERNEL_COUNTED)) - RTPE_GAUGE_DEC(kernel_only_streams); - if (!bf_set(&ps->stats_flags, PS_STATS_MIXED_COUNTED)) - RTPE_GAUGE_INC(kernel_user_streams); - } - else { - // userspace-only (for now). count it. - if (!bf_set(&ps->stats_flags, PS_STATS_USERSPACE_COUNTED)) - RTPE_GAUGE_INC(userspace_streams); - } -} -/** - * reverse of count_stream_stats_userspace() - */ -static void count_stream_stats_kernel(struct packet_stream *ps) { - if (!PS_ISSET(ps, RTP)) - return; - if (bf_set(&ps->stats_flags, PS_STATS_KERNEL)) - return; // flag was already set, nothing to do - - if (bf_isset(&ps->stats_flags, PS_STATS_USERSPACE)) { - // mixed stream. count as only mixed stream. - if (bf_clear(&ps->stats_flags, PS_STATS_KERNEL_COUNTED)) - RTPE_GAUGE_DEC(kernel_only_streams); - if (bf_clear(&ps->stats_flags, PS_STATS_USERSPACE_COUNTED)) - RTPE_GAUGE_DEC(userspace_streams); - if (!bf_set(&ps->stats_flags, PS_STATS_MIXED_COUNTED)) - RTPE_GAUGE_INC(kernel_user_streams); - } - else { - // kernel-only (for now). count it. - if (!bf_set(&ps->stats_flags, PS_STATS_KERNEL_COUNTED)) - RTPE_GAUGE_INC(kernel_only_streams); - } -} - /** * Packet handling starts in stream_packet(). * @@ -2841,9 +2776,6 @@ static int stream_packet(struct packet_handler_ctx *phc) { RTPE_STATS_INC(packets_user); RTPE_STATS_ADD(bytes_user, phc->s.len); - if (!PS_ISSET(phc->mp.stream, KERNELIZED) || rtpe_now.tv_sec > phc->mp.stream->kernel_time + 1) - count_stream_stats_userspace(phc->mp.stream); - ///////////////// EGRESS HANDLING str orig_raw = STR_NULL; @@ -3453,12 +3385,6 @@ enum thread_looper_action kernel_stats_updater(void) { goto next; } - // stats_in->last_packet is updated by the kernel only, so we can use it - // to count kernel streams - if (rtpe_now.tv_sec - atomic64_get_na(&ps->stats_in->last_packet) < 2) { - count_stream_stats_kernel(ps); - } - bool update = false; bool active_media = (rtpe_now.tv_sec - packet_stream_last_packet(ps) < 1); diff --git a/include/call.h b/include/call.h index 0f3cf521d..2d218ccdd 100644 --- a/include/call.h +++ b/include/call.h @@ -202,13 +202,6 @@ enum { #define PS_FLAG_PIERCE_NAT 0x08000000 #define PS_FLAG_NAT_WAIT 0x10000000 -// packet_stream stats_flags -#define PS_STATS_USERSPACE 0x00000001 -#define PS_STATS_KERNEL 0x00000002 -#define PS_STATS_USERSPACE_COUNTED 0x00000004 -#define PS_STATS_KERNEL_COUNTED 0x00000008 -#define PS_STATS_MIXED_COUNTED 0x00000010 - /* struct call_media */ #define MEDIA_FLAG_INITIALIZED 0x00010000 #define MEDIA_FLAG_ASYMMETRIC SHARED_FLAG_ASYMMETRIC @@ -470,7 +463,6 @@ struct packet_stream { atomic64 last_packet; // userspace only GHashTable *rtp_stats; /* LOCK: call->master_lock */ struct rtp_stats *rtp_stats_cache; - atomic64 stats_flags; enum endpoint_learning el_flags; #if RTP_LOOP_PROTECT