Start adding state annotations for diagnostic screen
Summary: The plan is to add such state annotations around all core sonar tasks, so the diagnostic screen can show a useful up to date picture of what's going on. This is the first batch of such annotaions, to act as a tracer while putting the rest of the diagnostics code in place. Reviewed By: passy Differential Revision: D9150555 fbshipit-source-id: 5c25205ecc690f0101b444681be48b823b0cb052
This commit is contained in:
committed by
Facebook Github Bot
parent
91e94815b4
commit
d36518d1aa
@@ -47,14 +47,16 @@ void SonarClient::setStateListener(
|
|||||||
|
|
||||||
void SonarClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
|
void SonarClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||||
SONAR_LOG(("SonarClient::addPlugin " + plugin->identifier()).c_str());
|
SONAR_LOG(("SonarClient::addPlugin " + plugin->identifier()).c_str());
|
||||||
|
auto step = sonarState_->start("Add plugin " + plugin->identifier());
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
performAndReportError([this, plugin]() {
|
performAndReportError([this, plugin, step]() {
|
||||||
if (plugins_.find(plugin->identifier()) != plugins_.end()) {
|
if (plugins_.find(plugin->identifier()) != plugins_.end()) {
|
||||||
throw std::out_of_range(
|
throw std::out_of_range(
|
||||||
"plugin " + plugin->identifier() + " already added.");
|
"plugin " + plugin->identifier() + " already added.");
|
||||||
}
|
}
|
||||||
plugins_[plugin->identifier()] = plugin;
|
plugins_[plugin->identifier()] = plugin;
|
||||||
|
step->complete();
|
||||||
if (connected_) {
|
if (connected_) {
|
||||||
refreshPlugins();
|
refreshPlugins();
|
||||||
}
|
}
|
||||||
@@ -107,19 +109,22 @@ void SonarClient::refreshPlugins() {
|
|||||||
void SonarClient::onConnected() {
|
void SonarClient::onConnected() {
|
||||||
SONAR_LOG("SonarClient::onConnected");
|
SONAR_LOG("SonarClient::onConnected");
|
||||||
|
|
||||||
|
auto step = sonarState_->start("Connect");
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
connected_ = true;
|
connected_ = true;
|
||||||
|
step->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SonarClient::onDisconnected() {
|
void SonarClient::onDisconnected() {
|
||||||
SONAR_LOG("SonarClient::onDisconnected");
|
SONAR_LOG("SonarClient::onDisconnected");
|
||||||
|
auto step = sonarState_->start("onDisconnected callbacks");
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
connected_ = false;
|
connected_ = false;
|
||||||
performAndReportError([this]() {
|
performAndReportError([this, step]() {
|
||||||
for (const auto& iter : plugins_) {
|
for (const auto& iter : plugins_) {
|
||||||
disconnect(iter.second);
|
disconnect(iter.second);
|
||||||
}
|
}
|
||||||
|
step->complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,15 +42,21 @@ class SonarClient : public SonarWebSocket::Callbacks {
|
|||||||
SonarClient(std::unique_ptr<SonarWebSocket> socket)
|
SonarClient(std::unique_ptr<SonarWebSocket> socket)
|
||||||
: socket_(std::move(socket)) {
|
: socket_(std::move(socket)) {
|
||||||
sonarState_ = std::make_unique<SonarState>();
|
sonarState_ = std::make_unique<SonarState>();
|
||||||
|
auto step = sonarState_->start("Create client");
|
||||||
socket_->setCallbacks(this);
|
socket_->setCallbacks(this);
|
||||||
|
step->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
|
auto step = sonarState_->start("Start client");
|
||||||
socket_->start();
|
socket_->start();
|
||||||
|
step->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop() {
|
void stop() {
|
||||||
|
auto step = sonarState_->start("Stop client");
|
||||||
socket_->stop();
|
socket_->stop();
|
||||||
|
step->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onConnected() override;
|
void onConnected() override;
|
||||||
|
|||||||
Reference in New Issue
Block a user