diff options
-rw-r--r-- | configd/src/apps/sentinel/config-handler.cpp | 2 | ||||
-rw-r--r-- | configd/src/apps/sentinel/metrics.cpp | 5 | ||||
-rw-r--r-- | configd/src/apps/sentinel/service.cpp | 7 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/timestamp.cpp | 7 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/timestamp.h | 3 | ||||
-rw-r--r-- | logd/src/logd/watcher.cpp | 6 | ||||
-rw-r--r-- | storage/src/vespa/storage/tools/throttlingsim.cpp | 6 | ||||
-rw-r--r-- | vespalog/src/logger/runserver.cpp | 29 |
8 files changed, 42 insertions, 23 deletions
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp index 0f624da2bf0..a73a5f01f33 100644 --- a/configd/src/apps/sentinel/config-handler.cpp +++ b/configd/src/apps/sentinel/config-handler.cpp @@ -44,7 +44,7 @@ ConfigHandler::ConfigHandler() _startMetrics(), _stateApi() { - _startMetrics.startedTime = time(nullptr); + _startMetrics.startedTime = fastos::time(); } ConfigHandler::~ConfigHandler() diff --git a/configd/src/apps/sentinel/metrics.cpp b/configd/src/apps/sentinel/metrics.cpp index 812ab56cd15..bb10c94ae12 100644 --- a/configd/src/apps/sentinel/metrics.cpp +++ b/configd/src/apps/sentinel/metrics.cpp @@ -2,6 +2,7 @@ #include "metrics.h" #include <vespa/vespalib/metrics/simple_metrics.h> +#include <vespa/fastos/timestamp.h> namespace config::sentinel { @@ -13,7 +14,7 @@ StartMetrics::StartMetrics() producer(metrics), currentlyRunningServices(0), totalRestartsCounter(0), - startedTime(time(nullptr)), + startedTime(fastos::time()), sentinel_restarts(metrics->counter("sentinel.restarts", "how many times sentinel restarted a service")), sentinel_totalRestarts(metrics->gauge("sentinel.totalRestarts", @@ -32,7 +33,7 @@ StartMetrics::~StartMetrics() = default; void StartMetrics::maybeLog() { - uint32_t curTime = time(nullptr); + uint32_t curTime = fastos::time(); sentinel_totalRestarts.sample(totalRestartsCounter); sentinel_running.sample(currentlyRunningServices); sentinel_uptime.sample(curTime - startedTime); diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp index 941ea690024..22f9681a2ff 100644 --- a/configd/src/apps/sentinel/service.cpp +++ b/configd/src/apps/sentinel/service.cpp @@ -4,6 +4,7 @@ #include "output-connection.h" #include <vespa/vespalib/util/stringfmt.h> #include <vespa/vespalib/util/signalhandler.h> +#include <vespa/fastos/timestamp.h> #include <csignal> #include <unistd.h> @@ -156,7 +157,7 @@ Service::start() LOG(warning, "tried to start '%s' in REMOVING state", name().c_str()); return; } - time_t now = time(0); + time_t now = fastos::time(); _last_start = now; // make a pipe, close the good ends of it, mark it close-on-exec @@ -322,7 +323,7 @@ Service::youExited(int status) if (! expectedDeath) { // make sure the service does not restart in a tight loop: - time_t now = time(0); + time_t now = fastos::time(); unsigned int diff = now - _last_start; if (diff < MAX_RESTART_PENALTY) { incrementRestartPenalty(); @@ -420,7 +421,7 @@ bool Service::wantsRestart() const { if (_state == RESTARTING) { - time_t now = time(0); + time_t now = fastos::time(); if (now > _last_start + _restartPenalty) { return true; } diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp index a662dd32a21..b671aa15b71 100644 --- a/fastos/src/vespa/fastos/timestamp.cpp +++ b/fastos/src/vespa/fastos/timestamp.cpp @@ -1,8 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "timestamp.h" +#include <chrono> #include <cmath> #include <sys/time.h> +using namespace std::chrono; + namespace fastos { const TimeStamp::TimeT TimeStamp::MILLI; @@ -39,4 +42,8 @@ int64_t ClockSystem::now() return ns; } +time_t time() { + return duration_cast<seconds>(system_clock::now().time_since_epoch()).count(); +} + } diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h index 06bf7af922c..c01f93205c0 100644 --- a/fastos/src/vespa/fastos/timestamp.h +++ b/fastos/src/vespa/fastos/timestamp.h @@ -84,6 +84,9 @@ private: TimeStamp _stopTime; }; +time_t time(); + + typedef StopWatchT<ClockSystem> TickStopWatch; typedef TickStopWatch StopWatch; diff --git a/logd/src/logd/watcher.cpp b/logd/src/logd/watcher.cpp index 103432e0136..1ef9288f4da 100644 --- a/logd/src/logd/watcher.cpp +++ b/logd/src/logd/watcher.cpp @@ -236,7 +236,7 @@ Watcher::watchfile() already.st_dev = sb.st_dev; already.st_ino = sb.st_ino; - time_t now = time(nullptr); + time_t now = fastos::time(); bool wantrotate = (now > created + _confsubscriber.getRotateAge()) || (sb.st_size > _confsubscriber.getRotateSize()); @@ -351,10 +351,10 @@ Watcher::removeOldLogs(const char *prefix) } if (S_ISREG(sb.st_mode)) { if (sb.st_mtime + - _confsubscriber.getRemoveAge() * 86400 < time(nullptr)) + _confsubscriber.getRemoveAge() * 86400 < fastos::time()) { LOG(info, "removing %s, too old (%f days)", fname, - (double)(time(nullptr)-sb.st_mtime)/86400.0); + (double)(fastos::time()-sb.st_mtime)/86400.0); if (unlink(fname) != 0) { LOG(warning, "cannot remove %s: %s", diff --git a/storage/src/vespa/storage/tools/throttlingsim.cpp b/storage/src/vespa/storage/tools/throttlingsim.cpp index 97f5af3518e..52cd81c6fbd 100644 --- a/storage/src/vespa/storage/tools/throttlingsim.cpp +++ b/storage/src/vespa/storage/tools/throttlingsim.cpp @@ -270,7 +270,7 @@ BusyCounterBalancingClient::BusyCounterBalancingClient(Messaging& msgng, int win void BusyCounterBalancingClient::run() { - // int startTime = time(NULL); + // int startTime = fastos::time(); while (running()) { { @@ -456,9 +456,9 @@ ThrottlingApp::Main() m.clients.push_back(c); } */ - int timeNow = time(NULL); + int timeNow = fastos::time(); - while (time(NULL) - timeNow < 240) { + while (fastos::time() - timeNow < 240) { m.print(); m.period.SetNow(); sleep(2); diff --git a/vespalog/src/logger/runserver.cpp b/vespalog/src/logger/runserver.cpp index be61ee2551d..8ea669697ee 100644 --- a/vespalog/src/logger/runserver.cpp +++ b/vespalog/src/logger/runserver.cpp @@ -1,25 +1,22 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <stdlib.h> -#include <string.h> -#include <stdio.h> +#include <cstdlib> +#include <cstring> +#include <cstdio> #include <fcntl.h> -#include <errno.h> +#include <cerrno> #include <unistd.h> -#include <time.h> -#include <csignal> #include <sys/select.h> #include <sys/types.h> #include <sys/wait.h> -#include <sys/time.h> #include <sys/resource.h> #include <sys/file.h> -#include <fcntl.h> #include <vespa/defaults.h> #include <vespa/log/llparser.h> #include "llreader.h" #include <vespa/log/log.h> +#include <chrono> LOG_SETUP("runserver"); @@ -38,6 +35,16 @@ void termsig(int sig) { } } +namespace { + +using namespace std::chrono; + +time_t steady_time() { + return duration_cast<seconds>(steady_clock::now().time_since_epoch()).count(); +} + +} + class PidFile { private: @@ -461,14 +468,14 @@ int main(int argc, char *argv[]) try { mypf.writePid(); do { - time_t laststart = time(NULL); + time_t laststart = steady_time(); stat = loop(service, argv+optind); if (restart > 0 && !gotstopsig) { - int wt = restart + laststart - time(NULL); + int wt = restart + laststart - steady_time(); if (wt < 0) wt = 0; LOG(info, "will restart in %d seconds", wt); } - while (!gotstopsig && time(NULL) - laststart < restart) { + while (!gotstopsig && steady_time() - laststart < restart) { sleep(1); } } while (!gotstopsig && restart > 0); |