From: Michael Tremer Date: Wed, 15 Mar 2023 03:01:46 +0000 (+0000) Subject: build: Show build time at the end X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f9a4c0b7ed845f6082bea18e33a70ce8d220eeb9;p=people%2Fstevee%2Fpakfire.git build: Show build time at the end Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 82c37e9a..778e5a60 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -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);