From caa840b95506872a4b15f6a0b827178a2aa71411 Mon Sep 17 00:00:00 2001 From: sooyeon Date: Fri, 27 Aug 2021 04:25:29 +0900 Subject: [PATCH] Add a checker to calculate latency - latency: from the time to request playing, to the time to receive the 1st synthesized audio data Change-Id: I84726b3a30ff89f1530d16b82d166621924b6204 Signed-off-by: sooyeon --- server/ttsd_server.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/ttsd_server.c b/server/ttsd_server.c index b32d1a2..0701e85 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "ttsd_config.h" #include "ttsd_data.h" @@ -29,6 +30,16 @@ #define CLIENT_CLEAN_UP_TIME 500 +/* for checking time */ +#define TIME_DIFF(start, end) \ + ((uint64_t)((end).tv_sec - (start).tv_sec) * 1000000 + (((end).tv_nsec - (start).tv_nsec) / 1000)) / 1000 + +static struct timespec g_request_playing, g_start_playing; +static double g_avg_latency; +static double g_min_latency; +static double g_max_latency; +static int g_file_num; + typedef struct { int uid; int uttid; @@ -213,6 +224,16 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_START"); SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", uid, uttid, data, data_size, audio_type, rate); + + clock_gettime(CLOCK_MONOTONIC_RAW, &g_start_playing); + long long int latency = (uint64_t)TIME_DIFF(g_request_playing, g_start_playing); + SLOG(LOG_INFO, tts_tag(), "[SERVER] Latency (Request playing ~ Get 1st synthesized results): %lld ms", latency); + double d_latency = (double)latency; + g_avg_latency += d_latency; + g_min_latency = (d_latency < g_min_latency) ? d_latency : g_min_latency; + g_max_latency = (d_latency > g_max_latency) ? d_latency : g_max_latency; + g_file_num++; + SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency); } else if (TTSE_RESULT_EVENT_FINISH == event) { SLOG(LOG_INFO, tts_tag(), "[SERVER] Event : TTSE_RESULT_EVENT_FINISH"); SECURE_SLOG(LOG_DEBUG, tts_tag(), "[SERVER] Result Info : uid(%d), utt(%d), data(%p), data size(%d) audiotype(%d) rate(%d)", @@ -652,6 +673,12 @@ int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* cred return TTSD_ERROR_OPERATION_FAILED; } + g_file_num = 0; + g_min_latency = 10000.0; + g_max_latency = 0.0; + g_avg_latency = 0.0; + + return TTSD_ERROR_NONE; } @@ -779,6 +806,7 @@ void __used_voice_cb(const char* lang, int type) int ttsd_server_finalize(int uid) { SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize"); + SLOG(LOG_INFO, tts_tag(), "[Server] File num(%d), Avg Latency(%lf), Min(%lf), Max(%lf)", g_file_num, (g_avg_latency / (double)g_file_num), g_min_latency, g_max_latency); app_tts_state_e state; if (0 > ttsd_data_get_client_state(uid, &state)) { @@ -1021,6 +1049,7 @@ int ttsd_server_play(int uid, const char* credential) } /* Check whether tts-engine is running or not */ + clock_gettime(CLOCK_MONOTONIC_RAW, &g_request_playing); if (TTSD_SYNTHESIS_CONTROL_DOING == ttsd_get_synth_control()) { SLOG(LOG_WARN, tts_tag(), "[Server WARNING] Engine has already been running."); } else { -- 2.7.4