aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2019-03-05 10:32:58 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2019-03-05 12:17:02 +0000
commitd138c1667dfaf921d2fea1990f7964df1a4a48f8 (patch)
tree8226b41daa04d0909e402d2915def97880839bed /searchlib
parentd9a1b8be930da47e9c7b42ab44eecd29b385c170 (diff)
Add a simple Trace Object wrapping the slime.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/engine/searchapi/searchapi_test.cpp78
-rw-r--r--searchlib/src/vespa/searchlib/engine/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/engine/request.h1
-rw-r--r--searchlib/src/vespa/searchlib/engine/trace.cpp33
-rw-r--r--searchlib/src/vespa/searchlib/engine/trace.h38
5 files changed, 122 insertions, 29 deletions
diff --git a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp
index a517890620c..f06ce5c188c 100644
--- a/searchlib/src/tests/engine/searchapi/searchapi_test.cpp
+++ b/searchlib/src/tests/engine/searchapi/searchapi_test.cpp
@@ -1,10 +1,12 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/log/log.h>
-LOG_SETUP("searchapi_test");
+
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/searchlib/common/packets.h>
#include <vespa/searchlib/engine/searchapi.h>
#include <vespa/searchlib/engine/packetconverter.h>
+#include <vespa/vespalib/data/slime/slime.h>
+#include <vespa/log/log.h>
+LOG_SETUP("searchapi_test");
using namespace search::engine;
using namespace search::fs4transport;
@@ -28,18 +30,8 @@ template <typename T> void copyPacket(T &src, T &dst) {
} // namespace <unnamed>
-class Test : public vespalib::TestApp
-{
-public:
- void propertyNames();
- void convertToRequest();
- void convertFromReply();
- int Main() override;
-};
-
-void
-Test::propertyNames()
-{
+
+TEST("propertyNames") {
EXPECT_EQUAL(search::MapNames::RANK, "rank");
EXPECT_EQUAL(search::MapNames::FEATURE, "feature");
EXPECT_EQUAL(search::MapNames::HIGHLIGHTTERMS, "highlightterms");
@@ -47,9 +39,7 @@ Test::propertyNames()
EXPECT_EQUAL(search::MapNames::CACHES, "caches");
}
-void
-Test::convertToRequest()
-{
+TEST("convertToReques") {
FS4Packet_QUERYX src;
src._offset = 2u;
src._maxhits = 3u;
@@ -116,9 +106,7 @@ Test::convertToRequest()
}
}
-void
-Test::convertFromReply()
-{
+TEST("convertFromReply") {
SearchReply src;
src.offset = 1u;
src.totalHitCount = 2u;
@@ -240,14 +228,46 @@ Test::convertFromReply()
}
}
-int
-Test::Main()
-{
- TEST_INIT("searchapi_test");
- propertyNames();
- convertToRequest();
- convertFromReply();
- TEST_DONE();
+void verify(vespalib::stringref expected, const vespalib::Slime & slime) {
+ vespalib::Slime expectedSlime;
+ vespalib::slime::JsonFormat::decode(expected, expectedSlime);
+ EXPECT_EQUAL(expectedSlime, slime);
+}
+
+TEST("verify trace") {
+ Trace t(7);
+ verify("{"
+ " traces: ["
+ " ],"
+ " creation_time: 7"
+ "}",
+ t.getRoot());
+
+ t.createCursor("tag_a");
+ verify("{"
+ " traces: ["
+ " {"
+ " tag: 'tag_a'"
+ " }"
+ " ],"
+ " creation_time: 7"
+ "}",
+ t.getRoot());
+ Trace::Cursor & tagB = t.createCursor("tag_b");
+ tagB.setLong("long", 19);
+ verify("{"
+ " traces: ["
+ " {"
+ " tag: 'tag_a'"
+ " },"
+ " {"
+ " tag: 'tag_b',"
+ " long: 19"
+ " }"
+ " ],"
+ " creation_time: 7"
+ "}",
+ t.getRoot());
}
-TEST_APPHOOK(Test);
+TEST_MAIN() { TEST_RUN_ALL(); } \ No newline at end of file
diff --git a/searchlib/src/vespa/searchlib/engine/CMakeLists.txt b/searchlib/src/vespa/searchlib/engine/CMakeLists.txt
index 95b47b991af..e475d786a60 100644
--- a/searchlib/src/vespa/searchlib/engine/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/engine/CMakeLists.txt
@@ -13,6 +13,7 @@ vespa_add_library(searchlib_engine OBJECT
searchreply.cpp
searchrequest.cpp
source_description.cpp
+ trace.cpp
transport_metrics.cpp
transportserver.cpp
DEPENDS
diff --git a/searchlib/src/vespa/searchlib/engine/request.h b/searchlib/src/vespa/searchlib/engine/request.h
index 863c2db4e15..58c71cd8458 100644
--- a/searchlib/src/vespa/searchlib/engine/request.h
+++ b/searchlib/src/vespa/searchlib/engine/request.h
@@ -3,6 +3,7 @@
#pragma once
#include "propertiesmap.h"
+#include "trace.h"
#include <vespa/fastos/timestamp.h>
namespace search::engine {
diff --git a/searchlib/src/vespa/searchlib/engine/trace.cpp b/searchlib/src/vespa/searchlib/engine/trace.cpp
new file mode 100644
index 00000000000..381c851f40b
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/engine/trace.cpp
@@ -0,0 +1,33 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "trace.h"
+#include <vespa/vespalib/data/slime/slime.h>
+#include <vespa/fastos/timestamp.h>
+
+namespace search::engine {
+
+
+Trace::Trace(const fastos::TimeStamp &start_time)
+ : _trace(std::make_unique<vespalib::Slime>()),
+ _root(_trace->setObject()),
+ _traces(_root.setArray("traces"))
+{
+ _root.setLong("creation_time", start_time);
+}
+
+Trace::~Trace() = default;
+
+Trace::Cursor &
+Trace::createCursor(vespalib::stringref name) {
+ Cursor & trace = _traces.addObject();
+ trace.setString("tag", name);
+ return trace;
+
+}
+
+vespalib::string
+Trace::toString() const {
+ return _trace->toString();
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/engine/trace.h b/searchlib/src/vespa/searchlib/engine/trace.h
new file mode 100644
index 00000000000..4f2bea680df
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/engine/trace.h
@@ -0,0 +1,38 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include <vespa/vespalib/stllike/string.h>
+
+namespace fastos { class TimeStamp; }
+namespace vespalib { class Slime; }
+namespace vespalib::slime { class Cursor; }
+
+namespace search::engine {
+
+ /**
+ * Used for adding traces to a request. Acquire a new Cursor for everytime you want to trace something.
+ * Note that it is not thread safe. All use of any cursor aquired must be thread safe.
+ */
+class Trace
+{
+public:
+ using Cursor = vespalib::slime::Cursor;
+ Trace(const fastos::TimeStamp &start_time);
+ ~Trace();
+
+ /**
+ * Will give you a trace entry. It will also add a timestamp relative to the creation of the trace.
+ * @param name
+ * @return
+ */
+ Cursor & createCursor(vespalib::stringref name);
+ vespalib::string toString() const;
+ vespalib::Slime & getRoot() const { return *_trace; }
+private:
+ std::unique_ptr<vespalib::Slime> _trace;
+ Cursor & _root;
+ Cursor & _traces;
+};
+
+}