aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/executor_explorer_utils.cpp
blob: 2bccbe468cec745498f9d4c3566552ecfd229878 (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
96
97
98
99
100
101
102
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "executor_explorer_utils.h"
#include <vespa/vespalib/data/slime/cursor.h>
#include <vespa/vespalib/util/adaptive_sequenced_executor.h>
#include <vespa/vespalib/util/blockingthreadstackexecutor.h>
#include <vespa/vespalib/util/sequencedtaskexecutor.h>
#include <vespa/vespalib/util/singleexecutor.h>
#include <vespa/vespalib/util/threadstackexecutor.h>

using vespalib::AdaptiveSequencedExecutor;
using vespalib::BlockingThreadStackExecutor;
using vespalib::ISequencedTaskExecutor;
using vespalib::SequencedTaskExecutor;
using vespalib::SingleExecutor;
using vespalib::ThreadExecutor;
using vespalib::ThreadStackExecutor;
using vespalib::slime::Cursor;

namespace proton::explorer {

namespace {

void
convert_syncable_executor_to_slime(const ThreadExecutor& executor, const vespalib::string& type, Cursor& object)
{
    object.setString("type", type);
    object.setLong("num_threads", executor.getNumThreads());
    object.setLong("task_limit", executor.getTaskLimit());
}

void
convert_single_executor_to_slime(const SingleExecutor& executor, Cursor& object)
{
    convert_syncable_executor_to_slime(executor, "SingleExecutor", object);
    object.setLong("watermark", executor.get_watermark());
    object.setDouble("reaction_time_sec", vespalib::to_s(executor.get_reaction_time()));
}

void
set_type(Cursor& object, const vespalib::string& type)
{
    object.setString("type", type);
}

void
convert_sequenced_executor_to_slime(const SequencedTaskExecutor& executor, Cursor& object)
{
    set_type(object, "SequencedTaskExecutor");
    object.setLong("num_executors", executor.getNumExecutors());
    convert_executor_to_slime(executor.first_executor(), object.setObject("executor"));
}

void
convert_adaptive_executor_to_slime(const AdaptiveSequencedExecutor& executor, Cursor& object)
{
    set_type(object, "AdaptiveSequencedExecutor");
    object.setLong("num_strands", executor.getNumExecutors());
    auto cfg = executor.get_config();
    object.setLong("num_threads", cfg.num_threads);
    object.setLong("max_waiting", cfg.max_waiting);
    object.setLong("max_pending", cfg.max_pending);
    object.setLong("wakeup_limit", cfg.wakeup_limit);
}

}

void
convert_executor_to_slime(const ThreadExecutor* executor, Cursor& object)
{
    if (executor == nullptr) {
        return;
    }
    if (const auto* single = dynamic_cast<const SingleExecutor*>(executor)) {
        convert_single_executor_to_slime(*single, object);
    } else if (const auto* blocking = dynamic_cast<const BlockingThreadStackExecutor*>(executor)) {
        convert_syncable_executor_to_slime(*blocking, "BlockingThreadStackExecutor", object);
    } else if (const auto* thread = dynamic_cast<const ThreadStackExecutor*>(executor)) {
        convert_syncable_executor_to_slime(*thread, "ThreadStackExecutor", object);
    } else {
        convert_syncable_executor_to_slime(*executor, "ThreadExecutor", object);
    }
}

void
convert_executor_to_slime(const ISequencedTaskExecutor* executor, Cursor& object)
{
    if (executor == nullptr) {
        return;
    }
    if (const auto* seq = dynamic_cast<const SequencedTaskExecutor*>(executor)) {
        convert_sequenced_executor_to_slime(*seq, object);
    } else if (const auto* ada = dynamic_cast<const AdaptiveSequencedExecutor*>(executor)) {
        convert_adaptive_executor_to_slime(*ada, object);
    } else {
        set_type(object, "ISequencedTaskExecutor");
        object.setLong("num_executors", executor->getNumExecutors());
    }
}

}