[WIP-04] Add timer
authorTae-Young Chung <ty83.chung@samsung.com>
Mon, 22 Apr 2024 01:39:24 +0000 (10:39 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Mon, 22 Apr 2024 01:39:24 +0000 (10:39 +0900)
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
inference/backends/mediavision/src/MvFaceDetectionTask.cpp
inference/backends/mediavision/src/MvFaceLandmarkDetectionTask.cpp
log/include/SingleoTimer.h [new file with mode: 0644]

index 6d667559e711a11561f37794c8ac779afabc0f45..672fa67885431e13fe044df0559082cd925091bf 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdexcept>
 #include "MvFaceDetectionTask.h"
+#include "SingleoTimer.h"
 
 using namespace std;
 
@@ -54,6 +55,7 @@ FaceResult& MvFaceDetectionTask::handle(unsigned char* data, unsigned int width,
 {
     SINGLEO_LOGD("MvFaceDetectionTask::handle()");
 
+       Timer timer;
     int ret = mv_source_fill_by_buffer(_mv_src, data, width * height * byte_per_pixel, width,
                                                                           height, MEDIA_VISION_COLORSPACE_RGB888);
        if (ret != MEDIA_VISION_ERROR_NONE)
@@ -79,8 +81,8 @@ FaceResult& MvFaceDetectionTask::handle(unsigned char* data, unsigned int width,
                result._rects.push_back(rect);
                SINGLEO_LOGD("idx[%2zd]: (%3zd, %3zd, %3zd, %3zd)", idx, rect.left, rect.top, rect.right, rect.bottom);
        }
+       SINGLEO_LOGD("MvFaceDectectionTask::handle() takes %d ms", timer.check_ms());
     result = MvFaceTaskManager::handle(data, width, height, byte_per_pixel, result);
-    
     return result;
 }
 
index 08dc8dd515955fc4df88420eca32a99e29fc072a..d87de1d89dd7655318ee262f33fb6e5e627b7468 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdexcept>
 #include <opencv2/core.hpp>
 #include "MvFaceLandmarkDetectionTask.h"
+#include "SingleoTimer.h"
 
 using namespace std;
 
@@ -55,6 +56,7 @@ FaceResult& MvFaceLandmarkDetectionTask::handle(unsigned char* data, unsigned in
 {
     SINGLEO_LOGD("MvFaceLandmarkDetectionTask::handle()");
 
+       Timer timer;
        cv::Mat cvData(cv::Size(width, height), CV_MAKE_TYPE(CV_8U, byte_per_pixel), data);
        cv::Mat roiCvData;
 
@@ -97,6 +99,7 @@ FaceResult& MvFaceLandmarkDetectionTask::handle(unsigned char* data, unsigned in
                        result = MvFaceTaskManager::handle(data, width, height, byte_per_pixel, result);
                }
        }
+       SINGLEO_LOGD("MvFaceLandmarkDetectionTask::handle() takes %d ms", timer.check_ms());
     return result;
 }
 
diff --git a/log/include/SingleoTimer.h b/log/include/SingleoTimer.h
new file mode 100644 (file)
index 0000000..558ee77
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __SINGLEO_TIME_H__
+#define __SINGLEO_TIME_H__
+
+#include <chrono>
+
+using namespace std;
+
+class Timer {
+private:
+    chrono::system_clock::time_point _start;
+
+public:
+    Timer() {
+        _start = chrono::system_clock::now();
+    }
+    void reset() {
+        _start = chrono::system_clock::now();
+    }
+    int64_t check_ms() {
+        return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - _start).count();
+    }
+};
+#endif