main/lxc: more fixes for lxc-top

- add kernel mem stat
- fix typo in IO error message
- fix -b to ignore TTY rows
This commit is contained in:
Natanael Copa 2024-07-25 13:58:04 +02:00
parent 6a3067bc1e
commit 22f419b54b
2 changed files with 78 additions and 12 deletions

View File

@ -4,7 +4,7 @@
pkgname=lxc pkgname=lxc
pkgver=6.0.1 pkgver=6.0.1
_pkgver=${pkgver/_rc/.rc} _pkgver=${pkgver/_rc/.rc}
pkgrel=6 pkgrel=7
pkgdesc="Userspace interface for the Linux kernel containment features" pkgdesc="Userspace interface for the Linux kernel containment features"
url="https://linuxcontainers.org/lxc/" url="https://linuxcontainers.org/lxc/"
arch="all" arch="all"
@ -177,7 +177,7 @@ _user_nic() {
sha512sums=" sha512sums="
7e8b9740178ae46a2ad3ba3f1e509f69f978d0a2a1f7e1938213ae9cb9a80f496d01be64958cad4aa6f01a73f1d8c3759c3e9df9df4f67c77e603ea0809d79c2 lxc-6.0.1.tar.gz 7e8b9740178ae46a2ad3ba3f1e509f69f978d0a2a1f7e1938213ae9cb9a80f496d01be64958cad4aa6f01a73f1d8c3759c3e9df9df4f67c77e603ea0809d79c2 lxc-6.0.1.tar.gz
3619a16604683d5cfa4b9d997cb8435232c016b71d0d7be2a0553d8136fa1914f916ef89d7092d3f51ff2e56714c918fef4e4e42bab89054fc92aec617228bec lxc-top-cgroupv2.patch d24a1226f37f575de5d85a850d74fa5a59623e1ec9fc8be30bacf1c874426213be3b6c4aa70a35d7df93fb2a95a573290768b92d0256c09d91fc629c8dc930e8 lxc-top-cgroupv2.patch
43299891779b0c8737b811e16d356e211d797d003af85d97ab969b3d47212e6c33ff5fbd36579534be9e84a2caa3cca8fd39f11a37cc54ec3e2344423e348499 lxc-info-cgroups-v2.patch 43299891779b0c8737b811e16d356e211d797d003af85d97ab969b3d47212e6c33ff5fbd36579534be9e84a2caa3cca8fd39f11a37cc54ec3e2344423e348499 lxc-info-cgroups-v2.patch
db71783366277a68a5c8116604cf845da4780fe4aebdb5820ae2c4fe028cfe52a9c94246db362476f2f195be6a9c2b835edbe521423f116fc66eb50023d6daab lxc.initd db71783366277a68a5c8116604cf845da4780fe4aebdb5820ae2c4fe028cfe52a9c94246db362476f2f195be6a9c2b835edbe521423f116fc66eb50023d6daab lxc.initd
91de43db5369a9e10102933514d674e9c875218a1ff2910dd882e5b9c308f9e430deacb13d1d7e0b2ed1ef682d0bb035aa6f8a6738f54fa2ca3a05acce04e467 lxc.confd 91de43db5369a9e10102933514d674e9c875218a1ff2910dd882e5b9c308f9e430deacb13d1d7e0b2ed1ef682d0bb035aa6f8a6738f54fa2ca3a05acce04e467 lxc.confd

View File

@ -1,7 +1,7 @@
From 40857b9de3714b3314f5c22e924d5993c458acbe Mon Sep 17 00:00:00 2001 From 40857b9de3714b3314f5c22e924d5993c458acbe Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org> From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 24 Jul 2024 15:23:11 +0200 Date: Wed, 24 Jul 2024 15:23:11 +0200
Subject: [PATCH 1/5] tools: lxc-top: refactor lxc-top stat structs Subject: [PATCH 1/7] tools: lxc-top: refactor lxc-top stat structs
Create separate structs for each controller class. This will make it Create separate structs for each controller class. This will make it
easier to add cgroupv2 support. easier to add cgroupv2 support.
@ -247,7 +247,7 @@ index aa6e7209e..bcc695b3e 100644
From ec11c2dad1ccf5fd6dd9a57e2812c4551f8a710f Mon Sep 17 00:00:00 2001 From ec11c2dad1ccf5fd6dd9a57e2812c4551f8a710f Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org> From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 24 Jul 2024 15:47:55 +0200 Date: Wed, 24 Jul 2024 15:47:55 +0200
Subject: [PATCH 2/5] tools: lxc-top: get memory stats from cgroups2 Subject: [PATCH 2/7] tools: lxc-top: get memory stats from cgroups2
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
--- ---
@ -316,7 +316,7 @@ index bcc695b3e..29d81563f 100644
From df219e84ca11294ba29ff9e85d09f4190942b30c Mon Sep 17 00:00:00 2001 From df219e84ca11294ba29ff9e85d09f4190942b30c Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org> From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 24 Jul 2024 16:32:30 +0200 Date: Wed, 24 Jul 2024 16:32:30 +0200
Subject: [PATCH 3/5] lxc-top: CPU stats for cgroups2 Subject: [PATCH 3/7] lxc-top: CPU stats for cgroups2
Recalculate the usec to nanoseconds and USER_HZ Recalculate the usec to nanoseconds and USER_HZ
@ -382,7 +382,7 @@ index 29d81563f..3a6c49e82 100644
From 094f05141db5968f8e3a855e4230579b12721a65 Mon Sep 17 00:00:00 2001 From 094f05141db5968f8e3a855e4230579b12721a65 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org> From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 24 Jul 2024 16:54:00 +0200 Date: Wed, 24 Jul 2024 16:54:00 +0200
Subject: [PATCH 4/5] tools: lxc-top: get the user HZ at runtime Subject: [PATCH 4/7] tools: lxc-top: get the user HZ at runtime
The USER_HZ depends on the kernel configuration. Get it run-time instead The USER_HZ depends on the kernel configuration. Get it run-time instead
of assume it is 100 HZ. of assume it is 100 HZ.
@ -450,10 +450,10 @@ index 3a6c49e82..deea1b41d 100644
2.45.2 2.45.2
From cf8f1e067f9be356f9879566ddfa31333929af22 Mon Sep 17 00:00:00 2001 From ebf0bbb3585330bf80bdd01aa7597672cca07aba Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org> From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 24 Jul 2024 17:29:10 +0200 Date: Wed, 24 Jul 2024 17:29:10 +0200
Subject: [PATCH 5/5] tools: lxc-top: add cgroups2 IO stats Subject: [PATCH 5/7] tools: lxc-top: add cgroups2 IO stats
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
--- ---
@ -461,7 +461,7 @@ Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
1 file changed, 53 insertions(+), 7 deletions(-) 1 file changed, 53 insertions(+), 7 deletions(-)
diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
index deea1b41d..6cc54988d 100644 index deea1b41d..15cf75a9a 100644
--- a/src/lxc/tools/lxc_top.c --- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c +++ b/src/lxc/tools/lxc_top.c
@@ -281,21 +281,21 @@ examples: @@ -281,21 +281,21 @@ examples:
@ -506,7 +506,7 @@ index deea1b41d..6cc54988d 100644
+ int i, j, len; + int i, j, len;
+ char **lines, **cols; + char **lines, **cols;
+ int ret = -1; + int ret = -1;
+
+ len = c->get_cgroup_item(c, item, buf, sizeof(buf)); + len = c->get_cgroup_item(c, item, buf, sizeof(buf));
+ if (len <= 0 || (size_t)len >= sizeof(buf)) { + if (len <= 0 || (size_t)len >= sizeof(buf)) {
+ return ret; + return ret;
@ -522,7 +522,7 @@ index deea1b41d..6cc54988d 100644
+ cols = lxc_string_split_and_trim(lines[i], ' '); + cols = lxc_string_split_and_trim(lines[i], ' ');
+ if (!cols) + if (!cols)
+ goto out; + goto out;
+
+ for (j = 0; cols[j]; j++) { + for (j = 0; cols[j]; j++) {
+ if (strncmp(cols[j], "rbytes=", 7) == 0) { + if (strncmp(cols[j], "rbytes=", 7) == 0) {
+ stats->read += strtoull(&cols[j][7], NULL, 0); + stats->read += strtoull(&cols[j][7], NULL, 0);
@ -550,7 +550,7 @@ index deea1b41d..6cc54988d 100644
- stat_get_blk_stats(c, "blkio.throttle.io_serviced", &ct->stats->io_serviced); - stat_get_blk_stats(c, "blkio.throttle.io_serviced", &ct->stats->io_serviced);
+ if (cg1_get_blk_stats(c, "blkio.throttle.io_service_bytes", &ct->stats->io_service_bytes) < 0) { + if (cg1_get_blk_stats(c, "blkio.throttle.io_service_bytes", &ct->stats->io_service_bytes) < 0) {
+ if (cg2_get_blk_stats(c, "io.stat", &ct->stats->io_service_bytes) < 0) { + if (cg2_get_blk_stats(c, "io.stat", &ct->stats->io_service_bytes) < 0) {
+ fprintf(stderr, "Unable to read CPU stats\n"); + fprintf(stderr, "Unable to read IO stats\n");
+ } + }
+ } else { + } else {
+ /* only with cgroups v1 */ + /* only with cgroups v1 */
@ -562,3 +562,69 @@ index deea1b41d..6cc54988d 100644
-- --
2.45.2 2.45.2
From 54e8ff395303f0d121cdb603a0ea5c01dd134dc3 Mon Sep 17 00:00:00 2001
From: Devon Schwartz <devon.s.schwartz@gmail.com>
Date: Wed, 24 Jul 2024 22:17:32 -0500
Subject: [PATCH 6/7] lxc-top: added kernel memory usage for cgroup2
---
src/lxc/tools/lxc_top.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
index 15cf75a9a..6cb38bb90 100644
--- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c
@@ -373,14 +373,13 @@ static int cg1_mem_stats(struct lxc_container *c, struct mem_stats *mem)
static int cg2_mem_stats(struct lxc_container *c, struct mem_stats *mem)
{
- mem->used = stat_get_int(c, "memory.current");
- mem->limit = stat_get_int(c, "memory.max");
- mem->swap_used = stat_get_int(c, "memory.swap.current");
- mem->swap_limit = stat_get_int(c, "memory.swap.max");
- /* TODO: find the kernel usage */
- mem->kmem_used = 0;
+ mem->used = stat_get_int(c, "memory.current");
+ mem->limit = stat_get_int(c, "memory.max");
+ mem->swap_used = stat_get_int(c, "memory.swap.current");
+ mem->swap_limit = stat_get_int(c, "memory.swap.max");
+ mem->kmem_used = stat_match_get_int(c, "memory.stat", "kernel", 1);
/* does not exist in cgroup v2 */
- mem->kmem_limit = 0;
+ // mem->kmem_limit = 0;
return mem->used > 0 ? 0 : -1;
}
--
2.45.2
From 9a7c15337202a00ae7d0a87906b3529f3ab9b84b Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Thu, 25 Jul 2024 13:52:27 +0200
Subject: [PATCH 7/7] tools: lxc-top: fix print in batch mode
We should not care about the number of rows when printing stats in batch
mode.
---
src/lxc/tools/lxc_top.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c
index 6cb38bb90..7498331ee 100644
--- a/src/lxc/tools/lxc_top.c
+++ b/src/lxc/tools/lxc_top.c
@@ -732,7 +732,7 @@ int lxc_top_main(int argc, char *argv[])
stats_print_header(&total);
}
- for (i = 0; i < active_cnt && i < ct_print_cnt; i++) {
+ for (i = 0; i < active_cnt && (i < ct_print_cnt || batch); i++) {
stats_print(container_stats[i].c->name, container_stats[i].stats, &total);
printf("\n");
}
--
2.45.2