From d948ed11a185be55ff414a7eb3ab9968801d01dc Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 14 Dec 2017 15:36:19 +0100 Subject: [PATCH] Csync: use QElapsedTimer and qCInfo instead of CSYNC_LOG and its own csync time function This allow to remove all the csync time manipulation routne which are now unused --- src/csync/CMakeLists.txt | 1 - src/csync/csync.cpp | 46 ++++------- src/csync/csync_time.c | 84 -------------------- src/csync/csync_time.h | 37 --------- src/csync/std/c_time.c | 42 ---------- src/csync/std/c_time.h | 27 ------- test/csync/CMakeLists.txt | 2 +- test/csync/std_tests/check_std_c_time.c | 101 ------------------------ 8 files changed, 18 insertions(+), 322 deletions(-) delete mode 100644 src/csync/csync_time.c delete mode 100644 src/csync/csync_time.h delete mode 100644 test/csync/std_tests/check_std_c_time.c diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index 2cf4e9600..bf1fc34c4 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -63,7 +63,6 @@ set(csync_SRCS csync.cpp csync_exclude.cpp csync_log.cpp - csync_time.c csync_util.cpp csync_misc.cpp diff --git a/src/csync/csync.cpp b/src/csync/csync.cpp index 667ab25b9..3fadf65d9 100644 --- a/src/csync/csync.cpp +++ b/src/csync/csync.cpp @@ -36,7 +36,6 @@ #include "c_lib.h" #include "csync_private.h" #include "csync_exclude.h" -#include "csync_time.h" #include "csync_util.h" #include "csync_misc.h" #include "std/c_private.h" @@ -46,11 +45,12 @@ #include "vio/csync_vio.h" -#include "csync_log.h" #include "csync_rename.h" #include "common/c_jhash.h" #include "common/syncjournalfilerecord.h" +Q_LOGGING_CATEGORY(lcCSync, "sync.csync.csync", QtInfoMsg) + csync_s::csync_s(const char *localUri, OCC::SyncJournalDb *statedb) : statedb(statedb) @@ -66,7 +66,6 @@ csync_s::csync_s(const char *localUri, OCC::SyncJournalDb *statedb) int csync_update(CSYNC *ctx) { int rc = -1; - struct timespec start, finish; if (ctx == NULL) { errno = EBADF; @@ -79,11 +78,12 @@ int csync_update(CSYNC *ctx) { csync_memstat_check(); if (!ctx->exclude_traversal_fn) { - CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "No exclude file loaded or defined!"); + qCInfo(lcCSync, "No exclude file loaded or defined!"); } /* update detection for local replica */ - csync_gettime(&start); + QElapsedTimer timer; + timer.start(); ctx->current = LOCAL_REPLICA; CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "## Starting local discovery ##"); @@ -96,15 +96,12 @@ int csync_update(CSYNC *ctx) { return rc; } - csync_gettime(&finish); - - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, - "Update detection for local replica took %.2f seconds walking %zu files.", - c_secdiff(finish, start), ctx->local.files.size()); + qCInfo(lcCSync) << "Update detection for local replica took" << timer.elapsed() / 1000. + << "seconds walking" << ctx->local.files.size() << "files"; csync_memstat_check(); /* update detection for remote replica */ - csync_gettime(&start); + timer.restart(); ctx->current = REMOTE_REPLICA; CSYNC_LOG(CSYNC_LOG_PRIORITY_INFO, "## Starting remote discovery ##"); @@ -117,12 +114,9 @@ int csync_update(CSYNC *ctx) { return rc; } - csync_gettime(&finish); - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, - "Update detection for remote replica took %.2f seconds " - "walking %zu files.", - c_secdiff(finish, start), ctx->remote.files.size()); + qCInfo(lcCSync) << "Update detection for remote replica took" << timer.elapsed() / 1000. + << "seconds walking" << ctx->remote.files.size() << "files"; csync_memstat_check(); ctx->status |= CSYNC_STATUS_UPDATE; @@ -133,7 +127,6 @@ int csync_update(CSYNC *ctx) { int csync_reconcile(CSYNC *ctx) { int rc = -1; - struct timespec start, finish; if (ctx == NULL) { errno = EBADF; @@ -142,17 +135,15 @@ int csync_reconcile(CSYNC *ctx) { ctx->status_code = CSYNC_STATUS_OK; /* Reconciliation for local replica */ - csync_gettime(&start); + QElapsedTimer timer; + timer.start(); ctx->current = LOCAL_REPLICA; rc = csync_reconcile_updates(ctx); - csync_gettime(&finish); - - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, - "Reconciliation for local replica took %.2f seconds visiting %zu files.", - c_secdiff(finish, start), ctx->local.files.size()); + qCInfo(lcCSync) << "Reconciliation for local replica took " << timer.elapsed() / 1000. + << "seconds visiting " << ctx->local.files.size() << " files."; if (rc < 0) { if (!CSYNC_STATUS_IS_OK(ctx->status_code)) { @@ -162,17 +153,14 @@ int csync_reconcile(CSYNC *ctx) { } /* Reconciliation for remote replica */ - csync_gettime(&start); + timer.restart(); ctx->current = REMOTE_REPLICA; rc = csync_reconcile_updates(ctx); - csync_gettime(&finish); - - CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, - "Reconciliation for remote replica took %.2f seconds visiting %zu files.", - c_secdiff(finish, start), ctx->remote.files.size()); + qCInfo(lcCSync) << "Reconciliation for remote replica took " << timer.elapsed() / 1000. + << "seconds visiting " << ctx->remote.files.size() << " files."; if (rc < 0) { if (!CSYNC_STATUS_IS_OK(ctx->status_code)) { diff --git a/src/csync/csync_time.c b/src/csync/csync_time.c deleted file mode 100644 index 442263cee..000000000 --- a/src/csync/csync_time.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config_csync.h" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include - -#include "csync_time.h" - -#ifndef _WIN32 -#include -#include -#else -#include -#endif - -#define CSYNC_LOG_CATEGORY_NAME "csync.time" -#include "csync_log.h" - -#ifdef HAVE_CLOCK_GETTIME -# ifdef _POSIX_MONOTONIC_CLOCK -# define CSYNC_CLOCK CLOCK_MONOTONIC -# else -# define CSYNC_CLOCK CLOCK_REALTIME -# endif -#endif - - -int csync_gettime(struct timespec *tp) -{ -#if defined(_WIN32) - __int64 wintime; - GetSystemTimeAsFileTime((FILETIME*)&wintime); - wintime -= 116444736000000000ll; //1jan1601 to 1jan1970 - tp->tv_sec = wintime / 10000000ll; //seconds - tp->tv_nsec = wintime % 10000000ll * 100; //nano-seconds -#elif defined(HAVE_CLOCK_GETTIME) - return clock_gettime(CSYNC_CLOCK, tp); -#else - struct timeval tv; - - if (gettimeofday(&tv, NULL) < 0) { - return -1; - } - - tp->tv_sec = tv.tv_sec; - tp->tv_nsec = tv.tv_usec * 1000; -#endif - return 0; -} - -#undef CSYNC_CLOCK - -void csync_sleep(unsigned int msecs) -{ -#if defined(_WIN32) - Sleep(msecs); -#else - usleep(msecs * 1000); -#endif -} diff --git a/src/csync/csync_time.h b/src/csync/csync_time.h deleted file mode 100644 index 14d355b32..000000000 --- a/src/csync/csync_time.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef _CSYNC_TIME_H -#define _CSYNC_TIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int csync_gettime(struct timespec *tp); -void csync_sleep(unsigned int msecs); - -#ifdef __cplusplus -} -#endif - -#endif /* _CSYNC_TIME_H */ diff --git a/src/csync/std/c_time.c b/src/csync/std/c_time.c index 4bcdcbf56..c28459e1b 100644 --- a/src/csync/std/c_time.c +++ b/src/csync/std/c_time.c @@ -26,48 +26,6 @@ #include "c_time.h" #include "c_utf8.h" -struct timespec c_tspecdiff(struct timespec time1, struct timespec time0) { - struct timespec ret; - int xsec = 0; - int sign = 1; - - if (time0.tv_nsec > time1.tv_nsec) { - xsec = (int) ((time0.tv_nsec - time1.tv_nsec) / (1E9 + 1)); - time0.tv_nsec -= (long int) (1E9 * xsec); - time0.tv_sec += xsec; - } - - if ((time1.tv_nsec - time0.tv_nsec) > 1E9) { - xsec = (int) ((time1.tv_nsec - time0.tv_nsec) / 1E9); - time0.tv_nsec += (long int) (1E9 * xsec); - time0.tv_sec -= xsec; - } - - ret.tv_sec = time1.tv_sec - time0.tv_sec; - ret.tv_nsec = time1.tv_nsec - time0.tv_nsec; - - if (time1.tv_sec < time0.tv_sec) { - sign = -1; - } - - ret.tv_sec = ret.tv_sec * sign; - - return ret; -} - -double c_secdiff(struct timespec clock1, struct timespec clock0) { - double ret; - struct timespec diff; - - diff = c_tspecdiff(clock1, clock0); - - ret = diff.tv_sec; - ret += (double) diff.tv_nsec / (double) 1E9; - - return ret; -} - - #ifdef HAVE_UTIMES int c_utimes(const char *uri, const struct timeval *times) { mbchar_t *wuri = c_utf8_path_to_locale(uri); diff --git a/src/csync/std/c_time.h b/src/csync/std/c_time.h index dee1b0e2b..3792198f8 100644 --- a/src/csync/std/c_time.h +++ b/src/csync/std/c_time.h @@ -33,33 +33,6 @@ extern "C" { #include #endif -/** - * @brief Calculate time difference - * - * The c_tspecdiff function returns the time elapsed between time time1 and time - * time0 represented as timespec. - * - * @param time1 The time. - * @param time0 The time. - * - * @return time elapsed between time1 and time0. - */ -struct timespec c_tspecdiff(struct timespec time1, struct timespec time0); - -/** - * @brief Calculate time difference. - * - * The function returns the time elapsed between time clock1 and time - * clock0 represented as double (in seconds and milliseconds). - * - * @param clock1 The time. - * @param clock0 The time. - * - * @return time elapsed between clock1 and clock0 in seconds and - * milliseconds. - */ -double c_secdiff(struct timespec clock1, struct timespec clock0); - OCSYNC_EXPORT int c_utimes(const char *uri, const struct timeval *times); #ifdef __cplusplus diff --git a/test/csync/CMakeLists.txt b/test/csync/CMakeLists.txt index 5cb0590e4..75cee7b7d 100644 --- a/test/csync/CMakeLists.txt +++ b/test/csync/CMakeLists.txt @@ -24,7 +24,7 @@ add_cmocka_test(check_std_c_alloc std_tests/check_std_c_alloc.c ${TEST_TARGET_LI add_cmocka_test(check_std_c_jhash std_tests/check_std_c_jhash.c ${TEST_TARGET_LIBRARIES}) add_cmocka_test(check_std_c_path std_tests/check_std_c_path.c ${TEST_TARGET_LIBRARIES}) add_cmocka_test(check_std_c_str std_tests/check_std_c_str.c ${TEST_TARGET_LIBRARIES}) -add_cmocka_test(check_std_c_time std_tests/check_std_c_time.c ${TEST_TARGET_LIBRARIES}) + # csync tests # This will be rewritten soon anyway. diff --git a/test/csync/std_tests/check_std_c_time.c b/test/csync/std_tests/check_std_c_time.c deleted file mode 100644 index db8e72ff6..000000000 --- a/test/csync/std_tests/check_std_c_time.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2008-2013 by Andreas Schneider - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include - -#include "csync_time.h" -#include "std/c_time.h" -#include - -#include "torture.h" - -static void check_c_tspecdiff(void **state) -{ - struct timespec start, finish, diff; - - (void) state; /* unused */ - - csync_gettime(&start); - csync_gettime(&finish); - - diff = c_tspecdiff(finish, start); - - assert_int_equal(diff.tv_sec, 0); - assert_true(diff.tv_nsec >= 0); -} - -static void check_c_tspecdiff_five(void **state) -{ - struct timespec start, finish, diff; - - (void) state; /* unused */ - - csync_gettime(&start); - sleep(5); - csync_gettime(&finish); - - diff = c_tspecdiff(finish, start); - - assert_int_equal(diff.tv_sec, 5); - assert_true(diff.tv_nsec > 0); -} - -static void check_c_secdiff(void **state) -{ - struct timespec start, finish; - double diff; - - (void) state; /* unused */ - - csync_gettime(&start); - csync_gettime(&finish); - - diff = c_secdiff(finish, start); - - assert_true(diff >= 0.00 && diff < 1.00); -} - -static void check_c_secdiff_three(void **state) -{ - struct timespec start, finish; - double diff; - - (void) state; /* unused */ - - csync_gettime(&start); - sleep(3); - csync_gettime(&finish); - - diff = c_secdiff(finish, start); - - assert_true(diff > 3.00 && diff < 4.00); -} - -int torture_run_tests(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(check_c_tspecdiff), - cmocka_unit_test(check_c_tspecdiff_five), - cmocka_unit_test(check_c_secdiff), - cmocka_unit_test(check_c_secdiff_three), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} -