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
This commit is contained in:
Olivier Goffart 2017-12-14 15:36:19 +01:00 committed by Dominik Schmidt
parent 257d8142b1
commit d948ed11a1
8 changed files with 18 additions and 322 deletions

View file

@ -63,7 +63,6 @@ set(csync_SRCS
csync.cpp
csync_exclude.cpp
csync_log.cpp
csync_time.c
csync_util.cpp
csync_misc.cpp

View file

@ -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)) {

View file

@ -1,84 +0,0 @@
/*
* libcsync -- a library to sync a directory with another
*
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
*
* 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 <errno.h>
#include <stdio.h>
#include <time.h>
#include "csync_time.h"
#ifndef _WIN32
#include <unistd.h>
#include <sys/time.h>
#else
#include <windows.h>
#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
}

View file

@ -1,37 +0,0 @@
/*
* libcsync -- a library to sync a directory with another
*
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
*
* 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 <time.h>
int csync_gettime(struct timespec *tp);
void csync_sleep(unsigned int msecs);
#ifdef __cplusplus
}
#endif
#endif /* _CSYNC_TIME_H */

View file

@ -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);

View file

@ -33,33 +33,6 @@ extern "C" {
#include <sys/time.h>
#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

View file

@ -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.

View file

@ -1,101 +0,0 @@
/*
* libcsync -- a library to sync a directory with another
*
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
*
* 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 <string.h>
#include "csync_time.h"
#include "std/c_time.h"
#include <unistd.h>
#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);
}