Skip to content

Commit edb7a42

Browse files
committed
[iccom] per channel input statistics
* Added sysfs entry to check for the statistics of the incoming data per channel.
1 parent 049f7d0 commit edb7a42

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/iccom.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ struct iccom_packet {
753753
// transferred to the consumer;
754754
// false: then message data ownership remains in ICCom,
755755
// and is immediately discarded after callback invocation.
756+
//
757+
// @total_msgs_rcv indicates the total number of the messages received
758+
// on this channel.
759+
// @total_consumer_bytes_rcv indicates the total number of consumer
760+
// bytes received on this channel.
756761
struct iccom_message_storage_channel
757762
{
758763
struct list_head channel_anchor;
@@ -764,6 +769,9 @@ struct iccom_message_storage_channel
764769

765770
void *consumer_callback_data;
766771
iccom_msg_ready_callback_ptr_t message_ready_callback;
772+
773+
int64_t total_msgs_rcv;
774+
int64_t total_consumer_bytes_rcv;
767775
};
768776

769777
// Describes the messages storage. Intended to be used to
@@ -1895,6 +1903,9 @@ __iccom_msg_storage_add_channel(struct iccom_message_storage *storage
18951903
channel_rec->consumer_callback_data = NULL;
18961904
channel_rec->message_ready_callback = NULL;
18971905

1906+
channel_rec->total_msgs_rcv = 0;
1907+
channel_rec->total_consumer_bytes_rcv = 0;
1908+
18981909
return channel_rec;
18991910
}
19001911

@@ -2329,7 +2340,11 @@ static void __iccom_msg_storage_channel_commit(
23292340
if (msg->uncommitted_length == 0) {
23302341
continue;
23312342
}
2343+
channel_rec->total_consumer_bytes_rcv += msg->uncommitted_length;
23322344
msg->uncommitted_length = 0;
2345+
if (msg->finalized) {
2346+
channel_rec->total_msgs_rcv++;
2347+
}
23332348
}
23342349
}
23352350

@@ -5719,6 +5734,39 @@ static ssize_t statistics_show(
57195734
}
57205735
static DEVICE_ATTR_RO(statistics);
57215736

5737+
// Prints info about the current iccom channels.
5738+
static ssize_t channels_show(
5739+
struct device *dev, struct device_attribute *attr, char *buf)
5740+
{
5741+
ICCOM_CHECK_PTR(buf, return -EINVAL);
5742+
5743+
struct iccom_dev *iccom = (struct iccom_dev *)dev_get_drvdata(dev);
5744+
5745+
ICCOM_CHECK_DEVICE("no device provided", return -ENODEV);
5746+
ICCOM_CHECK_DEVICE_PRIVATE("broken device data", return -ENODEV);
5747+
5748+
size_t len = 0;
5749+
5750+
// need to lock storage to get the info
5751+
struct iccom_message_storage *storage = &iccom->p->rx_messages;
5752+
struct iccom_message_storage_channel *channel_rec = NULL;
5753+
mutex_lock(&storage->lock);
5754+
list_for_each_entry(channel_rec, &storage->channels_list
5755+
, channel_anchor) {
5756+
len += (size_t)scnprintf(buf + len, PAGE_SIZE - len,
5757+
"%d: I: %llu m %llu b\n"
5758+
, channel_rec->channel
5759+
, channel_rec->total_msgs_rcv
5760+
, channel_rec->total_consumer_bytes_rcv
5761+
);
5762+
}
5763+
atomic_set(&storage->uncommitted_finalized_count, 0);
5764+
mutex_unlock(&storage->lock);
5765+
5766+
return len;
5767+
}
5768+
static DEVICE_ATTR_RO(channels);
5769+
57225770
// The size of the data package currently used, in bytes
57235771
static ssize_t data_package_size_show(
57245772
struct device *dev, struct device_attribute *attr, char *buf)
@@ -5894,6 +5942,7 @@ static DEVICE_ATTR_WO(channels_ctl);
58945942
static struct attribute *iccom_dev_attrs[] = {
58955943
&dev_attr_transport.attr,
58965944
&dev_attr_statistics.attr,
5945+
&dev_attr_channels.attr,
58975946
&dev_attr_channels_ctl.attr,
58985947
&dev_attr_channels_RW.attr,
58995948
&dev_attr_data_package_size.attr,

test/iccom_testenv.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ def print_iccom_statistics(self):
192192
print("ICCom %s statistics:" % (fn,))
193193
with open(fn, "r") as statistics:
194194
for line in statistics.readlines():
195+
line = line.strip()
196+
print(" | " + line)
197+
198+
fn = "/sys/devices/platform/" + self.get_one_iccom_name() + "/channels"
199+
200+
print("ICCom %s channel statistics:" % (fn,))
201+
with open(fn, "r") as statistics:
202+
for line in statistics.readlines():
203+
line = line.strip()
195204
print(" | " + line)
196205

197206
def curr_dpkg_size(self, refresh=False):

0 commit comments

Comments
 (0)