summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/features/debug_attribute_wait.cpp
blob: a19b5c7daa12dda32ad174c366ca5d6c874c1142 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "debug_attribute_wait.h"
#include <vespa/vespalib/util/time.h>
#include <vespa/vespalib/util/stash.h>


using search::attribute::IAttributeVector;
using namespace search::fef;

namespace search::features {

//-----------------------------------------------------------------------------

class DebugAttributeWaitExecutor : public FeatureExecutor
{
private:
    const IAttributeVector *_attribute;
    attribute::FloatContent  _buf;
    DebugAttributeWaitParams _params;

public:
    DebugAttributeWaitExecutor(const IQueryEnvironment &env,
                               const IAttributeVector * attribute,
                               const DebugAttributeWaitParams &params);
    void execute(uint32_t docId) override;
};

DebugAttributeWaitExecutor::DebugAttributeWaitExecutor(const IQueryEnvironment &,
                                                       const IAttributeVector *attribute,
                                                       const DebugAttributeWaitParams &params)
    : _attribute(attribute),
      _buf(),
      _params(params)
{ }

void
DebugAttributeWaitExecutor::execute(uint32_t docId)
{
    double waitTime = 0.0;

    if (_attribute != nullptr) {
        _buf.fill(*_attribute, docId);
        waitTime = _buf[0];
    }
    vespalib::Timer timer;
    vespalib::Timer::waitAtLeast(vespalib::from_s(waitTime), _params.busyWait);
    outputs().set_number(0, vespalib::to_s(timer.elapsed()));
}

//-----------------------------------------------------------------------------

DebugAttributeWaitBlueprint::DebugAttributeWaitBlueprint()
    : Blueprint("debugAttributeWait"),
      _params()
{
}

void
DebugAttributeWaitBlueprint::visitDumpFeatures(const IIndexEnvironment &, IDumpFeatureVisitor &) const
{
}

Blueprint::UP
DebugAttributeWaitBlueprint::createInstance() const
{
    return std::make_unique<DebugAttributeWaitBlueprint>();
}

bool
DebugAttributeWaitBlueprint::setup(const IIndexEnvironment &env, const ParameterList &params)
{
    _attribute = params[0].getValue();
    _params.busyWait = (params[1].asDouble() == 1.0);

    describeOutput("out", "actual time waited");
    env.hintAttributeAccess(_attribute);
    return true;
}

FeatureExecutor &
DebugAttributeWaitBlueprint::createExecutor(const IQueryEnvironment &env, vespalib::Stash &stash) const
{
    // Get attribute vector
    const IAttributeVector * attribute = env.getAttributeContext().getAttribute(_attribute);
    return stash.create<DebugAttributeWaitExecutor>(env, attribute, _params);
}

fef::ParameterDescriptions
DebugAttributeWaitBlueprint::getDescriptions() const
{
    return fef::ParameterDescriptions().desc().attribute(ParameterDataTypeSet::normalTypeSet(), ParameterCollection::ANY).number();
}

}