diff --git a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs index ccc986eef..51b575596 100644 --- a/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs +++ b/src/client/spark/AW2/Bus/VolSurfaceBlackboardManager.cs @@ -142,6 +142,7 @@ namespace mbts.spark { var list_imm = new VolSurfaceUsageListImmutable(ulist); Log.Ui.info(list_imm.log_string()); _bb.post(SparkTags.VolSurfaceUsageTag, list_imm); + _spin_vss(list_imm); }); _disps.Add(list_sub); } @@ -150,6 +151,13 @@ namespace mbts.spark { return _bb; } + void _spin_vss(VolSurfaceUsageListImmutable ulist) { + foreach (var u in ulist.UsageList) { + var vs_id = u.VsId; + _bb.post(SparkTags.VolSurfaceActiveUITag(vs_id), true); + } + } + void _on_vs_usage_update(Update update) { // TODO return; diff --git a/src/client/spark/core/Bus/BusTagDiagnostics.cs b/src/client/spark/core/Bus/BusTagDiagnostics.cs new file mode 100644 index 000000000..1206778f8 --- /dev/null +++ b/src/client/spark/core/Bus/BusTagDiagnostics.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; + + +public class BusTagDiagnostics { + + private class TagInfo { + public uint n_subs = 0; + public uint n_udpates = 0; + public DateTime last_sub_time = DateTime.MinValue; + public DateTime last_pub_time = DateTime.MinValue; + public bool published() { + return last_pub_time != DateTime.MinValue; + } + public bool subscribed() { + return last_sub_time != DateTime.MinValue; + } + public bool sub_without_pub() { + return subscribed() && !published() && + (DateTime.Now - last_pub_time).Seconds >= 10; + } + } + private readonly TimeSpan _log_per = TimeSpan.FromSeconds(5); + private DateTime _last_log_time = DateTime.Now; + private System.Threading.Thread _logging_thread; + private Dictionary tag_map = new Dictionary(); + private TagInfo _get_or_add(object tag) { + TagInfo ti = null; + if (!tag_map.TryGetValue(tag, out ti)) { + ti = new TagInfo(); + tag_map.Add(tag, ti); + } + return ti; + } + + public BusTagDiagnostics() { + _logging_thread = new System.Threading.Thread(() => { + while (true) { + System.Threading.Thread.Sleep(5000); + log_missing(); + } + }); + _logging_thread.IsBackground = true; + _logging_thread.Start(); + } + + public void update_pub(object tag) { + lock (this) { + TagInfo ti = _get_or_add(tag); + ti.n_udpates++; + ti.last_pub_time = DateTime.Now; + } + } + + public void update_sub(object tag) { + lock (this) { + TagInfo ti = _get_or_add(tag); + ti.last_sub_time = DateTime.Now; + } + } + + public void log_missing() { + lock (this) { + if (DateTime.Now - _last_log_time >= _log_per) { + _last_log_time = DateTime.Now; + foreach (var kv in tag_map) { + var tag = kv.Key; + TagInfo ti = kv.Value; + if (ti.sub_without_pub()) { + bts.Log.Ui.warn($"BusTagDiagnostics missing pub, tag: {tag.ToString()} n_subs: {ti.n_subs}"); + } + } + } + } + } + +} \ No newline at end of file