11 Star 4 Fork 16

src-openEuler/vmtop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vcpu_list-pre-malloc-vcpu-list-to-improve-performanc.patch 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
From 406dae88df5ce989f9166929522e7ec5c5899fce Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Fri, 12 Mar 2021 14:30:26 +0800
Subject: [PATCH] vcpu_list: pre malloc vcpu list to improve performance
It costs a lot of time to malloc and memset vcpu_list while getting a new vcpu.
And vcpu num is limited to MAX_VCPU_NUM = 1024, so pre malloc MAX_VCPU_NUM mem,
which will improve vmtop cpu usage a lot.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/vcpu_stat.c | 5 +++--
src/vmtop.c | 1 +
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/vcpu_stat.c b/src/vcpu_stat.c
index 222e4d2..1578ec4 100644
--- a/src/vcpu_stat.c
+++ b/src/vcpu_stat.c
@@ -97,7 +97,7 @@ int get_vcpu_list(struct domain_list *list)
if (!fp) {
return -1;
}
- clear_domains(list);
+ list->num = 0;
while (fgets(buf, BUF_SIZE - 1, fp)) {
char *p = NULL;
char *p_next = NULL;
@@ -107,7 +107,7 @@ int get_vcpu_list(struct domain_list *list)
if (list->num >= MAX_VCPU_NUM) {
break;
}
- struct domain *dom = add_domains(list);
+ struct domain *dom = &(list->domains[list->num]);
for (p = strtok_r(buf, " \t\r\n", &p_next); p && i < vcpu_stat_size;
p = strtok_r(NULL, " \t\r\n", &p_next)) {
if (vcpu_stat_stab[i].get_fun) {
@@ -116,6 +116,7 @@ int get_vcpu_list(struct domain_list *list)
}
i++;
}
+ list->num++;
}
fclose(fp);
return list->num;
diff --git a/src/vmtop.c b/src/vmtop.c
index f5fd4bd..9e273c6 100644
--- a/src/vmtop.c
+++ b/src/vmtop.c
@@ -55,6 +55,7 @@ static void init_parameter(void)
init_domains(&scr_cur);
init_domains(&scr_pre);
init_domains(&vcpu_list);
+ vcpu_list.domains = malloc(sizeof(struct domain) * MAX_VCPU_NUM);
begin_task = 1;
begin_field = 1;
thread_mode = 0; /* default not to show threads */
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/vmtop.git
git@gitee.com:src-openeuler/vmtop.git
src-openeuler
vmtop
vmtop
master

搜索帮助