Add a checker to calculate latency 28/263128/3
authorsooyeon <sooyeon.kim@samsung.com>
Thu, 26 Aug 2021 19:25:29 +0000 (04:25 +0900)
committersooyeon <sooyeon.kim@samsung.com>
Fri, 27 Aug 2021 16:49:33 +0000 (01:49 +0900)
- latency: from the time to request playing, to the time to receive the 1st synthesized audio data

Change-Id: I84726b3a30ff89f1530d16b82d166621924b6204
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
server/ttsd_server.c

index b32d1a20cb4d2b6e11d16ded08cfb570928922a6..0701e8589b68c9c5aa074d282a204fe3515c0f81 100644 (file)
@@ -14,6 +14,7 @@
 #include <app_manager.h>
 #include <aul.h>
 #include <Ecore.h>
+#include <sys/time.h>
 
 #include "ttsd_config.h"
 #include "ttsd_data.h"
 
 #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 {