Skip to content

Commit ea8ead4

Browse files
translate.c: implement new direct comp table mode
The new mode lists for each codec translation the actual real cost in cpu microseconds per second translated audio. This allows to compare the real cpu usage of translations and helps in evaluation of codec implementation changes regarding performance (regression testing). - add new table mode - hide the 999999 comp values, as these only indicate an issue with transcoding - hide the 0 values, as these also do not contain any information (only indicate a multistep transcoding) Resolves: #601
1 parent 8d79e65 commit ea8ead4

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

main/translate.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static AST_RWLIST_HEAD_STATIC(translators, ast_translator);
5959
struct translator_path {
6060
struct ast_translator *step; /*!< Next step translator */
6161
uint32_t table_cost; /*!< Complete table cost to destination */
62+
uint32_t comp_cost; /*!< Complete table cost to destination */
6263
uint8_t multistep; /*!< Multiple conversions required for this translation */
6364
};
6465

@@ -858,6 +859,7 @@ static void matrix_rebuild(int samples)
858859

859860
matrix_get(x, z)->step = t;
860861
matrix_get(x, z)->table_cost = t->table_cost;
862+
matrix_get(x, z)->comp_cost = t->comp_cost;
861863
}
862864
}
863865

@@ -987,7 +989,7 @@ static void handle_cli_recalc(struct ast_cli_args *a)
987989

988990
static char *handle_show_translation_table(struct ast_cli_args *a)
989991
{
990-
int x, y, i, k;
992+
int x, y, i, k, compCost;
991993
int longest = 7; /* slin192 */
992994
int max_codec_index = 0, curlen = 0;
993995
struct ast_str *out = ast_str_create(1024);
@@ -1056,7 +1058,16 @@ static char *handle_show_translation_table(struct ast_cli_args *a)
10561058

10571059
if (x >= 0 && y >= 0 && matrix_get(x, y)->step) {
10581060
/* Actual codec output */
1059-
ast_str_append(&out, 0, "%*u", curlen + 1, (matrix_get(x, y)->table_cost/100));
1061+
if (a->argv[3] && !strcasecmp(a->argv[3], "comp")) {
1062+
compCost = matrix_get(x, y)->comp_cost;
1063+
if (compCost == 0 || compCost == 999999) {
1064+
ast_str_append(&out, 0, "%*s", curlen + 1, "-");
1065+
} else {
1066+
ast_str_append(&out, 0, "%*u", curlen + 1, compCost);
1067+
}
1068+
} else {
1069+
ast_str_append(&out, 0, "%*u", curlen + 1, (matrix_get(x, y)->table_cost / 100));
1070+
}
10601071
} else if (i == 0 && k > 0) {
10611072
/* Top row - use a dynamic size */
10621073
if (!strcmp(col->name, "slin") ||
@@ -1163,22 +1174,28 @@ static char *handle_show_translation_path(struct ast_cli_args *a, const char *co
11631174

11641175
static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
11651176
{
1166-
static const char * const option[] = { "recalc", "paths", NULL };
1177+
static const char * const option[] = { "recalc", "paths", "comp", NULL };
11671178

11681179
switch (cmd) {
11691180
case CLI_INIT:
11701181
e->command = "core show translation";
11711182
e->usage =
1172-
"Usage: 'core show translation' can be used in two ways.\n"
1173-
" 1. 'core show translation [recalc [<recalc seconds>]]\n"
1183+
"Usage: 'core show translation' can be used in three ways.\n"
1184+
" 1. 'core show translation [recalc [<recalc seconds>]\n"
11741185
" Displays known codec translators and the cost associated\n"
11751186
" with each conversion. If the argument 'recalc' is supplied along\n"
11761187
" with optional number of seconds to test a new test will be performed\n"
11771188
" as the chart is being displayed.\n"
11781189
" 2. 'core show translation paths [codec [sample_rate]]'\n"
11791190
" This will display all the translation paths associated with a codec.\n"
11801191
" If a codec has multiple sample rates, the sample rate must be\n"
1181-
" provided as well.\n";
1192+
" provided as well.\n"
1193+
" 3. 'core show translation comp [<recalc seconds>]'\n"
1194+
" Displays known codec translators and the cost associated\n"
1195+
" with each conversion. If the argument 'recalc' is supplied along\n"
1196+
" with optional number of seconds to test a new test will be performed\n"
1197+
" as the chart is being displayed. The resulting numbers in the table\n"
1198+
" give the actual computational costs in microseconds.\n";
11821199
return NULL;
11831200
case CLI_GENERATE:
11841201
if (a->pos == 3) {
@@ -1203,7 +1220,7 @@ static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd,
12031220
return CLI_FAILURE;
12041221
}
12051222
return handle_show_translation_path(a, a->argv[4], sample_rate);
1206-
} else if (a->argv[3] && !strcasecmp(a->argv[3], option[0])) { /* recalc and then fall through to show table */
1223+
} else if (a->argv[3] && (!strcasecmp(a->argv[3], option[0]) || !strcasecmp(a->argv[3], option[2]))) { /* recalc and then fall through to show table */
12071224
handle_cli_recalc(a);
12081225
} else if (a->argc > 3) { /* wrong input */
12091226
return CLI_SHOWUSAGE;

0 commit comments

Comments
 (0)