Skip to content

Commit

Permalink
processor: Expose worker loop statistics in channel
Browse files Browse the repository at this point in the history
Worker has no messages so it can safely be exposed from channel
  • Loading branch information
shramov committed Nov 22, 2024
1 parent 7f77f2d commit 8b00722
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/processor/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,22 @@ int Worker::_init(const tll::Channel::Url &url, tll::Channel *master)
_ipc->callback_add(this, TLL_MESSAGE_MASK_DATA);
_child_add(_ipc.get(), "ipc");
loop.add(self());

if (_stat_enable) {
_stat.emplace(name);
internal.stat = &*_stat;
if (loop.stat(stat()))
return _log.fail(EINVAL, "Failed to enable stat on the loop");
}
return 0;
}

void Worker::_free()
{
_ipc.reset();
internal.stat = nullptr;
}

int Worker::_open(const ConstConfig &)
{
if (_setaffinity())
Expand Down
16 changes: 11 additions & 5 deletions src/processor/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ struct Worker : public tll::channel::Base<Worker>
static constexpr auto open_policy() { return OpenPolicy::Manual; }
static constexpr auto process_policy() { return ProcessPolicy::Never; }
static constexpr auto child_policy() { return ChildPolicy::Many; }
static constexpr auto stat_policy() { return StatPolicy::Manual; }
static constexpr std::string_view channel_protocol() { return "tll.worker"; }

tll::processor::Loop loop;

struct StatType : public Base::StatType
{
tll::stat::Integer<tll::stat::Sum, tll::stat::Unknown, 's', 't', 'e', 'p'> step;
tll::stat::Integer<tll::stat::Sum, tll::stat::Ns, 'p', 'o', 'l', 'l'> poll;
tll_stat_field_t padding[2] = {};
};

std::optional<tll::stat::Block<StatType>> _stat;

std::list<Object *> objects;
struct {
tll_state_t state = TLL_STATE_CLOSED;
Expand All @@ -40,11 +50,7 @@ struct Worker : public tll::channel::Base<Worker>
int _init(const tll::Channel::Url &url, tll::Channel *master);
int _open(const tll::ConstConfig &);
int _close();

void _free()
{
_ipc.reset();
}
void _free();

using tll::channel::Base<Worker>::post;

Expand Down

0 comments on commit 8b00722

Please sign in to comment.