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: D8954014

fbshipit-source-id: 864156b0d3f51eeb05c2c8916c1765e834f1dc8e
This commit is contained in:
John Knox
2018-08-03 07:34:34 -07:00
committed by Facebook Github Bot
parent fb447e4f84
commit c791a108f1
2 changed files with 14 additions and 3 deletions

View File

@@ -47,14 +47,16 @@ void SonarClient::setStateListener(
void SonarClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
SONAR_LOG(("SonarClient::addPlugin " + plugin->identifier()).c_str());
auto step = sonarState_->start("Add plugin " + plugin->identifier());
std::lock_guard<std::mutex> lock(mutex_);
performAndReportError([this, plugin]() {
performAndReportError([this, plugin, step]() {
if (plugins_.find(plugin->identifier()) != plugins_.end()) {
throw std::out_of_range(
"plugin " + plugin->identifier() + " already added.");
}
plugins_[plugin->identifier()] = plugin;
step->complete();
if (connected_) {
refreshPlugins();
}
@@ -107,19 +109,22 @@ void SonarClient::refreshPlugins() {
void SonarClient::onConnected() {
SONAR_LOG("SonarClient::onConnected");
auto step = sonarState_->start("Connect");
std::lock_guard<std::mutex> lock(mutex_);
connected_ = true;
step->complete();
}
void SonarClient::onDisconnected() {
SONAR_LOG("SonarClient::onDisconnected");
auto step = sonarState_->start("onDisconnected callbacks");
std::lock_guard<std::mutex> lock(mutex_);
connected_ = false;
performAndReportError([this]() {
performAndReportError([this, step]() {
for (const auto& iter : plugins_) {
disconnect(iter.second);
}
step->complete();
});
}

View File

@@ -42,15 +42,21 @@ class SonarClient : public SonarWebSocket::Callbacks {
SonarClient(std::unique_ptr<SonarWebSocket> socket)
: socket_(std::move(socket)) {
sonarState_ = std::make_unique<SonarState>();
auto step = sonarState_->start("Create client");
socket_->setCallbacks(this);
step->complete();
}
void start() {
auto step = sonarState_->start("Start client");
socket_->start();
step->complete();
}
void stop() {
auto step = sonarState_->start("Stop client");
socket_->stop();
step->complete();
}
void onConnected() override;