api,bearer: add 'attempts' and 'failed-attempts' statistics

When we're reusing over and over the same bearer object, we can
provide statistical information about the number of connection
attempts that have been done and how many of them failed.
This commit is contained in:
Aleksander Morgado
2020-04-10 11:45:03 +00:00
parent b3ec30403f
commit f325ef5902
8 changed files with 168 additions and 33 deletions
+88 -5
View File
@@ -11,8 +11,7 @@
* GNU General Public License for more details:
*
* Copyright (C) 2015 Azimut Electronics
*
* Author: Aleksander Morgado <aleksander@aleksander.es>
* Copyright (C) 2015-2020 Aleksander Morgado <aleksander@aleksander.es>
*/
#include <string.h>
@@ -34,14 +33,18 @@
G_DEFINE_TYPE (MMBearerStats, mm_bearer_stats, G_TYPE_OBJECT)
#define PROPERTY_DURATION "duration"
#define PROPERTY_RX_BYTES "rx-bytes"
#define PROPERTY_TX_BYTES "tx-bytes"
#define PROPERTY_DURATION "duration"
#define PROPERTY_RX_BYTES "rx-bytes"
#define PROPERTY_TX_BYTES "tx-bytes"
#define PROPERTY_ATTEMPTS "attempts"
#define PROPERTY_FAILED_ATTEMPTS "failed-attempts"
struct _MMBearerStatsPrivate {
guint duration;
guint64 rx_bytes;
guint64 tx_bytes;
guint attempts;
guint failed_attempts;
};
/*****************************************************************************/
@@ -142,6 +145,70 @@ mm_bearer_stats_set_tx_bytes (MMBearerStats *self,
/*****************************************************************************/
/**
* mm_bearer_stats_get_attempts:
* @self: a #MMBearerStats.
*
* Gets the number of connection attempts done with this bearer.
*
* Returns: a #guint.
*
* Since: 1.14
*/
guint
mm_bearer_stats_get_attempts (MMBearerStats *self)
{
g_return_val_if_fail (MM_IS_BEARER_STATS (self), 0);
return self->priv->attempts;
}
/**
* mm_bearer_stats_set_attempts: (skip)
*/
void
mm_bearer_stats_set_attempts (MMBearerStats *self,
guint attempts)
{
g_return_if_fail (MM_IS_BEARER_STATS (self));
self->priv->attempts = attempts;
}
/*****************************************************************************/
/**
* mm_bearer_stats_get_failed_attempts:
* @self: a #MMBearerStats.
*
* Gets the number of failed connection attempts done with this bearer.
*
* Returns: a #guint.
*
* Since: 1.14
*/
guint
mm_bearer_stats_get_failed_attempts (MMBearerStats *self)
{
g_return_val_if_fail (MM_IS_BEARER_STATS (self), 0);
return self->priv->failed_attempts;
}
/**
* mm_bearer_stats_set_failed_attempts: (skip)
*/
void
mm_bearer_stats_set_failed_attempts (MMBearerStats *self,
guint failed_attempts)
{
g_return_if_fail (MM_IS_BEARER_STATS (self));
self->priv->failed_attempts = failed_attempts;
}
/*****************************************************************************/
/**
* mm_bearer_stats_get_dictionary: (skip)
*/
@@ -167,6 +234,14 @@ mm_bearer_stats_get_dictionary (MMBearerStats *self)
"{sv}",
PROPERTY_TX_BYTES,
g_variant_new_uint64 (self->priv->tx_bytes));
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_ATTEMPTS,
g_variant_new_uint32 (self->priv->attempts));
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_FAILED_ATTEMPTS,
g_variant_new_uint32 (self->priv->failed_attempts));
return g_variant_builder_end (&builder);
}
@@ -212,6 +287,14 @@ mm_bearer_stats_new_from_dictionary (GVariant *dictionary,
mm_bearer_stats_set_tx_bytes (
self,
g_variant_get_uint64 (value));
} else if (g_str_equal (key, PROPERTY_ATTEMPTS)) {
mm_bearer_stats_set_attempts (
self,
g_variant_get_uint32 (value));
} else if (g_str_equal (key, PROPERTY_FAILED_ATTEMPTS)) {
mm_bearer_stats_set_failed_attempts (
self,
g_variant_get_uint32 (value));
}
g_free (key);
g_variant_unref (value);
+10 -6
View File
@@ -58,9 +58,11 @@ struct _MMBearerStatsClass {
GType mm_bearer_stats_get_type (void);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MMBearerStats, g_object_unref)
guint mm_bearer_stats_get_duration (MMBearerStats *self);
guint64 mm_bearer_stats_get_rx_bytes (MMBearerStats *self);
guint64 mm_bearer_stats_get_tx_bytes (MMBearerStats *self);
guint mm_bearer_stats_get_duration (MMBearerStats *self);
guint64 mm_bearer_stats_get_rx_bytes (MMBearerStats *self);
guint64 mm_bearer_stats_get_tx_bytes (MMBearerStats *self);
guint mm_bearer_stats_get_attempts (MMBearerStats *self);
guint mm_bearer_stats_get_failed_attempts (MMBearerStats *self);
/*****************************************************************************/
/* ModemManager/libmm-glib/mmcli specific methods */
@@ -73,9 +75,11 @@ MMBearerStats *mm_bearer_stats_new (void);
MMBearerStats *mm_bearer_stats_new_from_dictionary (GVariant *dictionary,
GError **error);
void mm_bearer_stats_set_duration (MMBearerStats *self, guint duration);
void mm_bearer_stats_set_rx_bytes (MMBearerStats *self, guint64 rx_bytes);
void mm_bearer_stats_set_tx_bytes (MMBearerStats *self, guint64 tx_bytes);
void mm_bearer_stats_set_duration (MMBearerStats *self, guint duration);
void mm_bearer_stats_set_rx_bytes (MMBearerStats *self, guint64 rx_bytes);
void mm_bearer_stats_set_tx_bytes (MMBearerStats *self, guint64 tx_bytes);
void mm_bearer_stats_set_attempts (MMBearerStats *self, guint attempts);
void mm_bearer_stats_set_failed_attempts (MMBearerStats *self, guint failed_attempts);
GVariant *mm_bearer_stats_get_dictionary (MMBearerStats *self);