Skip to content

Commit

Permalink
fixup and testing
Browse files Browse the repository at this point in the history
  • Loading branch information
kgiusti committed Oct 13, 2023
1 parent e8adc5f commit 83d961e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/alloc_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,14 @@ static void on_monitor_timer(void *context)
const qd_alloc_type_desc_t *desc = DEQ_HEAD(desc_list);
while (desc) {
qd_alloc_stats_t stats = qd_alloc_desc_stats(desc);

#ifdef NDEBUG
// For debug builds report all for verification purposes (and test the log buffer overflow path!)
if (stats.total_alloc_from_heap == 0) { // ignore unused items
desc = DEQ_NEXT(desc);
continue;
}
#endif
// log format: series of space separated item entries. Each entry has the format:
// "<type-name>:<# in use by threads>:<# in global freepool>"
uint64_t total = stats.total_alloc_from_heap - stats.total_free_to_heap;
Expand Down
38 changes: 38 additions & 0 deletions tests/system_tests_tcp_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io
import json
import os
import re
import socket
import subprocess
import time
Expand Down Expand Up @@ -1441,6 +1442,43 @@ def test_90_stats(self):
assert output["bytesIn"] == output["bytesOut"]
self.logger.log(tname + " SUCCESS")

@unittest.skipIf(DISABLE_SELECTOR_TESTS, DISABLE_SELECTOR_REASON)
def test_100_memory_metrics(self):
"""
Take advantage of the long running TCP test to verify that alloc_pool
metrics have been correctly written to the logs
"""
mem_re = re.compile(r' ram:[0-9]+\.[0-9]+[BKMGTi]+ vm:[0-9]+\.[0-9]+[BKMGTi]+ rss:[0-9]+\.[0-9]+[BKMGTi]+ pool:[0-9]+\.[0-9]+[BKMGTi]+')
action_re = re.compile(r' qdr_action_t:[0-9]+:[0-9]+')
for router in self.routers:
last_mem_match = None # match the start of the alloc log line
last_action_match = None # match the qdr_action_t entry in the log line
with open(router.logfile_path, 'rt') as log_file:
for line in log_file:
m = mem_re.search(line)
if m:
last_mem_match = m
m = action_re.search(line)
if m:
last_action_match = m
self.assertIsNotNone(last_mem_match, "failed to find alloc_pool output!")
self.assertIsNotNone(last_action_match, "failed to find qdr_action_t entry!")

# Sanity check that metrics are present:

# match = 'ram:62.49GiB vm:20.00TiB rss:58.88MiB pool:3.70KiB'
mems = last_mem_match.group().strip().split()
for mem in mems:
name, value = mem.split(':')
self.assertIn(name, ["ram", "vm", "rss", "pool"])
self.assertTrue(int(value.split('.')[0]) > 0,
f"Expected nonzero {name} counter!")
# match = ' qdr_action_t:192:0'
name, in_use, in_free = last_action_match.group().strip().split(':')
self.assertEqual(name, "qdr_action_t", f"Name mismatch {name}")
self.assertTrue(int(in_use) + int(in_free) > 0,
f"zero alloced? {in_use} {in_free}")


class TcpAdaptor(TcpAdaptorBase, CommonTcpTests):
@classmethod
Expand Down

0 comments on commit 83d961e

Please sign in to comment.