From 40b80af39d764de7ada42d8d77f4492b8a957c57 Mon Sep 17 00:00:00 2001
From: joshemb <josh@elixxir.io>
Date: Tue, 13 Sep 2022 11:32:22 -0700
Subject: [PATCH] Add a debug GetRunningProcesses to bindings

---
 bindings/follow.go |  6 ++++++
 stoppable/multi.go | 25 +++++++++++++++++++++++--
 xxdk/cmix.go       |  6 ++++++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/bindings/follow.go b/bindings/follow.go
index 2303274e3..e9b509761 100644
--- a/bindings/follow.go
+++ b/bindings/follow.go
@@ -136,6 +136,12 @@ func (c *Cmix) IsHealthy() bool {
 	return c.api.GetCmix().IsHealthy()
 }
 
+// GetRunningProcesses returns the name of all running processes at the time
+// of this call.
+func (c *Cmix) GetRunningProcesses() []string {
+	return c.api.GetRunningProcesses()
+}
+
 // NetworkHealthCallback contains a callback that is used to receive
 // notification if network health changes.
 type NetworkHealthCallback interface {
diff --git a/stoppable/multi.go b/stoppable/multi.go
index 81bd27025..7e8027fa5 100644
--- a/stoppable/multi.go
+++ b/stoppable/multi.go
@@ -61,10 +61,13 @@ func (m *Multi) GetStatus() Status {
 	lowestStatus := Stopped
 	m.mux.RLock()
 
-	for _, s := range m.stoppables {
+	for i := range m.stoppables {
+		s := m.stoppables[i]
 		status := s.GetStatus()
 		if status < lowestStatus {
 			lowestStatus = status
+			jww.DEBUG.Printf("Stoppable %s has status %s",
+				s.Name(), status.String())
 		}
 	}
 
@@ -73,6 +76,24 @@ func (m *Multi) GetStatus() Status {
 	return lowestStatus
 }
 
+// GetRunningProcesses returns a list of running Stoppable processes.
+func (m *Multi) GetRunningProcesses() []string {
+	m.mux.RLock()
+
+	runningProcesses := make([]string, 0)
+	for i := range m.stoppables {
+		s := m.stoppables[i]
+		status := s.GetStatus()
+		if status < Stopped {
+			runningProcesses = append(runningProcesses, s.Name())
+		}
+	}
+
+	m.mux.RUnlock()
+
+	return runningProcesses
+}
+
 // IsRunning returns true if Stoppable is marked as running.
 func (m *Multi) IsRunning() bool {
 	return m.GetStatus() == Running
@@ -90,7 +111,7 @@ func (m *Multi) IsStopped() bool {
 
 // Close issues a close signal to all child stoppables and marks the status of
 // the Multi Stoppable as stopping. Returns an error if one or more child
-// stoppables failed to close but it does not return their specific errors and
+// stoppables failed to close, but it does not return their specific errors and
 // assumes they print them to the log.
 func (m *Multi) Close() error {
 	var numErrors uint32
diff --git a/xxdk/cmix.go b/xxdk/cmix.go
index 33658c752..b3f5e5bd4 100644
--- a/xxdk/cmix.go
+++ b/xxdk/cmix.go
@@ -397,6 +397,12 @@ func (c *Cmix) HasRunningProcessies() bool {
 	return !c.followerServices.stoppable.IsStopped()
 }
 
+// GetRunningProcesses returns the name of all running processes at the time
+// of this call.
+func (c *Cmix) GetRunningProcesses() []string {
+	return c.followerServices.stoppable.GetRunningProcesses()
+}
+
 // GetRoundEvents registers a callback for round events.
 func (c *Cmix) GetRoundEvents() interfaces.RoundEvents {
 	jww.INFO.Printf("GetRoundEvents()")
-- 
GitLab