From 0b747de48cdb61994580665d7ae59feb47076d5e Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Thu, 25 Oct 2018 18:06:36 +0000 Subject: [PATCH] time: move time list code to its own file Just moving code, no significative changes Signed-off-by: Otavio Pontes --- Makefile.am | 2 + src/globals.c | 80 --------------------------------- src/swupd.h | 19 +------- src/timelist.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ src/timelist.h | 21 +++++++++ 5 files changed, 141 insertions(+), 98 deletions(-) create mode 100644 src/timelist.c create mode 100644 src/timelist.h diff --git a/Makefile.am b/Makefile.am index ab06bdb1..92fe2eaf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,8 @@ swupd_SOURCES = \ src/swupd-internal.h \ src/swupd.h \ src/telemetry.c \ + src/timelist.c \ + src/timelist.h \ src/update.c \ src/verify.c \ src/version.c \ diff --git a/src/globals.c b/src/globals.c index 26424cb8..ffc9d1b3 100644 --- a/src/globals.c +++ b/src/globals.c @@ -72,86 +72,6 @@ long update_server_port = -1; int max_parallel_downloads = -1; char *swupd_cmd = NULL; -timelist init_timelist(void) -{ - timelist head = TAILQ_HEAD_INITIALIZER(head); - TAILQ_INIT(&head); - return head; -} - -static struct time *alloc_time() -{ - struct time *t = calloc(1, sizeof(struct time)); - ON_NULL_ABORT(t); - - return t; -} - -/* Fill the time struct for later processing */ -void grabtime_start(timelist *head, const char *name) -{ - if (verbose_time == false) { - return; - } - - /* Only create one element for each start/stop block */ - struct time *t = alloc_time(); - - clock_gettime(CLOCK_MONOTONIC_RAW, &t->rawstart); - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t->procstart); - t->name = name; - t->complete = false; - TAILQ_INSERT_HEAD(head, t, times); -} - -void grabtime_stop(timelist *head) -{ - if (verbose_time == false) { - return; - } - - struct time *t; - - TAILQ_FOREACH(t, head, times) - { - if (!t->complete) { - clock_gettime(CLOCK_MONOTONIC_RAW, &t->rawstop); - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t->procstop); - t->complete = true; - return; - } - } -} - -void print_time_stats(timelist *head) -{ - if (verbose_time == false || TAILQ_FIRST(head) == NULL) { - return; - } - - double delta = 0; - struct time *t; - - fprintf(stderr, "\nRaw elapsed time stats:\n"); - TAILQ_FOREACH_REVERSE(t, head, timelist, times) - { - if (t->complete == true) { - delta = (t->rawstop.tv_sec - t->rawstart.tv_sec) * 1000 + (t->rawstop.tv_nsec / 1000000.0) - (t->rawstart.tv_nsec / 1000000.0); - fprintf(stderr, "%10.2f ms: %s\n", delta, t->name); - } - } - fprintf(stderr, "\nCPU process time stats:\n"); - while (!TAILQ_EMPTY(head)) { - t = TAILQ_LAST(head, timelist); - if (t->complete == true) { - delta = (t->procstop.tv_sec - t->procstart.tv_sec) * 1000 + (t->procstop.tv_nsec / 1000000.0) - (t->procstart.tv_nsec / 1000000.0); - fprintf(stderr, "%10.2f ms: %s\n", delta, t->name); - } - TAILQ_REMOVE(head, t, times); - free(t); - } -} - /* If the MIX_BUNDLES_DIR has the valid-mix flag file we can run through * adding the mix data to the OS */ bool check_mix_exists(void) diff --git a/src/swupd.h b/src/swupd.h index d46fa303..392d282d 100644 --- a/src/swupd.h +++ b/src/swupd.h @@ -9,11 +9,11 @@ #include #include #include -#include #include "list.h" #include "macros.h" #include "swupd-error.h" +#include "timelist.h" #ifdef __cplusplus extern "C" { @@ -153,17 +153,6 @@ struct filerecord { bool in_manifest; }; -struct time { - struct timespec procstart; - struct timespec procstop; - struct timespec rawstart; - struct timespec rawstop; - const char *name; - bool complete; - TAILQ_ENTRY(time) - times; -}; - struct file_counts { int checked; int missing; @@ -177,8 +166,6 @@ struct file_counts { int not_deleted; }; -typedef TAILQ_HEAD(timelist, time) timelist; - extern bool download_only; extern bool verify_esp_only; extern bool have_manifest_diskspace; @@ -238,12 +225,8 @@ extern void link_manifests(struct manifest *m1, struct manifest *m2); extern void link_submanifests(struct manifest *m1, struct manifest *m2, struct list *subs1, struct list *subs2, bool server); extern void free_manifest(struct manifest *manifest); -extern void grabtime_start(timelist *list, const char *name); -extern void grabtime_stop(timelist *list); -extern void print_time_stats(timelist *list); extern int get_value_from_path(char **contents, const char *path, bool is_abs_path); extern int get_version_from_path(const char *abs_path); -extern timelist init_timelist(void); extern int extract_to(const char *tarfile, const char *outputdir); diff --git a/src/timelist.c b/src/timelist.c new file mode 100644 index 00000000..4f751094 --- /dev/null +++ b/src/timelist.c @@ -0,0 +1,117 @@ +/* + * Software Updater - client side + * + * Copyright © 2018 Intel Corporation. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 or later of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define _GNU_SOURCE + +#include +#include +#include + +#include "swupd.h" +#include "timelist.h" + +struct time { + struct timespec procstart; + struct timespec procstop; + struct timespec rawstart; + struct timespec rawstop; + const char *name; + bool complete; + TAILQ_ENTRY(time) + times; +}; + +timelist init_timelist(void) +{ + timelist head = TAILQ_HEAD_INITIALIZER(head); + TAILQ_INIT(&head); + return head; +} + +static struct time *alloc_time() +{ + struct time *t = calloc(1, sizeof(struct time)); + ON_NULL_ABORT(t); + + return t; +} + +/* Fill the time struct for later processing */ +void grabtime_start(timelist *head, const char *name) +{ + if (verbose_time == false) { + return; + } + + /* Only create one element for each start/stop block */ + struct time *t = alloc_time(); + + clock_gettime(CLOCK_MONOTONIC_RAW, &t->rawstart); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t->procstart); + t->name = name; + t->complete = false; + TAILQ_INSERT_HEAD(head, t, times); +} + +void grabtime_stop(timelist *head) +{ + if (verbose_time == false) { + return; + } + + struct time *t; + + TAILQ_FOREACH(t, head, times) + { + if (!t->complete) { + clock_gettime(CLOCK_MONOTONIC_RAW, &t->rawstop); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t->procstop); + t->complete = true; + return; + } + } +} + +void print_time_stats(timelist *head) +{ + if (verbose_time == false || TAILQ_FIRST(head) == NULL) { + return; + } + + double delta = 0; + struct time *t; + + fprintf(stderr, "\nRaw elapsed time stats:\n"); + TAILQ_FOREACH_REVERSE(t, head, timelist, times) + { + if (t->complete == true) { + delta = (t->rawstop.tv_sec - t->rawstart.tv_sec) * 1000 + (t->rawstop.tv_nsec / 1000000.0) - (t->rawstart.tv_nsec / 1000000.0); + fprintf(stderr, "%10.2f ms: %s\n", delta, t->name); + } + } + fprintf(stderr, "\nCPU process time stats:\n"); + while (!TAILQ_EMPTY(head)) { + t = TAILQ_LAST(head, timelist); + if (t->complete == true) { + delta = (t->procstop.tv_sec - t->procstart.tv_sec) * 1000 + (t->procstop.tv_nsec / 1000000.0) - (t->procstart.tv_nsec / 1000000.0); + fprintf(stderr, "%10.2f ms: %s\n", delta, t->name); + } + TAILQ_REMOVE(head, t, times); + free(t); + } +} diff --git a/src/timelist.h b/src/timelist.h new file mode 100644 index 00000000..d71e49b6 --- /dev/null +++ b/src/timelist.h @@ -0,0 +1,21 @@ +#ifndef __TIME_H__ +#define __TIME_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef TAILQ_HEAD(timelist, time) timelist; + +extern timelist init_timelist(void); +extern void grabtime_start(timelist *list, const char *name); +extern void grabtime_stop(timelist *list); +extern void print_time_stats(timelist *list); + +#ifdef __cplusplus +} +#endif + +#endif