Populate info in background thread
This change incorporates
https://gerrit.openbmc.org/c/openbmc/openbmc-tools/+/50784 and
https://gerrit.openbmc.org/c/openbmc/openbmc-tools/+/50088.
The function `ListAllSensors` populates a list of DBus sensor objects.
Currently it runs in the main thread before the UI gets created.
To enhance user experience, this routine is moved to a separate thread,
so the information is populated by that thread, so the main thread does
not get blocked while the list is being filled.
Originally, change 50784's ListAllSensors function includes the
following steps:
1) List DBus connections currently on the Bus
2) Get Creds for each of the DBus connections
3) Examine objects in ObjectMapper to ..
* See if they are Sensor objects
* If so mark a "Sensor" as "visible in ObjectMapper"
4) List all Associations recorded in the ObjectMapper
* So they can be shown in the sensor info panel
5) Find association definitions
6) Find association endpoints
7) Check all objects from HwMon daemons
* Objects from the DBus-Sensors daemon will be added later
8) Check `ipmitool sdr`
Step 8) is currently removed in this change since running `ipmitool sdr`
can potentially take a long time.
Change-Id: If6f27f130060b52e22c405942a861ba40e45ced2
Signed-off-by: Sui Chen <suichen6@gmail.com>
diff --git a/dbus_capture.cpp b/dbus_capture.cpp
index 38acfc4..e464456 100644
--- a/dbus_capture.cpp
+++ b/dbus_capture.cpp
@@ -28,6 +28,11 @@
extern DBusConnectionSnapshot* g_connection_snapshot;
static std::unordered_map<uint64_t, uint64_t> in_flight_methodcalls;
+extern bool g_sensor_update_thread_active;
+extern std::string g_snapshot_update_bus_cxn;
+extern int g_snapshot_update_bus_cxn_id;
+extern int GetConnectionNumericID(const std::string& unique_name);
+
namespace dbus_top_analyzer
{
extern DBusTopStatistics g_dbus_statistics;
@@ -170,25 +175,56 @@
const char* destination = sd_bus_message_get_destination(m);
const char* interface = sd_bus_message_get_interface(m);
const char* member = sd_bus_message_get_member(m);
- // TODO: This is for the bottom-left window
- TrackMessage(m);
- // Look up the unique connection name for sender and destination
+ // For looking up the unique connection name for sender and
+ // destination
std::string sender_uniq, dest_uniq;
- if (sender != nullptr)
+ bool should_ignore = false;
+
+ if (g_sensor_update_thread_active &&
+ g_snapshot_update_bus_cxn != "")
{
- sender_uniq =
- g_connection_snapshot->GetUniqueNameIfExists(sender);
+ int cxn_id = -999;
+ if (sender != nullptr)
+ {
+ cxn_id = GetConnectionNumericID(std::string(sender));
+ }
+ if (destination != nullptr)
+ {
+ cxn_id = GetConnectionNumericID(std::string(destination));
+ }
+
+ // Reason for this: The connection may be the connection from
+ // the update thread plus 1, example: :1.10000 vs :1.10001 Not
+ // sure where the new connection comes from. FIXME
+ if (cxn_id <= 4 + g_snapshot_update_bus_cxn_id &&
+ cxn_id >= g_snapshot_update_bus_cxn_id)
+ {
+ should_ignore = true;
+ }
}
- if (destination != nullptr)
+
+ if (!should_ignore)
{
- dest_uniq =
- g_connection_snapshot->GetUniqueNameIfExists(destination);
+ // TODO: This is for the bottom-left window
+ TrackMessage(m);
+
+ if (sender != nullptr)
+ {
+ sender_uniq =
+ g_connection_snapshot->GetUniqueNameIfExists(sender);
+ }
+ if (destination != nullptr)
+ {
+ dest_uniq = g_connection_snapshot->GetUniqueNameIfExists(
+ destination);
+ }
+ // This is for the bottom-right window
+ dbus_top_analyzer::g_dbus_statistics.OnNewDBusMessage(
+ sender_uniq.c_str(), dest_uniq.c_str(), interface, path,
+ member, type, m);
}
- // This is for the bottom-right window
- dbus_top_analyzer::g_dbus_statistics.OnNewDBusMessage(
- sender_uniq.c_str(), dest_uniq.c_str(), interface, path, member,
- type, m);
+
sd_bus_message_unref(m);
}
r = sd_bus_wait(g_bus,