From ff812d0b1c2f87b873652c2b366ea4025ee2d15f Mon Sep 17 00:00:00 2001 From: zhongtao Date: Wed, 29 Nov 2023 09:33:32 +0000 Subject: [PATCH 165/181] =?UTF-8?q?!2286=20bugfix=20for=20the=20bliko=20ze?= =?UTF-8?q?ro=20value=20exception=20when=20executing=20the=20stats=20comma?= =?UTF-8?q?nd=20on=20the=20oci=20container=20*=20bugfix=20for=20the=20blik?= =?UTF-8?q?o=20zero=20value=20exception=20when=20executing=20the=20stats?= =?UTF-8?q?=20com=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/runtime/isula/isula_rt_ops.c | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c index c9e590b9..753816f5 100644 --- a/src/daemon/modules/runtime/isula/isula_rt_ops.c +++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c @@ -562,6 +562,40 @@ out: return ret; } +static void transform_stats_info_from_runtime(shim_client_runtime_stats *stats, struct runtime_container_resources_stats_info *info) +{ + if (stats == NULL || stats->data == NULL) { + return; + } + if (stats->data->pids != NULL) { + info->pids_current = stats->data->pids->current; + } + if (stats->data->cpu != NULL && stats->data->cpu->usage != NULL) { + info->cpu_use_nanos = stats->data->cpu->usage->total; + info->cpu_system_use = stats->data->cpu->usage->kernel; + } + shim_client_runtime_stats_data_memory *memory = stats->data->memory; + if (memory != NULL && memory->usage != NULL) { + info->mem_used = memory->usage->usage; + info->mem_limit = memory->usage->limit; + } + if (memory != NULL && memory->raw != NULL) { + info->inactive_file_total = memory->raw->total_inactive_file; + } + shim_client_runtime_stats_data_blkio *blkio = stats->data->blkio; + if (blkio == NULL) { + return; + } + for (size_t i = 0; i < blkio->io_service_bytes_recursive_len; i++) { + if (strcasecmp(blkio->io_service_bytes_recursive[i]->op, "read") == 0) { + info->blkio_read += blkio->io_service_bytes_recursive[i]->value; + } + if (strcasecmp(blkio->io_service_bytes_recursive[i]->op, "write") == 0) { + info->blkio_write += blkio->io_service_bytes_recursive[i]->value; + } + } +} + static int runtime_call_stats(const char *workdir, const char *runtime, const char *id, struct runtime_container_resources_stats_info *info) { @@ -601,20 +635,7 @@ static int runtime_call_stats(const char *workdir, const char *runtime, const ch goto out; } - if (stats != NULL && stats->data != NULL && stats->data->pids != NULL) { - info->pids_current = stats->data->pids->current; - } - if (stats != NULL && stats->data != NULL && stats->data->cpu != NULL && stats->data->cpu->usage) { - info->cpu_use_nanos = stats->data->cpu->usage->total; - info->cpu_system_use = stats->data->cpu->usage->kernel; - } - if (stats != NULL && stats->data != NULL && stats->data->memory != NULL && stats->data->memory->usage) { - info->mem_used = stats->data->memory->usage->usage; - info->mem_limit = stats->data->memory->usage->limit; - } - if (stats != NULL && stats->data != NULL && stats->data->memory != NULL && stats->data->memory->raw) { - info->inactive_file_total = stats->data->memory->raw->total_inactive_file; - } + transform_stats_info_from_runtime(stats, info); out: free_shim_client_runtime_stats(stats); -- 2.42.0