test: measure total latency correctly
authorInki Dae <inki.dae@samsung.com>
Mon, 5 Oct 2020 05:38:44 +0000 (14:38 +0900)
committerInki Dae <inki.dae@samsung.com>
Mon, 5 Oct 2020 05:38:44 +0000 (14:38 +0900)
Change-Id: Iaa55d24f5c594d31882849e8f92c500fe5114e68
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/testsuites/stream_infer/stream_infer.c
test/testsuites/stream_infer/stream_infer_common_util.h

index ccceab250425e5ec45b3ef5df851758a63e6dd0f..55d7fcaef8120b482c2eea1bc4c44775140b0d00 100644 (file)
@@ -182,6 +182,9 @@ typedef struct
 
 static HandOffData hdata_p;
 
+// Point to current user spack point which has camera image source to be inferenced.
+static user_stack_t current_data_p;
+
 static GMutex pose_mutex;
 static guint old_timeout = 0;
 static guint nFrames = 0;
@@ -350,8 +353,16 @@ void _hand_pose_cb (
                //printf("(%d,%d): %f\n", humanSkeleton.pose[n].x, humanSkeleton.pose[n].y, confidences[n]);
                //printf("(%d,%d)\n", humanSkeleton.pose[n].x, humanSkeleton.pose[n].y);
        }
+
        humanSkeleton.label = label;
        humanSkeleton.IsDetected = true;
+
+       struct timespec e_time;
+       clock_gettime(CLOCK_MONOTONIC, &e_time);
+
+       struct timespec diffspec = diff(current_data_p.s_time, e_time);
+       unsigned long timeDiff = gettotalmillisec(diffspec);
+       printf("elapsed time: %lu(ms)\n", timeDiff);
 }
 
 static void _hand_detected_cb (
@@ -389,34 +400,13 @@ static void _hand_detected_cb (
                return;
        }
 
-
-       struct timespec s_tspec;
-       struct timespec e_tspec;
-
-       clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-
        mv_source_clear(mv_src_p2);
        mv_source_fill_by_tensor_buffer(mv_src_p2, user_data,
                                        MV_INFERENCE_DATA_FLOAT32,
                                        56 * 56 * 21 * sizeof(float),
                                        56, 56, 21, 3);
 
-       clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-
-       struct timespec diffspec = diff(s_tspec, e_tspec);
-       unsigned long timeDiff = gettotalmillisec(diffspec);
-       printf("memcpy time: %lu(ms)\n", timeDiff);
-
-       clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-
        mv_inference_pose_landmark_detect(mv_src_p2, hp_mv_infer2, NULL,  _hand_pose_cb, NULL);
-
-       clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-
-       diffspec = diff(s_tspec, e_tspec);
-       timeDiff = gettotalmillisec(diffspec);
-       printf("pose_estimation time: %lu(ms)\n", timeDiff);
-       //humanSkeleton.IsDetected = true;
 #endif
        return;
 }
@@ -454,6 +444,22 @@ void _human_pose_cb (
 
        }
        humanSkeleton.IsDetected = true;
+
+       struct timespec e_time;
+       clock_gettime(CLOCK_MONOTONIC, &e_time);
+
+       struct timespec diffspec = diff(current_data_p.s_time, e_time);
+       unsigned long timeDiff = gettotalmillisec(diffspec);
+       printf("elapsed time: %lu(ms)\n", timeDiff);
+
+//     user_stack_t *s = (user_stack_t *)user_data;
+
+//     struct timespec e_time;
+//     clock_gettime(CLOCK_MONOTONIC, &e_time);
+
+//     struct timespec diffspec = diff(s->s_time, e_time);
+//     unsigned long timeDiff = gettotalmillisec(diffspec);
+//     printf("elapsed time: %lu(ms)\n", timeDiff);
 }
 
 static gboolean
@@ -488,19 +494,11 @@ run_pose (void *user_data)
 
                gst_buffer_unmap((GstBuffer *)s->buffer, &map);
 
-               g_mutex_unlock(&pose_mutex);
-
-               struct timespec s_tspec;
-               struct timespec e_tspec;
+               current_data_p = *s;
 
-               clock_gettime(CLOCK_MONOTONIC, &s_tspec);
-
-               mv_inference_pose_landmark_detect(mv_src_p, hp_mv_infer, &poseRoi, _human_pose_cb, NULL);
+               g_mutex_unlock(&pose_mutex);
 
-               clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-               struct timespec diffspec = diff(s_tspec, e_tspec);
-               unsigned long timeDiff = gettotalmillisec(diffspec);
-               printf("detect + pose time: %lu(ms)\n", timeDiff);
+               mv_inference_pose_landmark_detect(mv_src_p, hp_mv_infer, &poseRoi, _human_pose_cb, s->user_data);
        }
 
        return FALSE;
@@ -538,22 +536,12 @@ run_hand (void *user_data)
 
                gst_buffer_unmap((GstBuffer *)s->buffer, &map);
 
-               g_mutex_unlock(&pose_mutex);
-
-               struct timespec s_tspec;
-               struct timespec e_tspec;
+               current_data_p = *s;
 
-               void *outputTensorBuffer = s->user_data;
-
-               clock_gettime(CLOCK_MONOTONIC, &s_tspec);
+               g_mutex_unlock(&pose_mutex);
 
                // invoke tflite -> _hand_detected_cb -> memcpy output -> invoke tflite -> _pose_cb
-               mv_inference_hand_detect(mv_src_p, hp_mv_infer, _hand_detected_cb, outputTensorBuffer);
-
-               clock_gettime(CLOCK_MONOTONIC, &e_tspec);
-               struct timespec diffspec = diff(s_tspec, e_tspec);
-               unsigned long timeDiff = gettotalmillisec(diffspec);
-               printf("detect + pose time: %lu(ms)\n", timeDiff);
+               mv_inference_hand_detect(mv_src_p, hp_mv_infer, _hand_detected_cb, (void *)s->user_data);
        }
 
        return FALSE;
@@ -569,6 +557,7 @@ _pose_est_handoff(GstElement *object, GstBuffer *buffer, GstPad *pad, gpointer u
 
        g_mutex_lock(&pose_mutex);
        PushBuffer(s);
+       clock_gettime(CLOCK_MONOTONIC, &s->s_time);
        g_mutex_unlock(&pose_mutex);
 }
 
@@ -582,6 +571,7 @@ _hand_est_handoff(GstElement *object, GstBuffer *buffer, GstPad *pad, gpointer u
 
        g_mutex_lock(&pose_mutex);
        PushBuffer(s);
+       clock_gettime(CLOCK_MONOTONIC, &s->s_time);
        g_mutex_unlock(&pose_mutex);
 }
 
index b1b44c0c1d061362273fc188adedf488134c0402..45946af4e466a907094a2a1ff610d9efd323beb5 100644 (file)
@@ -1,6 +1,9 @@
+#include <time.h>
+
 typedef struct STACK {
        void *buffer;
        void *user_data;
+       struct timespec s_time;
 } user_stack_t;
 
 void InitProfiler(void);