mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-03 23:38:25 +00:00
time: move time list code to its own file
Just moving code, no significative changes Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-18
@@ -9,11 +9,11 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
+117
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __TIME_H__
|
||||
#define __TIME_H__
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user