summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-11-19 12:21:05 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-11-20 10:16:58 +0000
commit496e5cf57060fb068a9dc73ac7ff44333a60774e (patch)
treed8482043790e6c2fc673d66d8f1c1bd340d1d421
parent9225d36f8a4f5a6e12b8163c47d3cad272bd833c (diff)
Remove FastOS_Time usage
-rw-r--r--fastos/src/vespa/fastos/timestamp.cpp22
-rw-r--r--fastos/src/vespa/fastos/timestamp.h3
-rw-r--r--searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp17
-rw-r--r--searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp27
-rw-r--r--searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h6
-rw-r--r--searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp50
-rw-r--r--searchlib/src/vespa/searchlib/features/debug_wait.cpp40
-rw-r--r--searchlib/src/vespa/searchlib/features/nowfeature.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/features/nowfeature.h3
-rw-r--r--searchlib/src/vespa/searchlib/features/random_normal_feature.cpp32
-rw-r--r--searchlib/src/vespa/searchlib/features/randomfeature.cpp38
-rw-r--r--slobrok/src/vespa/slobrok/server/reserved_name.cpp21
-rw-r--r--slobrok/src/vespa/slobrok/server/reserved_name.h17
13 files changed, 141 insertions, 165 deletions
diff --git a/fastos/src/vespa/fastos/timestamp.cpp b/fastos/src/vespa/fastos/timestamp.cpp
index a1da4322f8c..5daad63f698 100644
--- a/fastos/src/vespa/fastos/timestamp.cpp
+++ b/fastos/src/vespa/fastos/timestamp.cpp
@@ -2,6 +2,7 @@
#include "timestamp.h"
#include <chrono>
#include <cmath>
+#include <thread>
#include <sys/time.h>
using namespace std::chrono;
@@ -90,10 +91,31 @@ StopWatch::StopWatch()
_stopTime(_startTime)
{ }
+void
+StopWatch::restart() {
+ _startTime = steady_now();
+ _stopTime = _startTime;
+}
+
StopWatch &
StopWatch::stop() {
_stopTime = steady_now();
return *this;
}
+void
+StopWatch::waitAtLeast(std::chrono::microseconds us, bool busyWait) {
+ steady_clock::time_point startTime = steady_clock::now();
+ steady_clock::time_point deadline = startTime + us;
+ while (steady_clock::now() < deadline) {
+ if (busyWait) {
+ for (int i = 0; i < 1000; i++)
+ ;
+ } else {
+ microseconds rem = (us - duration_cast<microseconds>(steady_clock::now() - startTime));
+ std::this_thread::sleep_for(rem);
+ }
+ }
+}
+
}
diff --git a/fastos/src/vespa/fastos/timestamp.h b/fastos/src/vespa/fastos/timestamp.h
index c670e9f9b49..36f296b891f 100644
--- a/fastos/src/vespa/fastos/timestamp.h
+++ b/fastos/src/vespa/fastos/timestamp.h
@@ -4,6 +4,7 @@
#include <cstdint>
#include <limits>
#include <string>
+#include <chrono>
namespace fastos {
@@ -152,11 +153,13 @@ public:
StopWatch();
StopWatch & stop();
+ void restart();
TimeStamp elapsed() const {
TimeStamp diff(_stopTime - _startTime);
return (diff > 0) ? diff : TimeStamp(0);
}
+ static void waitAtLeast(std::chrono::microseconds us, bool busyWait);
private:
SteadyTimeStamp _startTime;
SteadyTimeStamp _stopTime;
diff --git a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
index 1834beb9590..b976f76c3fb 100644
--- a/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
+++ b/searchlib/src/apps/vespa-attribute-inspect/vespa-attribute-inspect.cpp
@@ -153,29 +153,28 @@ LoadAttribute::Main()
vespalib::string fileName(_argv[idx]);
vespalib::FileHeader fh;
- do {
+ {
vespalib::string datFileName(fileName + ".dat");
Fast_BufferedFile file;
file.ReadOpenExisting(datFileName.c_str());
(void) fh.readFile(file);
- } while (0);
+ }
attribute::BasicType bt(fh.getTag("datatype").asString());
attribute::CollectionType ct(fh.getTag("collectiontype").asString());
attribute::Config c(bt, ct);
c.setFastSearch(doFastSearch);
c.setHuge(doHuge);
AttributePtr ptr = AttributeFactory::createAttribute(fileName, c);
- FastOS_Time timer;
- timer.SetNow();
+ fastos::StopWatch timer;
load(ptr);
- std::cout << "load time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "load time: " << timer.stop().elapsed().ms() << " seconds " << std::endl;
std::cout << "numDocs: " << ptr->getNumDocs() << std::endl;
if (doApplyUpdate) {
- timer.SetNow();
+ timer.restart();
applyUpdate(ptr);
- std::cout << "update time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "update time: " << timer.stop().elapsed().ms() << " seconds " << std::endl;
}
if (doPrintContent) {
@@ -192,9 +191,9 @@ LoadAttribute::Main()
if (doSave) {
vespalib::string saveFile = fileName + ".save";
std::cout << "saving attribute: " << saveFile << std::endl;
- timer.SetNow();
+ timer.restart();
ptr->save(saveFile);
- std::cout << "save time: " << timer.MilliSecsToNow() / 1000 << " seconds " << std::endl;
+ std::cout << "save time: " << timer.stop().elapsed().ms() << " seconds " << std::endl;
}
return 0;
diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
index 5c09f2d80bf..309100f3afd 100644
--- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
+++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.cpp
@@ -1,14 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debugwaitfunctionnode.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
-namespace search {
-namespace expression {
+namespace search::expression {
using vespalib::FieldBase;
using vespalib::Serializer;
using vespalib::Deserializer;
+using namespace std::chrono;
IMPLEMENT_EXPRESSIONNODE(DebugWaitFunctionNode, UnaryFunctionNode);
@@ -17,9 +16,7 @@ DebugWaitFunctionNode::DebugWaitFunctionNode()
_busyWait(true)
{ }
-DebugWaitFunctionNode::~DebugWaitFunctionNode()
-{
-}
+DebugWaitFunctionNode::~DebugWaitFunctionNode() = default;
DebugWaitFunctionNode::DebugWaitFunctionNode(ExpressionNode::UP arg, double waitTime, bool busyWait)
: UnaryFunctionNode(std::move(arg)),
@@ -28,22 +25,13 @@ DebugWaitFunctionNode::DebugWaitFunctionNode(ExpressionNode::UP arg, double wait
{
}
+using std::chrono::microseconds;
+
bool
DebugWaitFunctionNode::onExecute() const
{
- FastOS_Time time;
- time.SetNow();
- double millis = _waitTime * 1000.0;
+ fastos::StopWatch::waitAtLeast(microseconds(static_cast<long>(_waitTime * 1000000)), _busyWait);
- while (time.MilliSecsToNow() < millis) {
- if (_busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
getArg().execute();
updateResult().assign(getArg().getResult());
return true;
@@ -73,7 +61,6 @@ DebugWaitFunctionNode::visitMembers(vespalib::ObjectVisitor &visitor) const
}
}
-}
// this function was added by ../../forcelink.sh
void forcelink_file_searchlib_expression_debugwaitfunctionnode() {}
diff --git a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
index e5958a89bd0..c98a7dc36b5 100644
--- a/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
+++ b/searchlib/src/vespa/searchlib/expression/debugwaitfunctionnode.h
@@ -6,8 +6,7 @@
#include "resultvector.h"
#include <vespa/searchlib/common/sortspec.h>
-namespace search {
-namespace expression {
+namespace search::expression {
class DebugWaitFunctionNode : public UnaryFunctionNode
{
@@ -15,7 +14,7 @@ public:
DECLARE_EXPRESSIONNODE(DebugWaitFunctionNode);
DECLARE_NBO_SERIALIZE;
DebugWaitFunctionNode();
- ~DebugWaitFunctionNode();
+ ~DebugWaitFunctionNode() override;
DebugWaitFunctionNode(ExpressionNode::UP arg, double waitTime, bool busyWait);
void visitMembers(vespalib::ObjectVisitor &visitor) const override;
private:
@@ -25,4 +24,3 @@ private:
};
}
-}
diff --git a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
index 99645cc3338..57c4b3ca9a1 100644
--- a/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
+++ b/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
@@ -1,16 +1,13 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debug_attribute_wait.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
using search::attribute::IAttributeVector;
+using namespace search::fef;
+using namespace std::chrono;
-namespace search {
-
-using namespace fef;
-
-namespace features {
+namespace search::features {
//-----------------------------------------------------------------------------
@@ -28,39 +25,26 @@ public:
void execute(uint32_t docId) override;
};
-DebugAttributeWaitExecutor::DebugAttributeWaitExecutor(const IQueryEnvironment &env,
+DebugAttributeWaitExecutor::DebugAttributeWaitExecutor(const IQueryEnvironment &,
const IAttributeVector *attribute,
const DebugAttributeWaitParams &params)
: _attribute(attribute),
_buf(),
_params(params)
-{
- (void)env;
-}
+{ }
void
DebugAttributeWaitExecutor::execute(uint32_t docId)
{
double waitTime = 0.0;
- FastOS_Time time;
- time.SetNow();
- if (_attribute != NULL) {
+ if (_attribute != nullptr) {
_buf.fill(*_attribute, docId);
waitTime = _buf[0];
}
- double millis = waitTime * 1000.0;
-
- while (time.MilliSecsToNow() < millis) {
- if (_params.busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
- outputs().set_number(0, 1.0e-6 * time.MicroSecsToNow());
+ steady_clock::time_point start = steady_clock::now();
+ fastos::StopWatch::waitAtLeast(microseconds(static_cast<long>(waitTime * 1000000)), _params.busyWait);
+ outputs().set_number(0, (1.0e-6 * (steady_clock::now() - start)).count());
}
//-----------------------------------------------------------------------------
@@ -72,22 +56,19 @@ DebugAttributeWaitBlueprint::DebugAttributeWaitBlueprint()
}
void
-DebugAttributeWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &env, IDumpFeatureVisitor &visitor) const
+DebugAttributeWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
- (void)env;
- (void)visitor;
}
Blueprint::UP
DebugAttributeWaitBlueprint::createInstance() const
{
- return Blueprint::UP(new DebugAttributeWaitBlueprint());
+ return std::make_unique<DebugAttributeWaitBlueprint>();
}
bool
DebugAttributeWaitBlueprint::setup(const IIndexEnvironment &env, const ParameterList &params)
{
- (void)env;
_attribute = params[0].getValue();
_params.busyWait = (params[1].asDouble() == 1.0);
@@ -107,10 +88,7 @@ DebugAttributeWaitBlueprint::createExecutor(const IQueryEnvironment &env, vespal
fef::ParameterDescriptions
DebugAttributeWaitBlueprint::getDescriptions() const
{
- return fef::ParameterDescriptions().desc().attribute(fef::ParameterDataTypeSet::normalTypeSet(), fef::ParameterCollection::ANY).number();
+ return fef::ParameterDescriptions().desc().attribute(ParameterDataTypeSet::normalTypeSet(), ParameterCollection::ANY).number();
}
-//-----------------------------------------------------------------------------
-
-} // namespace features
-} // namespace search
+}
diff --git a/searchlib/src/vespa/searchlib/features/debug_wait.cpp b/searchlib/src/vespa/searchlib/features/debug_wait.cpp
index 6a26b24b451..c30a026137c 100644
--- a/searchlib/src/vespa/searchlib/features/debug_wait.cpp
+++ b/searchlib/src/vespa/searchlib/features/debug_wait.cpp
@@ -1,14 +1,11 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "debug_wait.h"
-#include <vespa/fastos/time.h>
-#include <thread>
+#include <vespa/fastos/timestamp.h>
-namespace search {
+using namespace search::fef;
-using namespace fef;
-
-namespace features {
+namespace search::features {
//-----------------------------------------------------------------------------
@@ -22,29 +19,19 @@ public:
void execute(uint32_t docId) override;
};
-DebugWaitExecutor::DebugWaitExecutor(const IQueryEnvironment &env, const DebugWaitParams &params)
+DebugWaitExecutor::DebugWaitExecutor(const IQueryEnvironment &, const DebugWaitParams &params)
: _params(params)
{
- (void)env;
}
+using namespace std::chrono;
+
void
DebugWaitExecutor::execute(uint32_t)
{
- FastOS_Time time;
- time.SetNow();
- double millis = _params.waitTime * 1000.0;
-
- while (time.MilliSecsToNow() < millis) {
- if (_params.busyWait) {
- for (int i = 0; i < 1000; i++)
- ;
- } else {
- int rem = (int)(millis - time.MilliSecsToNow());
- std::this_thread::sleep_for(std::chrono::milliseconds(rem));
- }
- }
- outputs().set_number(0, 1.0e-6 * time.MicroSecsToNow());
+ steady_clock::time_point start = steady_clock::now();
+ fastos::StopWatch::waitAtLeast(microseconds(static_cast<long>(_params.waitTime * 1000000)), _params.busyWait);
+ outputs().set_number(0, (1.0e-6 * (steady_clock::now() - start)).count());
}
//-----------------------------------------------------------------------------
@@ -56,16 +43,14 @@ DebugWaitBlueprint::DebugWaitBlueprint()
}
void
-DebugWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &env, IDumpFeatureVisitor &visitor) const
+DebugWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
- (void)env;
- (void)visitor;
}
Blueprint::UP
DebugWaitBlueprint::createInstance() const
{
- return Blueprint::UP(new DebugWaitBlueprint());
+ return std::make_unique<DebugWaitBlueprint>();
}
bool
@@ -87,5 +72,4 @@ DebugWaitBlueprint::createExecutor(const IQueryEnvironment &env, vespalib::Stash
//-----------------------------------------------------------------------------
-} // namespace features
-} // namespace search
+}
diff --git a/searchlib/src/vespa/searchlib/features/nowfeature.cpp b/searchlib/src/vespa/searchlib/features/nowfeature.cpp
index 76cbd3fa05c..074acb2e890 100644
--- a/searchlib/src/vespa/searchlib/features/nowfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/nowfeature.cpp
@@ -1,16 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "nowfeature.h"
-#include <vespa/searchlib/fef/featurenamebuilder.h>
#include <vespa/searchlib/fef/queryproperties.h>
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/fastos/time.h>
+#include <chrono>
-namespace search {
-namespace features {
+namespace search::features {
NowExecutor::NowExecutor(int64_t timestamp) :
- search::fef::FeatureExecutor(),
+ fef::FeatureExecutor(),
_timestamp(timestamp)
{
}
@@ -21,39 +19,37 @@ NowExecutor::execute(uint32_t) {
}
void
-NowBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &visitor) const
+NowBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &visitor) const
{
visitor.visitDumpFeature(getBaseName());
}
bool
-NowBlueprint::setup(const search::fef::IIndexEnvironment &,
- const search::fef::ParameterList &)
+NowBlueprint::setup(const fef::IIndexEnvironment &, const fef::ParameterList &)
{
describeOutput("out", "The timestamp (seconds since epoch) of query execution.");
return true;
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
NowBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new NowBlueprint());
+ return std::make_unique<NowBlueprint>();
}
-search::fef::FeatureExecutor &
-NowBlueprint::createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+NowBlueprint::createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const
{
int64_t timestamp;
const fef::Property &prop = env.getProperties().lookup(fef::queryproperties::now::SystemTime::NAME);
if (prop.found()) {
timestamp = atoll(prop.get().c_str());
} else {
- FastOS_Time now;
- now.SetNow();
- timestamp = (int64_t)now.Secs();
+ timestamp = duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
}
return stash.create<NowExecutor>(timestamp);
}
-}}
+}
diff --git a/searchlib/src/vespa/searchlib/features/nowfeature.h b/searchlib/src/vespa/searchlib/features/nowfeature.h
index e9191689fb2..73a19048a00 100644
--- a/searchlib/src/vespa/searchlib/features/nowfeature.h
+++ b/searchlib/src/vespa/searchlib/features/nowfeature.h
@@ -36,8 +36,7 @@ public:
fef::ParameterDescriptions getDescriptions() const override {
return fef::ParameterDescriptions().desc();
}
- bool setup(const fef::IIndexEnvironment & env,
- const fef::ParameterList & params) override;
+ bool setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params) override;
fef::FeatureExecutor &createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const override;
};
diff --git a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
index 99de8ba31e2..91ed78fafa3 100644
--- a/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
+++ b/searchlib/src/vespa/searchlib/features/random_normal_feature.cpp
@@ -3,16 +3,16 @@
#include "random_normal_feature.h"
#include "utils.h"
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/fastos/time.h>
+#include <chrono>
#include <vespa/log/log.h>
LOG_SETUP(".features.randomnormalfeature");
namespace search::features {
-RandomNormalExecutor::RandomNormalExecutor(uint64_t seed, double mean, double stddev) :
- search::fef::FeatureExecutor(),
- _rnd(mean, stddev, true)
+RandomNormalExecutor::RandomNormalExecutor(uint64_t seed, double mean, double stddev)
+ : fef::FeatureExecutor(),
+ _rnd(mean, stddev, true)
{
LOG(debug, "RandomNormalExecutor: seed=%" PRIu64 ", mean=%f, stddev=%f", seed, mean, stddev);
_rnd.seed(seed);
@@ -25,7 +25,7 @@ RandomNormalExecutor::execute(uint32_t)
}
RandomNormalBlueprint::RandomNormalBlueprint() :
- search::fef::Blueprint("randomNormal"),
+ fef::Blueprint("randomNormal"),
_seed(0),
_mean(0.0),
_stddev(1.0)
@@ -33,22 +33,20 @@ RandomNormalBlueprint::RandomNormalBlueprint() :
}
void
-RandomNormalBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &) const
+RandomNormalBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &) const
{
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
RandomNormalBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new RandomNormalBlueprint());
+ return std::make_unique<RandomNormalBlueprint>();
}
bool
-RandomNormalBlueprint::setup(const search::fef::IIndexEnvironment & env,
- const search::fef::ParameterList & params)
+RandomNormalBlueprint::setup(const fef::IIndexEnvironment & env, const fef::ParameterList & params)
{
- search::fef::Property p = env.getProperties().lookup(getName(), "seed");
+ fef::Property p = env.getProperties().lookup(getName(), "seed");
if (p.found()) {
_seed = util::strToNum<uint64_t>(p.get());
}
@@ -64,14 +62,14 @@ RandomNormalBlueprint::setup(const search::fef::IIndexEnvironment & env,
return true;
}
-search::fef::FeatureExecutor &
-RandomNormalBlueprint::createExecutor(const search::fef::IQueryEnvironment &, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+RandomNormalBlueprint::createExecutor(const fef::IQueryEnvironment &, vespalib::Stash &stash) const
{
uint64_t seed = _seed;
if (seed == 0) {
- FastOS_Time time;
- time.SetNow();
- seed = static_cast<uint64_t>(time.MicroSecs()) ^
+ seed = static_cast<uint64_t>(duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count()) ^
reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads
}
return stash.create<RandomNormalExecutor>(seed, _mean, _stddev);
diff --git a/searchlib/src/vespa/searchlib/features/randomfeature.cpp b/searchlib/src/vespa/searchlib/features/randomfeature.cpp
index cdedbcadc5e..db5ccc67a60 100644
--- a/searchlib/src/vespa/searchlib/features/randomfeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/randomfeature.cpp
@@ -3,19 +3,17 @@
#include "randomfeature.h"
#include "utils.h"
#include <vespa/searchlib/fef/properties.h>
-#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/fastos/time.h>
-
+#include <chrono>
#include <vespa/log/log.h>
LOG_SETUP(".features.randomfeature");
namespace search::features {
-RandomExecutor::RandomExecutor(uint64_t seed, uint64_t matchSeed) :
- search::fef::FeatureExecutor(),
- _rnd(),
- _matchRnd(),
- _matchSeed(matchSeed)
+RandomExecutor::RandomExecutor(uint64_t seed, uint64_t matchSeed)
+ : fef::FeatureExecutor(),
+ _rnd(),
+ _matchRnd(),
+ _matchSeed(matchSeed)
{
LOG(debug, "RandomExecutor: seed=%" PRIu64 ", matchSeed=%" PRIu64, seed, matchSeed);
_rnd.srand48(seed);
@@ -33,28 +31,26 @@ RandomExecutor::execute(uint32_t docId)
RandomBlueprint::RandomBlueprint() :
- search::fef::Blueprint("random"),
+ fef::Blueprint("random"),
_seed(0)
{
}
void
-RandomBlueprint::visitDumpFeatures(const search::fef::IIndexEnvironment &,
- search::fef::IDumpFeatureVisitor &) const
+RandomBlueprint::visitDumpFeatures(const fef::IIndexEnvironment &, fef::IDumpFeatureVisitor &) const
{
}
-search::fef::Blueprint::UP
+fef::Blueprint::UP
RandomBlueprint::createInstance() const
{
- return search::fef::Blueprint::UP(new RandomBlueprint());
+ return std::make_unique<RandomBlueprint>();
}
bool
-RandomBlueprint::setup(const search::fef::IIndexEnvironment & env,
- const search::fef::ParameterList &)
+RandomBlueprint::setup(const fef::IIndexEnvironment & env, const fef::ParameterList &)
{
- search::fef::Property p = env.getProperties().lookup(getName(), "seed");
+ fef::Property p = env.getProperties().lookup(getName(), "seed");
if (p.found()) {
_seed = util::strToNum<uint64_t>(p.get());
}
@@ -63,14 +59,14 @@ RandomBlueprint::setup(const search::fef::IIndexEnvironment & env,
return true;
}
-search::fef::FeatureExecutor &
-RandomBlueprint::createExecutor(const search::fef::IQueryEnvironment &env, vespalib::Stash &stash) const
+using namespace std::chrono;
+
+fef::FeatureExecutor &
+RandomBlueprint::createExecutor(const fef::IQueryEnvironment &env, vespalib::Stash &stash) const
{
uint64_t seed = _seed;
if (seed == 0) {
- FastOS_Time time;
- time.SetNow();
- seed = static_cast<uint64_t>(time.MicroSecs()) ^
+ seed = static_cast<uint64_t>(duration_cast<microseconds>(steady_clock::now().time_since_epoch()).count()) ^
reinterpret_cast<uint64_t>(&seed); // results in different seeds in different threads
}
uint64_t matchSeed = util::strToNum<uint64_t>
diff --git a/slobrok/src/vespa/slobrok/server/reserved_name.cpp b/slobrok/src/vespa/slobrok/server/reserved_name.cpp
index 389154f16b8..76e8738a79b 100644
--- a/slobrok/src/vespa/slobrok/server/reserved_name.cpp
+++ b/slobrok/src/vespa/slobrok/server/reserved_name.cpp
@@ -1,2 +1,23 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "reserved_name.h"
+
+using std::chrono::duration_cast;
+
+namespace slobrok {
+
+ReservedName::ReservedName(const std::string &name, const std::string &spec, bool local)
+ : NamedService(name, spec),
+ _reservedTime(steady_clock::now()),
+ isLocal(local)
+{ }
+
+bool
+ReservedName::stillReserved() const {
+ return (milliseconds() < 15000);
+}
+
+int64_t ReservedName::milliseconds() const {
+ return duration_cast<std::chrono::seconds>(steady_clock::now() - _reservedTime).count();
+}
+
+} \ No newline at end of file
diff --git a/slobrok/src/vespa/slobrok/server/reserved_name.h b/slobrok/src/vespa/slobrok/server/reserved_name.h
index 1ebed4b94dc..0b2a4c392ee 100644
--- a/slobrok/src/vespa/slobrok/server/reserved_name.h
+++ b/slobrok/src/vespa/slobrok/server/reserved_name.h
@@ -2,7 +2,7 @@
#pragma once
#include "named_service.h"
-#include <vespa/fastos/time.h>
+#include <chrono>
namespace slobrok {
@@ -18,19 +18,14 @@ namespace slobrok {
class ReservedName: public NamedService
{
private:
- FastOS_Time _reservedTime;
+ using steady_clock = std::chrono::steady_clock;
+ steady_clock::time_point _reservedTime;
+ int64_t milliseconds() const;
public:
const bool isLocal;
- ReservedName(const std::string &name, const std::string &spec, bool local)
- : NamedService(name, spec), _reservedTime(), isLocal(local)
- {
- _reservedTime.SetNow();
- }
- bool stillReserved() const {
- return (_reservedTime.MilliSecsToNow() < 15000);
- }
- int seconds() const { return _reservedTime.MilliSecsToNow() / 1000; }
+ ReservedName(const std::string &name, const std::string &spec, bool local);
+ bool stillReserved() const;
};
//-----------------------------------------------------------------------------