]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
build: Show build time at the end
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 15 Mar 2023 03:01:46 +0000 (03:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 15 Mar 2023 03:01:46 +0000 (03:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 82c37e9a08d1abb9e480eb0fec575fc89ac85dec..778e5a6050ddfd50072ad42f6ae927421c57e8be 100644 (file)
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/mount.h>
+#include <time.h>
 #include <unistd.h>
 #include <uuid/uuid.h>
 
@@ -70,6 +71,9 @@ struct pakfire_build {
 
        char target[PATH_MAX];
 
+       // Times
+       time_t time_start;
+
        // cgroup
        struct pakfire_cgroup* cgroup;
 
@@ -103,6 +107,17 @@ static int pakfire_build_has_flag(struct pakfire_build* build, int flag) {
        return build->flags & flag;
 }
 
+static time_t pakfire_build_duration(struct pakfire_build* build) {
+       // What time is it now?
+       time_t now = time(NULL);
+
+       // Return any errors
+       if (now < 0)
+               return now;
+
+       return now - build->time_start;
+}
+
 static int __pakfire_build_setup_repo(struct pakfire* pakfire,
                struct pakfire_repo* repo, void* p) {
        char path[PATH_MAX];
@@ -1516,6 +1531,19 @@ static int pakfire_build_setup_repo(struct pakfire_build* build) {
        return r;
 }
 
+static int pakfire_build_set_time_start(struct pakfire_build* build) {
+       const time_t now = time(NULL);
+
+       if (now < 0) {
+               ERROR(build->pakfire, "Could not fetch start time: %m\n");
+               return 1;
+       }
+
+       build->time_start = now;
+
+       return 0;
+}
+
 PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
                struct pakfire* pakfire, const char* id, int flags) {
        int r;
@@ -1534,6 +1562,11 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
        // Copy flags
        b->flags = flags;
 
+       // Store start time
+       r = pakfire_build_set_time_start(b);
+       if (r)
+               goto ERROR;
+
        // Parse ID
        r = pakfire_build_parse_id(b, id);
        if (r)
@@ -2045,6 +2078,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        struct pakfire_package* package = NULL;
        struct pakfire_parser* makefile = NULL;
        char* buildroot = NULL;
+       char duration[TIME_STRING_MAX];
        int r;
 
        // Set buildroot
@@ -2108,6 +2142,13 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p
        if (r)
                goto ERROR;
 
+       // Log duration
+       r = pakfire_format_time(duration, pakfire_build_duration(build));
+       if (r)
+               goto ERROR;
+
+       INFO(build->pakfire, "Build successfully completed in %s\n", duration);
+
 ERROR:
        if (makefile)
                pakfire_parser_unref(makefile);