From: @zhendongchen Reviewed-by: @zhanghailiang_lucky,@zhanghailiang_lucky Signed-off-by: @zhanghailiang_lucky,@zhanghailiang_lucky
This commit is contained in:
commit
40defc9dd1
43
input-change-wait-mechanism-for-input.patch
Normal file
43
input-change-wait-mechanism-for-input.patch
Normal 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
|
||||
|
||||
33
keyboard-change-wait-time-to-3s.patch
Normal file
33
keyboard-change-wait-time-to-3s.patch
Normal 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
|
||||
|
||||
35
performance-change-memset-location.patch
Normal file
35
performance-change-memset-location.patch
Normal 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
|
||||
|
||||
70
performance-del-unnecessary-memcpy-and-memset.patch
Normal file
70
performance-del-unnecessary-memcpy-and-memset.patch
Normal 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
|
||||
|
||||
129
proc-del-loop-sscanf-for-proc-pid-stat-file.patch
Normal file
129
proc-del-loop-sscanf-for-proc-pid-stat-file.patch
Normal 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
|
||||
|
||||
153
proc-del-unused-items-getting-from-proc-stat-refresh.patch
Normal file
153
proc-del-unused-items-getting-from-proc-stat-refresh.patch
Normal 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
|
||||
|
||||
35
utils-del-realpath-from-read_file.patch
Normal file
35
utils-del-realpath-from-read_file.patch
Normal 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
|
||||
|
||||
60
vcpu_list-pre-malloc-vcpu-list-to-improve-performanc.patch
Normal file
60
vcpu_list-pre-malloc-vcpu-list-to-improve-performanc.patch
Normal 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
|
||||
|
||||
22
vmtop.spec
22
vmtop.spec
@ -1,6 +1,6 @@
|
||||
Name: vmtop
|
||||
Version: 1.1
|
||||
Release: 4
|
||||
Release: 5
|
||||
Summary: A tool for collecting and analyzing data of virtual machine
|
||||
License: Mulan PSL V2
|
||||
Group: Application/System
|
||||
@ -30,6 +30,14 @@ 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
|
||||
|
||||
Requires: libvirt, ncurses
|
||||
|
||||
@ -70,6 +78,18 @@ install -m 550 vmtop ${RPM_BUILD_ROOT}/usr/bin/%{name}
|
||||
%{_bindir}/vmtop
|
||||
|
||||
%changelog
|
||||
* Tue Mar 16 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
|
||||
- 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>
|
||||
- input: change wait mechanism for input
|
||||
|
||||
* Sat Feb 27 2021 Huawei Technologies Co., Ltd <alex.chen@huawei.com>
|
||||
- version: unified with release version
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user