mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Add process column for normalized CPU usage
Shows the process CPU usage divided by the number of CPU cores
This commit is contained in:
parent
a8a723ffe9
commit
15eab2012d
18
Process.c
18
Process.c
@ -257,13 +257,18 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
|
||||
bool coloring = this->settings->highlightMegabytes;
|
||||
|
||||
switch (field) {
|
||||
case PERCENT_CPU: {
|
||||
if (this->percent_cpu > 999.9) {
|
||||
xSnprintf(buffer, n, "%4u ", (unsigned int)this->percent_cpu);
|
||||
} else if (this->percent_cpu > 99.9) {
|
||||
xSnprintf(buffer, n, "%3u. ", (unsigned int)this->percent_cpu);
|
||||
case PERCENT_CPU:
|
||||
case PERCENT_NORM_CPU: {
|
||||
float cpuPercentage = this->percent_cpu;
|
||||
if (field == PERCENT_NORM_CPU) {
|
||||
cpuPercentage /= this->processList->cpuCount;
|
||||
}
|
||||
if (cpuPercentage > 999.9) {
|
||||
xSnprintf(buffer, n, "%4u ", (unsigned int)cpuPercentage);
|
||||
} else if (cpuPercentage > 99.9) {
|
||||
xSnprintf(buffer, n, "%3u. ", (unsigned int)cpuPercentage);
|
||||
} else {
|
||||
xSnprintf(buffer, n, "%4.1f ", this->percent_cpu);
|
||||
xSnprintf(buffer, n, "%4.1f ", cpuPercentage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -492,6 +497,7 @@ long Process_compare(const void* v1, const void* v2) {
|
||||
|
||||
switch (settings->sortKey) {
|
||||
case PERCENT_CPU:
|
||||
case PERCENT_NORM_CPU:
|
||||
return SPACESHIP_NUMBER(p2->percent_cpu, p1->percent_cpu);
|
||||
case PERCENT_MEM:
|
||||
return SPACESHIP_NUMBER(p2->m_resident, p1->m_resident);
|
||||
|
@ -48,6 +48,7 @@ typedef enum ProcessFields {
|
||||
TIME = 50,
|
||||
NLWP = 51,
|
||||
TGID = 52,
|
||||
PERCENT_NORM_CPU = 53,
|
||||
} ProcessField;
|
||||
|
||||
typedef struct ProcessPidColumn_ {
|
||||
|
@ -48,6 +48,7 @@ ProcessFieldData Process_fields[] = {
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
|
@ -40,6 +40,7 @@ ProcessFieldData Process_fields[] = {
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
|
@ -73,6 +73,7 @@ ProcessFieldData Process_fields[] = {
|
||||
[M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process (unused since Linux 2.6; always 0)", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
|
@ -142,6 +142,12 @@ ProcessFieldData Process_fields[] = {
|
||||
.description = "Percentage of the CPU time the process used in the last sampling",
|
||||
.flags = 0,
|
||||
},
|
||||
[PERCENT_NORM_CPU] = {
|
||||
.name = "PERCENT_NORM_CPU",
|
||||
.title = "NCPU%",
|
||||
.description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)",
|
||||
.flags = 0,
|
||||
},
|
||||
[PERCENT_MEM] = {
|
||||
.name = "PERCENT_MEM",
|
||||
.title = "MEM% ",
|
||||
|
@ -48,6 +48,7 @@ ProcessFieldData Process_fields[] = {
|
||||
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, },
|
||||
[ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .flags = 0, },
|
||||
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, },
|
||||
[PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, },
|
||||
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, },
|
||||
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
|
||||
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, },
|
||||
|
Loading…
Reference in New Issue
Block a user