lib/discovery: Fix debug information about in-progress scans.
There can be multiple plugin.Scan calls active at the same time,
so each should use their own separate stat.
Change-Id: I1869b8c86fa3563467b490ca10d03ff0c9c7e602
diff --git a/lib/discovery/plugins/ble/ble.go b/lib/discovery/plugins/ble/ble.go
index edc24d6..e8a16c4 100644
--- a/lib/discovery/plugins/ble/ble.go
+++ b/lib/discovery/plugins/ble/ble.go
@@ -27,6 +27,7 @@
var (
statMu sync.Mutex
statIdx int
+ seenIdx int
)
type plugin struct {
@@ -64,12 +65,16 @@
// plugins should be made aware of the plugin that sent the event.
// In that case, perhaps these stats should also be exported there,
// rather than in each plugin implementation?
- stat := naming.Join(p.statPrefix, "seen")
+ statMu.Lock()
+ stat := naming.Join(p.statPrefix, "seen", fmt.Sprint(seenIdx))
+ seenIdx++
+ statMu.Unlock()
var seenMu sync.Mutex // Safety between this goroutine and stats
stats.NewStringFunc(stat, func() string {
seenMu.Lock()
defer seenMu.Unlock()
buf := new(bytes.Buffer)
+ fmt.Fprintf(buf, "InterfaceName: %q\n", interfaceName)
for k, v := range seen {
fmt.Fprintf(buf, "%s: %v\n\n", k, *v)
}