Compare commits

...

21 Commits

Author SHA1 Message Date
openeuler-ci-bot
ae43c83b8c
!58 [sync] PR-55: update vmtop download url
From: @openeuler-sync-bot 
Reviewed-by: @yezengruan 
Signed-off-by: @yezengruan
2022-11-24 06:06:48 +00:00
yezengruan
d25cab9dc5 update vmtop download url
The download url is dead and needs to be updated.

Signed-off-by: yezengruan <yezengruan@huawei.com>
(cherry picked from commit 3803cd48b8e5fe6d9142624b21d459b22d3d06ee)
2022-11-24 12:40:07 +08:00
openeuler-ci-bot
d9f0fb3264
!53 [sync] PR-52: 【轻量级 PR】:Unified license name specification
From: @openeuler-sync-bot 
Reviewed-by: @yezengruan 
Signed-off-by: @yezengruan
2022-10-09 03:16:31 +00:00
付善庆
72b130d277 Unified license name specification
Signed-off-by: 付善庆 <fushanqing@kylinos.cn>
(cherry picked from commit 84e98b2d278c96a085956199842c0f22d760fe31)
2022-10-09 11:04:57 +08:00
openeuler-ci-bot
ad30aaa030
!47 【轻量级PR】修正changelog中的错误日期
From: @konglidong 
Reviewed-by: @yezengruan 
Signed-off-by: @yezengruan
2022-06-15 09:26:04 +00:00
konglidong
36e9c6d659 modify bad date in changelog 2022-06-15 16:45:57 +08:00
openeuler-ci-bot
d4621c2e6a
!43 [sync] PR-41: add README.zh.md. update README.md
From: @openeuler-sync-bot 
Reviewed-by: @kevinzhu1 
Signed-off-by: @kevinzhu1
2022-05-05 09:42:42 +00:00
yezengruan
c977d9dfb1 add README.zh.md. update README.md
Signed-off-by: gomico <smiku294@live.cn>
Signed-off-by: yezengruan <yezengruan@huawei.com>
(cherry picked from commit 021210523a19bb156ec21b021e20605f967ea140)
2022-05-05 15:33:13 +08:00
yezengruan
b6865b2eef update spec changelog
Signed-off-by: yezengruan <yezengruan@huawei.com>
(cherry picked from commit ecaf920edf4c57a22e39e4387e658ac8009654b7)
2022-05-05 15:33:13 +08:00
openeuler-ci-bot
40defc9dd1 !36 Automatically generate code patches with openeuler !20 !24
From: @zhendongchen
Reviewed-by: @zhanghailiang_lucky,@zhanghailiang_lucky
Signed-off-by: @zhanghailiang_lucky,@zhanghailiang_lucky
2021-04-25 17:10:52 +08:00
Alex Chen
aaefe9eaa0 spec: Update release version with !20 !24
increase release verison by one

Signed-off-by: Alex Chen <alex.chen@huawei.com>
2021-04-22 16:57:15 +08:00
Alex Chen
34f499dde0 spec: Update patch and changelog with !24
vcpu_list: pre malloc vcpu list to improve performance
performance: del unnecessary memcpy and memset
keyboard: change wait time to 3s
performance: change memset location
proc: del unused items getting from proc stat refresh
proc: del loop sscanf for proc pid stat file
utils: del realpath from read_file

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
ec90fc1e17 utils: del realpath from read_file
Since the path in read_file is constructed by vmtop, there is no need
to use realpath to modify the path. So, del realpath to release cpu time.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
6c00a8de63 proc: del loop sscanf for proc pid stat file
Loop sscanf and strtok will take a long cpu time, since
get_proc_stat is called per thread. So, replace these with a single sscanf,
which will save much cpu time.
Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
13badcdda8 proc: del unused items getting from proc stat refresh
Currently, vmtop gets a lot of items from /proc/pid/stat, and there
are many unused data in these items, which will add a lot of cpu usage.
So, del these item's getting process.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
2306ad24de performance: change memset location
There is no need to clear all mem in add_domains, beacause memcpy will
write the front section. We only need to clear the mem in the end, which
will improve the performance.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
47557de587 keyboard: change wait time to 3s
Currently, key wait time is 1s, which is too short to display vm-exit status.
So, change it to 3s.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
fea85e8fb5 performance: del unnecessary memcpy and memset
There is no need to malloc a new mem to save old domain list data,
and now->domains and pre->domains are pointers.
So assign now->domains to pre->domains satisfies the requirement.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:11 +08:00
Huawei Technologies Co., Ltd
1f664abbd5 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>
2021-04-22 16:57:11 +08:00
Alex Chen
03b8e2075d spec: Update patch and changelog with !20
input: change wait mechanism for input

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:10 +08:00
Huawei Technologies Co., Ltd
0a9bc10b52 input: change wait mechanism for input
Currently, vmtop uses halfdelay to set waiting timeout of input.
But, halfdelay's timeout can only be between 1~255, which limits vmtop's
functioniing.

Signed-off-by: nocjj <1250062498@qq.com>
2021-04-22 16:57:10 +08:00
10 changed files with 794 additions and 12 deletions

View File

@ -0,0 +1,197 @@
From 43a69408e9d04e3df94d456c2e5921e6fae82169 Mon Sep 17 00:00:00 2001
From: gomico <smiku294@live.cn>
Date: Tue, 26 Apr 2022 14:56:45 +0800
Subject: [PATCH] add README.zh.md. update README.md.
---
README.md | 54 +++++++++++++++++++++++-------------
README.zh.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+), 19 deletions(-)
create mode 100644 README.zh.md
diff --git a/README.md b/README.md
index 8dcebb6..25f4c10 100644
--- a/README.md
+++ b/README.md
@@ -3,12 +3,15 @@
A tool for collecting and analyzing data of virtual machine.
### Description
-vmtop is a user-mode tool running on the host, which can dynamically view the resource usage of virtual machines in real time, include CPU usage, memory usage, vcpu kvm exits. It brings great convenience to virtualization problems and performance optimization, and is a pratical tool that intergrates multi-party info to monitor virtual machines.
+
+vmtop is a user-mode tool running on the host. You can use the tool to dynamically view the usage of virtual machine resources in real time, including CPU usage, memory usage, and vCPU KVM exits. vmtop brings great convenience to locating virtualization problems and performance optimization, and is a practical tool that integrates multi-party information for monitoring virtual machines.
### Building
-This project uses ncurses, ncurses-devel, autoconf, libvirt, libvirt-devel. Go to check them out if you do not have them locally installed.
+
+This project uses ncurses, ncurses-devel, autoconf, libvirt, libvirt-devel. Check them out if you do not have them locally installed.
The simple steps to make vmtop are:
+
```sh
1. aclocal
2. autoconf
@@ -17,45 +20,58 @@ The simple steps to make vmtop are:
5. ./configure
6. make
```
-And then you will find vmtop in the source code dictionary.
+
+Then you will find vmtop in the source code dictionary.
### Introductions
-#### usage
-Run directly from the commandline.
+
+#### Usage
+
+Run directly from the command line mode.
+
```sh
vmtop [-option]
```
-#### start option
-- d: Set delay time between two display
-- H: Show threads
-- n: Set display times, default no limit
-- b: Display in text mode to save result in file
-#### shortcut key
-- H: Open thread mode or close thread mode
-- q: Quit from vmtop
-- f: Show fields filter
+#### Start Options
+
+- -d: sets the refresh interval
+- -H: shows thread information
+- -n: sets the number of refresh times, which is not limited by default
+- -b: displays in text mode to save results to a file
+
+#### Shortcut Keys
+
+- H: displays or stops the thread information
+- q: quits vmtop
+- f: shows field filter
### Contribution
#### Git
+
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Style
-It is much better to be consistent with the exiting files. For new files:
-- C: use kernel code style
-- others: keep same with exiting files
+
+You are advised to keep new files consistent with the existing files. For new files:
+
+- in C: use kernel coding style
+- in other languages: keep them consistent with the existing files
#### Patches
-Use 'git format-patch' to format patched and use 'git send-email' to send mail to [@openeuler](virt@openeuler.org) mailing list. And if it is a patch set, it is much better to use '--cover-letter' option when you format patches, so that we can understand what the pacthset does.
+
+Use 'git format-patch' to format patches and use 'git send-email' to send mail to [@openeuler](virt@openeuler.org) mailing list. For patch sets, the '--cover-letter' option is recommended when you format the patches. This helps us understand the features of the patches.
### Maintainers
+
[@zhanghailiang](https://gitee.com/zhanghailiang_luckyh)
[@nocjj](https://gitee.com/nocjj)
### License
-[Mulan](License/LICENSE)
+
+[Mulan](License/LICENSE)
\ No newline at end of file
diff --git a/README.zh.md b/README.zh.md
new file mode 100644
index 0000000..f5a9193
--- /dev/null
+++ b/README.zh.md
@@ -0,0 +1,77 @@
+# vmtop
+
+用于收集和分析虚拟机数据的工具。
+
+### 介绍
+
+vmtop 是运行于主机端的用户模式工具,能够以动态方式实时查看虚拟机资源使用量,包括 CPU 和内存使用量,以及 vCPU KVM 退出事件。vmtop 为定位虚拟化问题和性能优化提供了极大的便利,是一种能集成多方信息以便监控虚拟机的实用工具。
+
+### 构建
+
+本项目使用 ncurses、ncurses-devel、autoconf、libvirt、libvirt-devel请提前在本地安装好这些软件库。
+
+构建 vmtop 的步骤非常简单:
+
+```sh
+1. aclocal
+2. autoconf
+3. autoheader
+4. automake --add-missing
+5. ./configure
+6. make
+```
+
+之后就可以在源代码字典中找到 vmtop。
+
+### 使用说明
+
+#### 使用方法
+
+直接以命令行模式运行。
+
+```sh
+vmtop [-option]
+```
+
+#### 启动选项
+
+- -d: 设置显示刷新间隔
+- -H: 显示线程信息
+- -n: 设置显示刷新次数,默认不限制次数
+- -b: 以文字模式显示,以便将结果保存到文件
+
+#### 快捷键
+
+- H: 开启或关闭线程信息显示
+- q: 退出 vmtop
+- f: 显示字段过滤
+
+
+### 参与贡献
+
+#### Git
+
+1. Fork 本仓库
+2. 新建 Feat_xxx 分支
+3. 提交代码
+4. 新建 Pull Request
+
+#### 代码风格
+
+新增文件的风格建议与已有文件保持一致。对于新增文件:
+
+- C 语言:使用内核编码风格
+- 其他语言:与已有文件保持一致
+
+#### 补丁
+
+使用 'git format-patch' 来格式化补丁,使用 'git send-email' 来向 [@openeuler](virt@openeuler.org) 邮件列表发送邮件。对于补丁集,建议在格式化补丁时添加 '--cover-letter' 选项,以便我们更好地了解补丁的功能特性。
+
+### 维护人员
+
+[@zhanghailiang](https://gitee.com/zhanghailiang_luckyh)
+[@nocjj](https://gitee.com/nocjj)
+
+### 授权
+
+[Mulan](License/LICENSE)
\ No newline at end of file
--
2.27.0

View File

@ -0,0 +1,43 @@
From 49201ec920c30ca1096fcf258696cef33a11b056 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Sat, 27 Feb 2021 11:23:29 +0800
Subject: [PATCH] input: change wait mechanism for input
Currently, vmtop uses halfdelay to set waiting timeout of input.
But, halfdelay's timeout can only be between 1~255, which limits vmtop's
functioniing.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/vmtop.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/vmtop.c b/src/vmtop.c
index f5fd4bd..cc2c141 100644
--- a/src/vmtop.c
+++ b/src/vmtop.c
@@ -489,6 +489,8 @@ int main(int argc, char *argv[])
if (scr_mode == TERM_MODE) {
print_scr = printw;
init_screen();
+ /* set getch wait for delay time */
+ wtimeout(stdscr, delay_time * 1000);
} else {
print_scr = printf;
}
@@ -507,11 +509,7 @@ int main(int argc, char *argv[])
show_domains(&scr_cur);
if (scr_mode == TERM_MODE) {
- /*
- * set getch wait for delay time
- * if timeout return ERR and continue
- */
- halfdelay(delay_time * 10);
+ /* if timeout return ERR and continue */
key = getch();
if (key != ERR) {
parse_keys(key);
--
2.27.0

View File

@ -0,0 +1,33 @@
From 3e87175d5a82ddefe353327310c253627add6c60 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Mon, 15 Mar 2021 14:04:06 +0800
Subject: [PATCH] keyboard: change wait time to 3s
Currently, key wait time is 1s, which is too short to display vm-exit status.
So, change it to 3s.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/vmtop.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/vmtop.c b/src/vmtop.c
index 9e273c6..071ac9a 100644
--- a/src/vmtop.c
+++ b/src/vmtop.c
@@ -60,11 +60,10 @@ static void init_parameter(void)
begin_field = 1;
thread_mode = 0; /* default not to show threads */
quit_flag = 0;
- delay_time = 1; /* default delay 1s between display */
display_loop = -1;
scr_mode = TERM_MODE;
quit_flag = 0;
- delay_time = 1; /* default delay 1s between display */
+ delay_time = 3; /* default delay 1s between display */
scr_row_size = 2048; /* defualt size row */
scr_col_size = 1024; /* default size col */
monitor_id = -1; /* default monitor all domains */
--
2.27.0

View File

@ -0,0 +1,35 @@
From 23915d6eff1ba63c5a9967a519879225312ead01 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Mon, 15 Mar 2021 20:03:18 +0800
Subject: [PATCH] performance: change memset location
There is no need to clear all mem in add_domains, beacause memcpy will
write the front section. We only need to clear the mem in the end, which
will improve the performance.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/domain.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/domain.c b/src/domain.c
index b8c527a..977cabe 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -55,11 +55,12 @@ struct domain *add_domains(struct domain_list *list)
if (new_list == NULL) {
return NULL;
}
- memset(new_list, 0, sizeof(struct domain) * (list->num + 1));
memcpy(new_list, list->domains, sizeof(struct domain) * list->num);
free(list->domains);
list->domains = new_list;
list->num++;
+ memset(&(list->domains[list->num - 1]), 0, sizeof(struct domain));
+
return &(list->domains[list->num - 1]);
}
--
2.27.0

View File

@ -0,0 +1,70 @@
From cee7a38c7bbbb199f5f1a2e290e4a1b425026d35 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Fri, 12 Mar 2021 15:25:30 +0800
Subject: [PATCH] performance: del unnecessary memcpy and memset
There is no need to malloc a new mem to save old domain list data,
and now->domains and pre->domains are pointers.
So assign now->domains to pre->domains satisfies the requirement.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/domain.c | 35 ++++++-----------------------------
1 file changed, 6 insertions(+), 29 deletions(-)
diff --git a/src/domain.c b/src/domain.c
index f8dea48..b8c527a 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -63,33 +63,6 @@ struct domain *add_domains(struct domain_list *list)
return &(list->domains[list->num - 1]);
}
-static void copy_domains(struct domain_list *now, struct domain_list *pre)
-{
- clear_domains(pre);
- pre->num = now->num;
- if (pre->num <= 0) {
- return;
- }
- pre->domains = malloc(sizeof(struct domain) * pre->num);
- if (pre->domains == NULL) {
- pre->num = 0;
- return;
- }
- memcpy(pre->domains, now->domains, sizeof(struct domain) * pre->num);
- for (int i = 0; i < pre->num; i++) {
- if (pre->domains[i].nlwp <= 0) {
- continue;
- }
- pre->domains[i].threads = malloc(sizeof(struct domain) *
- pre->domains[i].nlwp);
- if (pre->domains[i].threads == NULL) {
- continue;
- }
- memcpy(pre->domains[i].threads, now->domains[i].threads,
- sizeof(struct domain) * pre->domains[i].nlwp);
- }
-}
-
static void pop_domains(struct domain_list *list)
{
list->num--;
@@ -308,8 +281,12 @@ int refresh_domains(struct domain_list *now, struct domain_list *pre)
{
int num;
- copy_domains(now, pre); /* save last data int pre */
- clear_domains(now);
+ /* save data in pre domain_list */
+ clear_domains(pre);
+ pre->num = now->num;
+ pre->domains = now->domains;
+ init_domains(now);
+
if (get_vcpu_list(&vcpu_list) < 0) {
return -1;
}
--
2.27.0

View File

@ -0,0 +1,129 @@
From 3afac4c6992006c31fa33fe351bf27eedc34be1c Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Tue, 16 Mar 2021 16:23:23 +0800
Subject: [PATCH] proc: del loop sscanf for proc pid stat file
Loop sscanf and strtok will take a long cpu time, since
get_proc_stat is called per thread. So, replace these with a single sscanf,
which will save much cpu time.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/proc.c | 73 +++++++++++++++++-------------------------------------
src/type.h | 2 +-
2 files changed, 24 insertions(+), 51 deletions(-)
diff --git a/src/proc.c b/src/proc.c
index d33ede3..a722a92 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -19,46 +19,9 @@
#define STAT_PATH_SIZE 40
struct file_item proc_stab[] = {
-#define GDF(f) (void *)GET_NAME(f), (void *)DELTA_NAME(f), NULL
-#define GF(f) (void *)GET_NAME(f), NULL, NULL
- {"%c", GF(state)},
- {"%d", GF(ppid)},
- {"%d", GF(pgrd)},
- {"%*d", NULL, NULL, NULL},
- {"%*d", NULL, NULL, NULL},
- {"%*d", NULL, NULL, NULL},
- {"%lu", GF(flags)},
- {"%lu", GF(min_flt)},
- {"%lu", GF(cmin_flt)},
- {"%lu", GF(maj_flt)},
- {"%lu", GF(cmaj_flt)},
+#define GDF(f) NULL, (void *)DELTA_NAME(f), NULL
{"%llu", GDF(utime)},
- {"%llu", GDF(stime)},
- {"%llu", GF(cutime)},
- {"%llu", GF(cstime)},
- {"%*ld", NULL, NULL, NULL},
- {"%*ld", NULL, NULL, NULL},
- {"%d", GF(nlwp)},
- {"%ld", GF(alarm)},
- {"%llu", GF(start_time)},
- {"%lu", GF(vsize)},
- {"%ld", GF(rss)},
- {"%lu", GF(rss_rlim)},
- {"%*lu", NULL, NULL, NULL},
- {"%*lu", NULL, NULL, NULL},
- {"%*lu", NULL, NULL, NULL},
- {"%*lu", NULL, NULL, NULL},
- {"%*lu", NULL, NULL, NULL},
- {"%*s", NULL, NULL, NULL}, /* discard signal */
- {"%*s", NULL, NULL, NULL}, /* discard blocked */
- {"%*s", NULL, NULL, NULL}, /* discard sigignore */
- {"%*s", NULL, NULL, NULL}, /* discard sigcatch */
- {"%*lu", NULL, NULL, NULL},
- {"%*u", NULL, NULL, NULL}, /* dsicard nswap */
- {"%*u", NULL, NULL, NULL}, /* discard cnswap */
- {"%*d", NULL, NULL, NULL},
- {"%d", GF(processor)}
-#undef GF
+ {"%llu", GDF(stime)}
#undef GDF
};
@@ -70,9 +33,6 @@ int get_proc_stat(struct domain *dom)
char path[STAT_PATH_SIZE];
char *tmp1 = NULL;
char *tmp2 = NULL;
- char *p = NULL;
- char *p_next = NULL;
- int i = 0;
int len;
if (dom->type == ISDOMAIN) {
@@ -100,14 +60,27 @@ int get_proc_stat(struct domain *dom)
dom->vmname[len] = '\0';
/* read start from process state */
- tmp2 = tmp2 + 2;
- for (p = strtok_r(tmp2, " \t\r\n", &p_next); p && i < stat_size;
- p = strtok_r(NULL, " \t\r\n", &p_next)) {
- if (proc_stab[i].get_fun != NULL) {
- sscanf(p, proc_stab[i].format, (*proc_stab[i].get_fun)(dom));
- }
- ++i;
- }
+ sscanf(tmp2 + 2,
+ "%c "
+ "%d %d %*d %*d %*d "
+ "%lu "
+ "%lu %lu %lu %lu "
+ "%llu %llu %llu %llu "
+ "%*d %*d "
+ "%d %ld "
+ "%llu %lu %ld %lu "
+ "%*u %*u %*u %*u %*u "
+ "%*s %*s %*s %*s "
+ "%*u %*u %*u %*d "
+ "%d",
+ &(dom->state),
+ &(dom->ppid), &(dom->pgrd),
+ &(dom->flags),
+ &(dom->min_flt), &(dom->cmin_flt), &(dom->maj_flt), &(dom->cmaj_flt),
+ &(dom->utime), &(dom->stime), &(dom->cutime), &(dom->cstime),
+ &(dom->nlwp), &(dom->alarm),
+ &(dom->start_time), &(dom->vsize), &(dom->rss), &(dom->rss_rlim),
+ &(dom->processor));
return 1;
}
diff --git a/src/type.h b/src/type.h
index f5d148c..77dd696 100644
--- a/src/type.h
+++ b/src/type.h
@@ -86,7 +86,7 @@ struct domain {
long int
alarm,
rss;
- unsigned int
+ unsigned long
flags,
min_flt,
cmin_flt,
--
2.27.0

View File

@ -0,0 +1,153 @@
From da33b45b1945c2eae9cadb04b021179e2640670a Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Tue, 16 Mar 2021 13:55:36 +0800
Subject: [PATCH] proc: del unused items getting from proc stat refresh
Currently, vmtop gets a lot of items from /proc/pid/stat, and there
are many unused data in these items, which will add a lot of cpu usage.
So, del these item's getting process.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/proc.c | 28 +++++++++++++---------------
src/proc.h | 14 --------------
src/type.h | 16 +---------------
3 files changed, 14 insertions(+), 44 deletions(-)
diff --git a/src/proc.c b/src/proc.c
index 0263c67..d33ede3 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -24,9 +24,9 @@ struct file_item proc_stab[] = {
{"%c", GF(state)},
{"%d", GF(ppid)},
{"%d", GF(pgrd)},
- {"%d", GF(session)},
- {"%d", GF(tty)},
- {"%d", GF(tpgid)},
+ {"%*d", NULL, NULL, NULL},
+ {"%*d", NULL, NULL, NULL},
+ {"%*d", NULL, NULL, NULL},
{"%lu", GF(flags)},
{"%lu", GF(min_flt)},
{"%lu", GF(cmin_flt)},
@@ -36,30 +36,28 @@ struct file_item proc_stab[] = {
{"%llu", GDF(stime)},
{"%llu", GF(cutime)},
{"%llu", GF(cstime)},
- {"%ld", GF(priority)},
- {"%ld", GF(nice)},
+ {"%*ld", NULL, NULL, NULL},
+ {"%*ld", NULL, NULL, NULL},
{"%d", GF(nlwp)},
{"%ld", GF(alarm)},
{"%llu", GF(start_time)},
{"%lu", GF(vsize)},
{"%ld", GF(rss)},
{"%lu", GF(rss_rlim)},
- {"%lu", GF(start_code)},
- {"%lu", GF(end_code)},
- {"%lu", GF(start_stack)},
- {"%lu", GF(kstk_esp)},
- {"%lu", GF(kstk_eip)},
+ {"%*lu", NULL, NULL, NULL},
+ {"%*lu", NULL, NULL, NULL},
+ {"%*lu", NULL, NULL, NULL},
+ {"%*lu", NULL, NULL, NULL},
+ {"%*lu", NULL, NULL, NULL},
{"%*s", NULL, NULL, NULL}, /* discard signal */
{"%*s", NULL, NULL, NULL}, /* discard blocked */
{"%*s", NULL, NULL, NULL}, /* discard sigignore */
{"%*s", NULL, NULL, NULL}, /* discard sigcatch */
- {"%lu", GF(wchan)},
+ {"%*lu", NULL, NULL, NULL},
{"%*u", NULL, NULL, NULL}, /* dsicard nswap */
{"%*u", NULL, NULL, NULL}, /* discard cnswap */
- {"%d", GF(exit_signal)},
- {"%d", GF(processor)},
- {"%lu", GF(rtprio)},
- {"%lu", GF(sched)}
+ {"%*d", NULL, NULL, NULL},
+ {"%d", GF(processor)}
#undef GF
#undef GDF
};
diff --git a/src/proc.h b/src/proc.h
index a7fd443..0061ab1 100644
--- a/src/proc.h
+++ b/src/proc.h
@@ -16,9 +16,6 @@
GET_VALUE(state)
GET_VALUE(ppid)
GET_VALUE(pgrd)
-GET_VALUE(session)
-GET_VALUE(tty)
-GET_VALUE(tpgid)
GET_VALUE(flags)
GET_VALUE(min_flt)
GET_VALUE(cmin_flt)
@@ -28,24 +25,13 @@ GET_DELTA_FUN(utime)
GET_DELTA_FUN(stime)
GET_VALUE(cutime)
GET_VALUE(cstime)
-GET_VALUE(priority)
-GET_VALUE(nice)
GET_VALUE(nlwp)
GET_VALUE(alarm)
GET_VALUE(start_time)
GET_VALUE(vsize)
GET_VALUE(rss)
GET_VALUE(rss_rlim)
-GET_VALUE(start_code)
-GET_VALUE(end_code)
-GET_VALUE(start_stack)
-GET_VALUE(kstk_esp)
-GET_VALUE(kstk_eip)
-GET_VALUE(wchan)
-GET_VALUE(exit_signal)
GET_VALUE(processor)
-GET_VALUE(rtprio)
-GET_VALUE(sched)
int get_proc_stat(struct domain *dom);
void refresh_delta_stat(struct domain *new, struct domain *old);
diff --git a/src/type.h b/src/type.h
index 3c08387..f5d148c 100644
--- a/src/type.h
+++ b/src/type.h
@@ -81,15 +81,9 @@ struct domain {
int
ppid,
pgrd,
- session,
- tty,
- tpgid,
nlwp,
- exit_signal,
processor;
long int
- priority,
- nice,
alarm,
rss;
unsigned int
@@ -99,15 +93,7 @@ struct domain {
maj_flt,
cmaj_flt,
vsize,
- rss_rlim,
- start_code,
- end_code,
- start_stack,
- kstk_esp,
- kstk_eip,
- rtprio,
- sched,
- wchan;
+ rss_rlim;
u64
DFX_VALUE(utime),
DFX_VALUE(stime),
--
2.27.0

View File

@ -0,0 +1,35 @@
From 6f48c7f25e6db54941c110517ff25648d6287ec8 Mon Sep 17 00:00:00 2001
From: nocjj <1250062498@qq.com>
Date: Tue, 16 Mar 2021 20:04:32 +0800
Subject: [PATCH] utils: del realpath from read_file
Since the path in read_file is constructed by vmtop, there is no need
to use realpath to modify the path. So, del realpath to release cpu time.
Signed-off-by: nocjj <1250062498@qq.com>
---
src/utils.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/utils.c b/src/utils.c
index 3cb1146..29de9c9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -24,12 +24,11 @@ int read_file(char *buf, int bufsize, const char *path)
{
int fd;
int len;
- char mpath[PATH_MAX];
- if (strlen(path) > PATH_MAX - 1 || realpath(path, mpath) == NULL) {
+ if (strlen(path) > PATH_MAX - 1) {
return -1;
}
- fd = open(mpath, O_RDONLY, 0);
+ fd = open(path, O_RDONLY, 0);
if (fd == -1) {
return -1;
}
--
2.27.0

View File

@ -0,0 +1,60 @@
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

View File

@ -1,12 +1,12 @@
Name: vmtop
Version: 1.1
Release: 4
Release: 7
Summary: A tool for collecting and analyzing data of virtual machine
License: Mulan PSL V2
License: MulanPSL-2.0
Group: Application/System
URL: https://gitee.com/openeuler/vmtop
Source:https://gitee.com/openeuler/vmtop/repository/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source: https://gitee.com/openeuler/vmtop/releases/download/v%{version}/%{name}-%{version}.tar.gz
Patch0001: bugfix-fix-ST-GUE-HYP-formula.patch
Patch0002: display-expand-row-size-in-TEXT-mode.patch
@ -30,6 +30,15 @@ Patch0019: codestyle-del-unused-var.patch
Patch0020: bugfix-add-check-to-avoid-invalid-ptr-for-strcmp.patch
Patch0021: input-add-invalid-opt-check-in-input.patch
Patch0022: version-unified-with-release-version.patch
Patch0023: input-change-wait-mechanism-for-input.patch
Patch0024: vcpu_list-pre-malloc-vcpu-list-to-improve-performanc.patch
Patch0025: performance-del-unnecessary-memcpy-and-memset.patch
Patch0026: keyboard-change-wait-time-to-3s.patch
Patch0027: performance-change-memset-location.patch
Patch0028: proc-del-unused-items-getting-from-proc-stat-refresh.patch
Patch0029: proc-del-loop-sscanf-for-proc-pid-stat-file.patch
Patch0030: utils-del-realpath-from-read_file.patch
Patch0031: add-README.zh.md.-update-README.md.patch
Requires: libvirt, ncurses
@ -70,16 +79,34 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name}
%{_bindir}/vmtop
%changelog
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
* Sun Oct 09 2022 fushanqing <fushanqing@kylinos.cn> - 1.1-7
- Unified license name specification
* Wed Apr 27 2022 yezengruan <yezengruan@huawei.com> - 1.1-6
- add README.zh.md. update README.md
* Tue Mar 16 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-5
- vcpu_list: pre malloc vcpu list to improve performance
- performance: del unnecessary memcpy and memset
- keyboard: change wait time to 3s
- performance: change memset location
- proc: del unused items getting from proc stat refresh
- proc: del loop sscanf for proc pid stat file
- utils: del realpath from read_file
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-4
- input: change wait mechanism for input
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-4
- version: unified with release version
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-3
- input: add invalid opt check in input
* Thu Jan 21 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
* Thu Jan 21 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-3
- bugfix: add check to avoid invalid ptr for strcmp
* Thu 14 Jan 2021 Jiajun Chen <1250062498@qq.com> -1.1-2
* Thu Jan 14 2021 Jiajun Chen <1250062498@qq.com> - 1.1-2
- vcp_stat: add Max Scheduling Delay time items to display
- args: add -p option
- key: add page up/down key response
@ -89,22 +116,22 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name}
- arch: add x86 kvm exits items
- codestyle: del unused var
* Wed Oct 28 2020 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
* Wed Oct 28 2020 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-1
- display: modify filter display to support more display fields items
* Wed Oct 28 2020 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
* Wed Oct 28 2020 Huawei Technologies Co., Ltd <alex.chen@huawei.com> - 1.1-1
- vcpu_stat: add remaining kvm exits items to display
* Sat Oct 10 2020 Jiajun Chen <1250062498@qq.com> -1.1-0
* Sat Oct 10 2020 Jiajun Chen <1250062498@qq.com> - 1.1-0
- spec: modify source url
* Sun Sep 27 2020 nocjj <1250062498@qq.com>
* Sun Sep 27 2020 nocjj <1250062498@qq.com> - 1.0-4
- vcpustat: modify vcpu info acquirement from debugfs
- display: expand %CPU display
- display: add limit to usage display
- vmtop: simplify print_domain_field
* Mon Sep 21 2020 Ruyi Chen <chenruyi2@huawei.com>
* Mon Sep 21 2020 Ruyi Chen <chenruyi2@huawei.com> - 1.0-3
- vmtop: add -h and -v
* Mon Sep 21 2020 Jiajun Chen <1250062498@qq.com> - 1.0-2