aboutsummaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-12-09 04:09:05 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-12-16 23:48:46 +0000
commit225be01d5405c179584eb7fc08309c8f4a08fb22 (patch)
treefe50a91214b2db66a0df797d2dc46e51ab4bfcd1 /fastos
parentc72bdc628b4493bfb2974ab3fe479d2af0d376f1 (diff)
GC unused timestamp in schema.
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/tests/processtest.cpp12
-rw-r--r--fastos/src/tests/thread_bounce_test.cpp13
-rw-r--r--fastos/src/tests/threadtest.cpp25
-rw-r--r--fastos/src/vespa/fastos/timestamp.cpp36
-rw-r--r--fastos/src/vespa/fastos/timestamp.h50
-rw-r--r--fastos/src/vespa/fastos/unix_process.cpp6
6 files changed, 31 insertions, 111 deletions
diff --git a/fastos/src/tests/processtest.cpp b/fastos/src/tests/processtest.cpp
index 5a78eff1d36..e39b6461a29 100644
--- a/fastos/src/tests/processtest.cpp
+++ b/fastos/src/tests/processtest.cpp
@@ -1,9 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "tests.h"
#include <vespa/fastos/process.h>
-#include <vespa/fastos/timestamp.h>
using namespace std::chrono_literals;
+using namespace std::chrono;
class MyListener : public FastOS_ProcessRedirectListener
{
@@ -213,7 +213,7 @@ public:
if(waitKill)
timeOut = 1;
- fastos::StopWatch timer;
+ steady_clock::time_point start = steady_clock::now();
int returnCode;
if(!xproc->Wait(&returnCode, timeOut))
@@ -228,11 +228,11 @@ public:
}
if (waitKill) {
- double milliSecs = timer.elapsed().ms();
- if((milliSecs < 900) ||
- (milliSecs > 3500))
+ nanoseconds elapsed = steady_clock::now() - start;
+ if((elapsed < 900ms) ||
+ (elapsed > 3500ms))
{
- Progress(false, "WaitKill time = %d", int(milliSecs));
+ Progress(false, "WaitKill time = %d", duration_cast<milliseconds>(elapsed).count());
}
}
diff --git a/fastos/src/tests/thread_bounce_test.cpp b/fastos/src/tests/thread_bounce_test.cpp
index 84506938455..488002341e9 100644
--- a/fastos/src/tests/thread_bounce_test.cpp
+++ b/fastos/src/tests/thread_bounce_test.cpp
@@ -3,7 +3,8 @@
#include "tests.h"
#include "job.h"
#include "thread_test_base.hpp"
-#include <vespa/fastos/timestamp.h>
+
+using namespace std::chrono;
class Thread_Bounce_Test : public ThreadTestBase
{
@@ -39,12 +40,12 @@ class Thread_Bounce_Test : public ThreadTestBase
lastcntsum = -1;
for (int iter = 0; iter < 8; iter++) {
- fastos::StopWatch checkTime;
+ steady_clock::time_point start = steady_clock::now();
- int left = static_cast<int>(checkTime.elapsed().ms());
- while (left < 1000) {
- std::this_thread::sleep_for(std::chrono::milliseconds(1000 - left));
- left = static_cast<int>(checkTime.elapsed().ms());
+ nanoseconds left = steady_clock::now() - start;
+ while (left < 1000ms) {
+ std::this_thread::sleep_for(1000ms - left);
+ left = steady_clock::now() - start;
}
mutex1.lock();
diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp
index 0a8a0d2bf02..1fa9820c8d7 100644
--- a/fastos/src/tests/threadtest.cpp
+++ b/fastos/src/tests/threadtest.cpp
@@ -3,13 +3,15 @@
#include "tests.h"
#include "job.h"
#include "thread_test_base.hpp"
-#include <vespa/fastos/timestamp.h>
#include <cstdlib>
#include <chrono>
#define MUTEX_TEST_THREADS 6
#define MAX_THREADS 7
+using namespace std::chrono;
+using namespace std::chrono_literals;
+
class ThreadTest : public ThreadTestBase
{
int Main () override;
@@ -202,7 +204,7 @@ class ThreadTest : public ThreadTestBase
Job *jobs = new Job[count];
threadsok = 0;
- fastos::StopWatch timer;
+ steady_clock::time_point start = steady_clock::now();
for (i = 0; i < count; i++) {
jobs[i].code = SILENTNOP;
jobs[i].ownThread = pool->NewThread(this, &jobs[i]);
@@ -225,13 +227,13 @@ class ThreadTest : public ThreadTestBase
if (jobs[i].ownThread != nullptr)
jobs[i].ownThread->Join();
}
- fastos::TimeStamp used = timer.elapsed();
+ nanoseconds used = steady_clock::now() - start;
if (!silent) {
- Progress(true, "Used time: %2.3f", used.sec());
+ double timeused = used.count() / 1000000000.0;
- double timeused = used.sec();
- ProgressFloat(true, "Threads/s: %6.1f",
+ Progress(true, "Used time: %2.3f", timeused);
+ ProgressFloat(true, "Threads/s: %6.1f",
static_cast<float>(static_cast<double>(threadsok) / timeused));
}
if (threadsok != ((outercount + 1) * count))
@@ -517,12 +519,13 @@ class ThreadTest : public ThreadTestBase
std::mutex **mutexes = new std::mutex*[allocCount];
- fastos::StopWatch timer;
+ steady_clock::time_point start = steady_clock::now();
for (i=0; i<allocCount; i++)
mutexes[i] = new std::mutex;
- Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, timer.elapsed().ms());
+ nanoseconds elapsed = steady_clock::now() - start;
+ Progress(true, "Allocated %d mutexes at time: %ld ms", allocCount, duration_cast<milliseconds>(elapsed).count());
for (int e=0; e<4; e++) {
for(i=0; i<allocCount; i++)
@@ -531,12 +534,14 @@ class ThreadTest : public ThreadTestBase
for(i=0; i<allocCount; i++)
mutexes[i]->unlock();
- Progress(true, "Tested %d mutexes at time: %d ms", allocCount, timer.elapsed().ms());
+ elapsed = steady_clock::now() - start;
+ Progress(true, "Tested %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count());
}
for (i=0; i<allocCount; i++)
delete mutexes[i];
- Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, timer.elapsed().ms());
+ elapsed = steady_clock::now() - start;
+ Progress(true, "Deleted %d mutexes at time: %d ms", allocCount, duration_cast<milliseconds>(elapsed).count());
delete [] mutexes;
diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp
index ef206067900..d8e89dcf99f 100644
--- a/fastos/src/vespa/fastos/timestamp.cpp
+++ b/fastos/src/vespa/fastos/timestamp.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "timestamp.h"
#include <cmath>
-#include <thread>
#include <sys/time.h>
using std::chrono::system_clock;
@@ -44,39 +43,4 @@ time() {
return system_clock::to_time_t(system_clock::now());
}
-namespace {
-
-SteadyTimeStamp
-steady_now() {
- return SteadyTimeStamp(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
-}
-
-}
-
-StopWatch::StopWatch()
- : _startTime(steady_now())
-{ }
-
-void
-StopWatch::restart() {
- _startTime = steady_now();
-}
-
-TimeStamp
-StopWatch::elapsed() const {
- return (steady_now() - _startTime);
-}
-
-void
-StopWatch::waitAtLeast(std::chrono::microseconds us, bool busyWait) {
- if (busyWait) {
- steady_clock::time_point deadline = steady_clock::now() + us;
- while (steady_clock::now() < deadline) {
- for (int i = 0; i < 1000; i++) { }
- }
- } else {
- std::this_thread::sleep_for(us);
- }
-}
-
}
diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h
index 0d23cf7151f..37587f4dc3e 100644
--- a/fastos/src/vespa/fastos/timestamp.h
+++ b/fastos/src/vespa/fastos/timestamp.h
@@ -16,13 +16,6 @@ public:
static const TimeT MICRO = 1000*MILLI;
static const TimeT NANO = 1000*MICRO;
static const TimeT SEC = NANO;
- class Seconds {
- public:
- explicit Seconds(double v) : _v(v * NANO) {}
- TimeT val() const { return _v; }
- private:
- TimeT _v;
- };
TimeStamp() : _time(0) { }
TimeStamp(const timeval & tv) : _time(tv.tv_sec*SEC + tv.tv_usec*MILLI) { }
TimeStamp(int v) : _time(v) { }
@@ -31,7 +24,6 @@ public:
TimeStamp(unsigned long v) : _time(v) { }
TimeStamp(long long v) : _time(v) { }
TimeStamp(unsigned long long v) : _time(v) { }
- TimeStamp(Seconds v) : _time(v.val()) { }
TimeT val() const { return _time; }
operator TimeT () const { return val(); }
TimeStamp & operator += (TimeStamp b) { _time += b._time; return *this; }
@@ -53,48 +45,6 @@ inline TimeStamp operator -(TimeStamp a, TimeStamp b) { return TimeStamp(a.val()
inline TimeStamp operator *(long a, TimeStamp b) { return TimeStamp(a * b.val()); }
inline TimeStamp operator *(double a, TimeStamp b) { return TimeStamp(static_cast<int64_t>(a * b.val())); }
-class SteadyTimeStamp {
-public:
- SteadyTimeStamp() : _timeStamp() { }
- explicit SteadyTimeStamp(TimeStamp timeStamp) : _timeStamp(timeStamp) { }
-
- friend TimeStamp operator -(SteadyTimeStamp a, SteadyTimeStamp b) {
- return a._timeStamp - b._timeStamp;
- }
- friend SteadyTimeStamp operator -(SteadyTimeStamp a, TimeStamp b) {
- return SteadyTimeStamp(a._timeStamp - b);
- }
- friend SteadyTimeStamp operator +(SteadyTimeStamp a, TimeStamp b) {
- return SteadyTimeStamp(a._timeStamp + b);
- }
- friend bool operator != (SteadyTimeStamp a, SteadyTimeStamp b) {
- return a._timeStamp != b._timeStamp;
- }
- friend bool operator == (SteadyTimeStamp a, SteadyTimeStamp b) {
- return a._timeStamp == b._timeStamp;
- }
- friend bool operator < (SteadyTimeStamp a, SteadyTimeStamp b) {
- return a._timeStamp < b._timeStamp;
- }
- friend bool operator > (SteadyTimeStamp a, SteadyTimeStamp b) {
- return a._timeStamp > b._timeStamp;
- }
- std::string toString() const { return _timeStamp.toString(); };
-private:
- TimeStamp _timeStamp;
-};
-
-class StopWatch
-{
-public:
- StopWatch();
- void restart();
- TimeStamp elapsed() const;
- static void waitAtLeast(std::chrono::microseconds us, bool busyWait);
-private:
- SteadyTimeStamp _startTime;
-};
-
time_t time();
}
diff --git a/fastos/src/vespa/fastos/unix_process.cpp b/fastos/src/vespa/fastos/unix_process.cpp
index 4d4197f5354..087f800e668 100644
--- a/fastos/src/vespa/fastos/unix_process.cpp
+++ b/fastos/src/vespa/fastos/unix_process.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "process.h"
#include "unix_ipc.h"
-#include "timestamp.h"
#include "ringbuffer.h"
#include <vector>
#include <cstring>
@@ -41,6 +40,7 @@ extern char **environ;
#endif
using namespace std::chrono_literals;
+using namespace std::chrono;
static pid_t safe_fork ()
{
@@ -1600,7 +1600,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process,
bool timeOutKillAttempted = false;
- fastos::StopWatch timer;
+ steady_clock::time_point start = steady_clock::now();
if (pollStillRunning != nullptr)
*pollStillRunning = true;
@@ -1625,7 +1625,7 @@ FastOS_UNIX_ProcessStarter::Wait(FastOS_UNIX_Process *process,
if ((timeOutSeconds != -1) && !timeOutKillAttempted) {
- if (timer.elapsed().ms() >= (timeOutSeconds * 1000)) {
+ if ((steady_clock::now() - start) >= seconds(timeOutSeconds)) {
process->Kill();
timeOutKillAttempted = true;
}