Add getStateSummary method for diagnostics
Summary: Adds a more structured representation of state updates than a multiline string. Also changes the string form to omit [started] records. Reviewed By: danielbuechele Differential Revision: D9315503 fbshipit-source-id: 55b8f9572091fd42fe852c8d26a8f2a53f76c82a
This commit is contained in:
committed by
Facebook Github Bot
parent
e51b8c0742
commit
660da3f80e
@@ -23,6 +23,7 @@
|
||||
#include <Sonar/SonarConnection.h>
|
||||
#include <Sonar/SonarResponder.h>
|
||||
#include <Sonar/SonarStateUpdateListener.h>
|
||||
#include <Sonar/SonarState.h>
|
||||
|
||||
using namespace facebook;
|
||||
using namespace facebook::sonar;
|
||||
@@ -249,6 +250,21 @@ class JSonarPluginWrapper : public SonarPlugin {
|
||||
JSonarPluginWrapper(jni::global_ref<JSonarPlugin> plugin): jplugin(plugin) {}
|
||||
};
|
||||
|
||||
struct JStateSummary : public jni::JavaClass<JStateSummary> {
|
||||
public:
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/sonar/core/StateSummary;";
|
||||
|
||||
static jni::local_ref<JStateSummary> create() {
|
||||
return newInstance();
|
||||
}
|
||||
|
||||
void addEntry(std::string name, std::string state) {
|
||||
static const auto method = javaClassStatic()->getMethod<void(std::string, std::string)>("addEntry");
|
||||
return method(self(), name, state);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class JSonarClient : public jni::HybridClass<JSonarClient> {
|
||||
public:
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/sonar/android/SonarClientImpl;";
|
||||
@@ -265,6 +281,7 @@ class JSonarClient : public jni::HybridClass<JSonarClient> {
|
||||
makeNativeMethod("unsubscribe", JSonarClient::unsubscribe),
|
||||
makeNativeMethod("getPlugin", JSonarClient::getPlugin),
|
||||
makeNativeMethod("getState", JSonarClient::getState),
|
||||
makeNativeMethod("getStateSummary", JSonarClient::getStateSummary),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -307,6 +324,21 @@ class JSonarClient : public jni::HybridClass<JSonarClient> {
|
||||
return SonarClient::instance()->getState();
|
||||
}
|
||||
|
||||
jni::global_ref<JStateSummary::javaobject> getStateSummary() {
|
||||
auto summary = jni::make_global(JStateSummary::create());
|
||||
auto elements = SonarClient::instance()->getStateElements();
|
||||
for (auto&& element : elements) {
|
||||
std::string status;
|
||||
switch (element.state_) {
|
||||
case State::in_progress: status = "IN_PROGRESS"; break;
|
||||
case State::failed: status = "FAILED"; break;
|
||||
case State::success: status = "SUCCESS"; break;
|
||||
}
|
||||
summary->addEntry(element.name_, status);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
jni::alias_ref<JSonarPlugin> getPlugin(const std::string& identifier) {
|
||||
auto plugin = SonarClient::instance()->getPlugin(identifier);
|
||||
if (plugin) {
|
||||
@@ -347,7 +379,6 @@ class JSonarClient : public jni::HybridClass<JSonarClient> {
|
||||
private:
|
||||
friend HybridBase;
|
||||
std::shared_ptr<SonarStateUpdateListener> mStateListener = nullptr;
|
||||
|
||||
JSonarClient() {}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.facebook.sonar.BuildConfig;
|
||||
import com.facebook.sonar.core.SonarClient;
|
||||
import com.facebook.sonar.core.SonarPlugin;
|
||||
import com.facebook.sonar.core.SonarStateUpdateListener;
|
||||
import com.facebook.sonar.core.StateSummary;
|
||||
|
||||
@DoNotStrip
|
||||
class SonarClientImpl implements SonarClient {
|
||||
@@ -65,4 +66,7 @@ class SonarClientImpl implements SonarClient {
|
||||
|
||||
@Override
|
||||
public native String getState();
|
||||
|
||||
@Override
|
||||
public native StateSummary getStateSummary();
|
||||
}
|
||||
|
||||
@@ -23,4 +23,6 @@ public interface SonarClient {
|
||||
void unsubscribe();
|
||||
|
||||
String getState();
|
||||
|
||||
StateSummary getStateSummary();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.facebook.sonar.core;
|
||||
|
||||
public class StateElement {
|
||||
private final String mName;
|
||||
private final String mState;
|
||||
public StateElement(String name, String state) {
|
||||
mName = name;
|
||||
mState = state;
|
||||
}
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.facebook.sonar.core;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class StateSummary {
|
||||
|
||||
public enum State {
|
||||
IN_PROGRESS, SUCCESS, FAILED, UNKNOWN;
|
||||
}
|
||||
|
||||
public static class StateElement {
|
||||
private final String mName;
|
||||
private final State mState;
|
||||
public StateElement(String name, State state) {
|
||||
mName = name;
|
||||
mState = state;
|
||||
}
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
public State getState() {
|
||||
return mState;
|
||||
}
|
||||
}
|
||||
|
||||
public final List<StateElement> mList = new ArrayList<>();
|
||||
|
||||
public void addEntry(String name, String state) {
|
||||
State s;
|
||||
try {
|
||||
s = State.valueOf(state);
|
||||
} catch (RuntimeException e) {
|
||||
s = State.UNKNOWN;
|
||||
}
|
||||
mList.add(new StateElement(name, s));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user