{"id":1967,"url":"https://patchwork.libcamera.org/api/1.1/patches/1967/?format=json","web_url":"https://patchwork.libcamera.org/patch/1967/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190914110620.23290-1-laurent.pinchart@ideasonboard.com>","date":"2019-09-14T11:06:19","name":"[libcamera-devel,v2,1/2] libcamera: utils: Add clock helpers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"e1ba812553fac617b691ca3d6596b834d42af336","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1967/mbox/","series":[{"id":490,"url":"https://patchwork.libcamera.org/api/1.1/series/490/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=490","date":"2019-09-14T11:06:19","name":"[libcamera-devel,v2,1/2] libcamera: utils: Add clock helpers","version":2,"mbox":"https://patchwork.libcamera.org/series/490/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1967/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1967/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0BD0260BB0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Sep 2019 13:06:32 +0200 (CEST)","from pendragon.lan (bl10-204-24.dsl.telepac.pt [85.243.204.24])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D3F4823F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Sep 2019 13:06:30 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1568459191;\n\tbh=ld3KQjRs/cuBqAj1qCZazqmBMF8jmGfvEidrHcu8Uwk=;\n\th=From:To:Subject:Date:From;\n\tb=WQGAMnJofQgDl73Ymz5bAIYAbpwjktnmt3wwj7tMTcEbJrCY4QUetDrBxX2LZC4xX\n\t77wagARuCRtpJ/TQxlSPVVpL51dCLvKDLTVbcTaCIO7ov5/i/H3YWuctrfGcq0BAFd\n\tW/aQaB2RHuoh2kXM8QtofVjL3DNzk1bB4/UEWvOc=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 14 Sep 2019 14:06:19 +0300","Message-Id":"<20190914110620.23290-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/2] libcamera: utils: Add clock helpers","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 14 Sep 2019 11:06:32 -0000"},"content":"In preparation for standardisation of the std::chrono::steady_clock as\nthe libcamera default clock, define aliases for the clock, duration and\ntime point, and add helper functions to convert a duration to a timespec\nand a time point to a string. More helpers will be added later as\nneeded.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/utils.h | 10 +++++++\n src/libcamera/utils.cpp       | 50 +++++++++++++++++++++++++++++++++++\n 2 files changed, 60 insertions(+)","diff":"diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex 47a422587338..52eee8ac2804 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -8,7 +8,10 @@\n #define __LIBCAMERA_UTILS_H__\n \n #include <algorithm>\n+#include <chrono>\n #include <memory>\n+#include <string>\n+#include <sys/time.h>\n \n #define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n \n@@ -53,6 +56,13 @@ const T& clamp(const T& v, const T& lo, const T& hi)\n \treturn std::max(lo, std::min(v, hi));\n }\n \n+using clock = std::chrono::steady_clock;\n+using duration = std::chrono::steady_clock::duration;\n+using time_point = std::chrono::steady_clock::time_point;\n+\n+struct timespec duration_to_timespec(const duration &value);\n+std::string time_point_to_string(const time_point &time);\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex afbdd8349790..fe7ec53302a3 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -7,6 +7,8 @@\n \n #include \"utils.h\"\n \n+#include <iomanip>\n+#include <sstream>\n #include <stdlib.h>\n #include <string.h>\n #include <unistd.h>\n@@ -93,6 +95,54 @@ char *secure_getenv(const char *name)\n  * \\return lo if v is less than lo, hi if v is greater than hi, otherwise v\n  */\n \n+/**\n+ * \\typedef clock\n+ * \\brief The libcamera clock (monotonous)\n+ */\n+\n+/**\n+ * \\typedef duration\n+ * \\brief The libcamera duration related to libcamera::utils::clock\n+ */\n+\n+/**\n+ * \\typedef time_point\n+ * \\brief The libcamera time point related to libcamera::utils::clock\n+ */\n+\n+/**\n+ * \\brief Convert a duration to a timespec\n+ * \\param[in] value The duration\n+ * \\return A timespec expressing the duration\n+ */\n+struct timespec duration_to_timespec(const duration &value)\n+{\n+\tuint64_t nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(value).count();\n+\tstruct timespec ts;\n+\tts.tv_sec = nsecs / 1000000000ULL;\n+\tts.tv_nsec = nsecs % 1000000000ULL;\n+\treturn ts;\n+}\n+\n+/**\n+ * \\brief Convert a time point to a string representation\n+ * \\param[in] time The time point\n+ * \\return A string representing the time point in hh:mm:ss.nanoseconds format\n+ */\n+std::string time_point_to_string(const time_point &time)\n+{\n+\tuint64_t nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(time.time_since_epoch()).count();\n+\tunsigned int secs = nsecs / 1000000000ULL;\n+\n+\tstd::ostringstream ossTimestamp;\n+\tossTimestamp.fill('0');\n+\tossTimestamp << secs / (60 * 60) << \":\"\n+\t\t     << std::setw(2) << (secs / 60) % 60 << \":\"\n+\t\t     << std::setw(2) << secs % 60 << \".\"\n+\t\t     << std::setw(9) << nsecs % 1000000000ULL;\n+\treturn ossTimestamp.str();\n+}\n+\n } /* namespace utils */\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v2","1/2"]}