Stats: Add field PendingReplies 99/233899/10
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Wed, 20 May 2020 07:32:23 +0000 (16:32 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Fri, 22 May 2020 06:15:07 +0000 (15:15 +0900)
Pending replies will increasing
1) if client sending lots of messages to destination at once
2) if server eats incoming messages.(no reply)

In case of 2) dbus-daemon still has pending information.
With default bus context option (reply_timeout=-1) it never freed.

Assuming 2) happended repeatedly, then it is hard to detect until it
exceeds maximum pending replies limit, because of dbus-daemon print warning messages
only if pending replies over bus limit(default 1024 for system bus).

Change-Id: Iee0515fac68af7586547cc5ef5e6fa73d388a312
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
bus/connection.c
bus/connection.h
bus/stats.c

index e1802e7..851fb1b 100644 (file)
@@ -118,6 +118,7 @@ typedef struct
 #ifdef DBUS_ENABLE_STATS
   int peak_match_rules;
   int peak_bus_names;
+  int peak_pending_replies;
 #endif
   int n_pending_unix_fds;
   DBusTimeout *pending_unix_fds_timeout;
@@ -2041,6 +2042,17 @@ bus_connections_expect_reply (BusConnections  *connections,
       return FALSE;
     }
 
+#ifdef DBUS_ENABLE_STATS
+  {
+    BusConnectionData *d;
+
+    d = BUS_CONNECTION_DATA (will_get_reply);
+    _dbus_assert (d != NULL);
+
+    update_peak(&d->peak_pending_replies, count);
+  }
+#endif
+
   pending = dbus_new0 (BusPendingReply, 1);
   if (pending == NULL)
     {
@@ -2965,6 +2977,40 @@ bus_connection_get_peak_bus_names (DBusConnection *connection)
 
   return d->peak_bus_names;
 }
+
+int bus_connection_get_n_pending_replies (DBusConnection *connection)
+{
+  BusConnectionData *d;
+  DBusList *link;
+  BusPendingReply *pending;
+  int count = 0;
+
+  d = BUS_CONNECTION_DATA (connection);
+  _dbus_assert(d != NULL);
+
+  link = bus_expire_list_get_first_link(d->connections->pending_replies);
+  while (link != NULL)
+    {
+      pending = link->data;
+      link = bus_expire_list_get_next_link(d->connections->pending_replies,
+        link);
+      if (pending->will_get_reply == connection)
+        ++count;
+    }
+
+  return count;
+}
+
+int
+bus_connection_get_peak_pending_replies (DBusConnection *connection)
+{
+  BusConnectionData *d;
+
+  d = BUS_CONNECTION_DATA (connection);
+  _dbus_assert (d != NULL);
+
+  return d->peak_pending_replies;
+}
 #endif /* DBUS_ENABLE_STATS */
 
 dbus_bool_t
index ba7ce2f..868508a 100644 (file)
@@ -194,4 +194,7 @@ int bus_connections_get_peak_bus_names_per_conn   (BusConnections *connections);
 int bus_connection_get_peak_match_rules           (DBusConnection *connection);
 int bus_connection_get_peak_bus_names             (DBusConnection *connection);
 
+int bus_connection_get_n_pending_replies          (DBusConnection *connection);
+int bus_connection_get_peak_pending_replies      (DBusConnection *connection);
+
 #endif /* BUS_CONNECTION_H */
index 2742235..367d9c1 100644 (file)
@@ -170,7 +170,11 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection,
       !_dbus_asv_add_uint32 (&arr_iter, "PeakBusNames",
         bus_connection_get_peak_bus_names (stats_connection)) ||
       !_dbus_asv_add_string (&arr_iter, "UniqueName",
-        bus_connection_get_name (stats_connection)))
+        bus_connection_get_name (stats_connection))  ||
+      !_dbus_asv_add_uint32 (&arr_iter, "PendingReplies",
+        bus_connection_get_n_pending_replies (stats_connection)) ||
+      !_dbus_asv_add_uint32 (&arr_iter, "PeakPendingReplies",
+        bus_connection_get_peak_pending_replies (stats_connection)))
     {
       _dbus_asv_abandon (&iter, &arr_iter);
       goto oom;