From c791a108f1516e974f4a57c587f54b7c2a7a1cec Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 3 Aug 2018 07:34:34 -0700 Subject: [PATCH] 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 --- xplat/Sonar/SonarClient.cpp | 11 ++++++++--- xplat/Sonar/SonarClient.h | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/xplat/Sonar/SonarClient.cpp b/xplat/Sonar/SonarClient.cpp index 2040f9ab9..9ac2fe9ca 100644 --- a/xplat/Sonar/SonarClient.cpp +++ b/xplat/Sonar/SonarClient.cpp @@ -47,14 +47,16 @@ void SonarClient::setStateListener( void SonarClient::addPlugin(std::shared_ptr plugin) { SONAR_LOG(("SonarClient::addPlugin " + plugin->identifier()).c_str()); + auto step = sonarState_->start("Add plugin " + plugin->identifier()); std::lock_guard 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 lock(mutex_); connected_ = true; + step->complete(); } void SonarClient::onDisconnected() { SONAR_LOG("SonarClient::onDisconnected"); - + auto step = sonarState_->start("onDisconnected callbacks"); std::lock_guard lock(mutex_); connected_ = false; - performAndReportError([this]() { + performAndReportError([this, step]() { for (const auto& iter : plugins_) { disconnect(iter.second); } + step->complete(); }); } diff --git a/xplat/Sonar/SonarClient.h b/xplat/Sonar/SonarClient.h index d569ab3ff..49f90b688 100644 --- a/xplat/Sonar/SonarClient.h +++ b/xplat/Sonar/SonarClient.h @@ -42,15 +42,21 @@ class SonarClient : public SonarWebSocket::Callbacks { SonarClient(std::unique_ptr socket) : socket_(std::move(socket)) { sonarState_ = std::make_unique(); + 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;