Skip to content

Commit

Permalink
TIG-3421 Add actor debug information to actors (mongodb#652)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrachev authored Apr 15, 2022
1 parent ca58212 commit a3fd9cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/cast_core/src/HelloWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ struct HelloWorld::PhaseConfig {

void HelloWorld::run() {
for (auto&& config : _loop) {
// Note that this gets printed before any rate-limiting occurs.
// I.e an actor may print "Starting ... execution" then be rate-limited
// because rate-limiting is part of the inner actor iteration.
BOOST_LOG_TRIVIAL(debug) << "Starting " << this->actorInfo() << " execution";
for (auto _ : config) {
auto ctx = config->operation.start();
BOOST_LOG_TRIVIAL(info) << config->message;
Expand All @@ -51,6 +55,7 @@ void HelloWorld::run() {
config->syntheticOperation.report(metrics::clock::now(),
std::chrono::milliseconds{_helloCounter});
}
BOOST_LOG_TRIVIAL(debug) << "Ended " << this->actorInfo() << " execution";
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/gennylib/include/gennylib/Actor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef HEADER_00818641_6D7B_4A3D_AFC6_38CC0DBAD99B_INCLUDED
#define HEADER_00818641_6D7B_4A3D_AFC6_38CC0DBAD99B_INCLUDED

#include <string>

namespace genny {

using ActorId = unsigned int;
Expand Down Expand Up @@ -79,6 +81,15 @@ class Actor {
*/
// static std::string_view defaultName()


/**
* @return info string containing the actor type, name and id
* Can be used for debug logging.
*/
std::string actorInfo() const {
return _actorInfo;
}

/**
* The main method of an actor. Will be run in its own thread.
* This is only intended to be called by workload drivers.
Expand All @@ -96,6 +107,7 @@ class Actor {

private:
ActorId _id;
std::string _actorInfo;
};

} // namespace genny
Expand Down
12 changes: 12 additions & 0 deletions src/gennylib/include/gennylib/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ class ActorContext final : public v1::HasNode {
: v1::HasNode{node}, _workload{&workloadContext}, _phaseContexts{} {
_phaseContexts = constructPhaseContexts(_node, this);
auto threads = (*this)["Threads"].maybe<int>().value_or(1);
_actorType = (*this)["Type"].maybe<std::string>().value_or("no_type");
_actorName = (*this)["Name"].maybe<std::string>().value_or("no_name");
_nextActorId = this->workload().claimActorIds(threads);
}

Expand All @@ -353,6 +355,14 @@ class ActorContext final : public v1::HasNode {
return _nextActorId++;
}

/**
* @param id for this actor
* @return info string containing the actor type, name and id
*/
std::string actorInfo(ActorId id) const {
return _actorType + "::" + _actorName + "::" + std::to_string(id);
}

/**
* @return top-level workload configuration
*/
Expand Down Expand Up @@ -449,6 +459,8 @@ class ActorContext final : public v1::HasNode {
WorkloadContext* _workload;
std::unordered_map<PhaseNumber, std::unique_ptr<PhaseContext>> _phaseContexts;

std::string _actorType;
std::string _actorName;
std::atomic<ActorId> _nextActorId;
};

Expand Down
3 changes: 2 additions & 1 deletion src/gennylib/src/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#include <gennylib/context.hpp>

namespace genny {
Actor::Actor(ActorContext& context) : _id{context.nextActorId()} {}
Actor::Actor(ActorContext& context)
: _id{context.nextActorId()}, _actorInfo{context.actorInfo(_id)} {}
} // namespace genny
4 changes: 2 additions & 2 deletions src/gennylib/src/Orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ PhaseNumber Orchestrator::awaitPhaseStart(bool block, int addTokens) {
for (auto&& cb : _prePhaseHooks) {
cb(this);
}
BOOST_LOG_TRIVIAL(debug) << "Beginning phase " << currentPhase;
BOOST_LOG_TRIVIAL(info) << "Beginning phase " << currentPhase;
_phaseChange.notify_all();
state = State::PhaseStarted;
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ bool Orchestrator::awaitPhaseEnd(bool block, int removeTokens) {

if (_currentTokens <= 0) {
++_current;
BOOST_LOG_TRIVIAL(debug) << "Ended phase " << (this->_current - 1);
BOOST_LOG_TRIVIAL(info) << "Ended phase " << (this->_current - 1);
_phaseChange.notify_all();
state = State::PhaseEnded;
} else {
Expand Down

0 comments on commit a3fd9cb

Please sign in to comment.