Skip to content

Commit 5cf75f9

Browse files
func_frame_trace: Add CLI command to dump frame queue.
This adds a simple CLI command that can be used for analyzing all frames currently queued to a channel. A couple log messages are also adjusted to be more useful in tracing bridging problems. Resolves: #533
1 parent 09052bf commit 5cf75f9

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

funcs/func_frame_trace.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "asterisk/channel.h"
3636
#include "asterisk/pbx.h"
3737
#include "asterisk/framehook.h"
38+
#include "asterisk/cli.h"
3839

3940
/*** DOCUMENTATION
4041
<function name="FRAME_TRACE" language="en_US">
@@ -438,14 +439,64 @@ static struct ast_custom_function frame_trace_function = {
438439
.write = frame_trace_helper,
439440
};
440441

442+
static char *handle_dump_frames(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
443+
{
444+
struct ast_channel *chan;
445+
struct ast_frame *f;
446+
int c = 1;
447+
448+
switch (cmd) {
449+
case CLI_INIT:
450+
e->command = "channel dump frames";
451+
e->usage =
452+
"Usage: channel dump frames <channel>\n"
453+
" List all frames queued to a channel.\n";
454+
return NULL;
455+
case CLI_GENERATE:
456+
return ast_complete_channels(a->line, a->word, a->pos, a->n, 3);
457+
}
458+
459+
if (a->argc != 4) {
460+
return CLI_SHOWUSAGE;
461+
}
462+
463+
chan = ast_channel_get_by_name(a->argv[3]);
464+
if (!chan) {
465+
ast_cli(a->fd, "%s is not a known channel\n", a->argv[3]);
466+
return CLI_SUCCESS;
467+
}
468+
469+
ast_channel_lock(chan);
470+
471+
ast_cli(a->fd, "== Frame list for %s ==\n", ast_channel_name(chan));
472+
ast_cli(a->fd, "%5s %6s %6s %-15s (%-20s) - %s\n", "#", "Seqno", "Stream", "Frame Type", "Frame Subclass", "Src");
473+
AST_LIST_TRAVERSE(ast_channel_readq(chan), f, frame_list) {
474+
char type[64];
475+
char subclass[64];
476+
ast_frame_type2str(f->frametype, type, sizeof(type));
477+
ast_frame_subclass2str(f, subclass, sizeof(subclass), NULL, 0);
478+
ast_cli(a->fd, "%5d %6d %6d %-15s (%-20s) - %s\n", c++, f->seqno, f->stream_num, type, subclass, S_OR(f->src, ""));
479+
}
480+
481+
ast_channel_unlock(chan);
482+
ast_channel_unref(chan);
483+
return CLI_SUCCESS;
484+
}
485+
486+
static struct ast_cli_entry cli_frames[] = {
487+
AST_CLI_DEFINE(handle_dump_frames, "Display frames queued on a specific channel")
488+
};
489+
441490
static int unload_module(void)
442491
{
492+
ast_cli_unregister_multiple(cli_frames, ARRAY_LEN(cli_frames));
443493
return ast_custom_function_unregister(&frame_trace_function);
444494
}
445495

446496
static int load_module(void)
447497
{
448498
int res = ast_custom_function_register(&frame_trace_function);
499+
res |= ast_cli_register_multiple(cli_frames, ARRAY_LEN(cli_frames));
449500
return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
450501
}
451502

main/channel.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,11 @@ static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, in
10801080
}
10811081

10821082
if ((queued_frames + new_frames > 128 || queued_voice_frames + new_voice_frames > 96)) {
1083+
int total_queued = queued_frames + new_frames;
1084+
int total_voice = queued_voice_frames + new_voice_frames;
10831085
int count = 0;
1084-
ast_log(LOG_WARNING, "Exceptionally long %squeue length queuing to %s\n", queued_frames + new_frames > 128 ? "" : "voice ", ast_channel_name(chan));
1086+
ast_log(LOG_WARNING, "Exceptionally long %squeue length (%d voice / %d total) queuing to %s\n",
1087+
queued_frames + new_frames > 128 ? "" : "voice ", total_voice, total_queued, ast_channel_name(chan));
10851088
AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_readq(chan), cur, frame_list) {
10861089
/* Save the most recent frame */
10871090
if (!AST_LIST_NEXT(cur, frame_list)) {
@@ -1098,6 +1101,9 @@ static int __ast_queue_frame(struct ast_channel *chan, struct ast_frame *fin, in
10981101
}
10991102
}
11001103
AST_LIST_TRAVERSE_SAFE_END;
1104+
if (count) {
1105+
ast_debug(4, "Discarded %d frame%s due to queue overload on %s\n", count, ESS(count), ast_channel_name(chan));
1106+
}
11011107
}
11021108

11031109
if (after) {

0 commit comments

Comments
 (0)