Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: add GPU meter and process column #1288

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = ColorPair(Magenta, Black),
[CPU_STEAL] = ColorPair(Cyan, Black),
[CPU_GUEST] = ColorPair(Cyan, Black),
[GPU_ENGINE_1] = ColorPair(Green, Black),
[GPU_ENGINE_2] = ColorPair(Yellow, Black),
[GPU_ENGINE_3] = ColorPair(Red, Black),
[GPU_ENGINE_4] = A_BOLD | ColorPair(Blue, Black),
[GPU_RESIDUE] = ColorPair(Magenta, Black),
[PANEL_EDIT] = ColorPair(White, Blue),
[SCREENS_OTH_BORDER] = ColorPair(Blue, Blue),
[SCREENS_OTH_TEXT] = ColorPair(Black, Blue),
Expand Down Expand Up @@ -312,6 +317,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = A_BOLD,
[CPU_STEAL] = A_DIM,
[CPU_GUEST] = A_DIM,
[GPU_ENGINE_1] = A_BOLD,
[GPU_ENGINE_2] = A_NORMAL,
[GPU_ENGINE_3] = A_REVERSE | A_BOLD,
[GPU_ENGINE_4] = A_REVERSE,
[GPU_RESIDUE] = A_BOLD,
[PANEL_EDIT] = A_BOLD,
[SCREENS_OTH_BORDER] = A_DIM,
[SCREENS_OTH_TEXT] = A_DIM,
Expand Down Expand Up @@ -425,6 +435,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = ColorPair(Blue, White),
[CPU_STEAL] = ColorPair(Cyan, White),
[CPU_GUEST] = ColorPair(Cyan, White),
[GPU_ENGINE_1] = ColorPair(Green, White),
[GPU_ENGINE_2] = ColorPair(Yellow, White),
[GPU_ENGINE_3] = ColorPair(Red, White),
[GPU_ENGINE_4] = ColorPair(Blue, White),
[GPU_RESIDUE] = ColorPair(Magenta, White),
[PANEL_EDIT] = ColorPair(White, Blue),
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black, White),
[SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black, White),
Expand Down Expand Up @@ -538,6 +553,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = ColorPair(Blue, Black),
[CPU_STEAL] = ColorPair(Black, Black),
[CPU_GUEST] = ColorPair(Black, Black),
[GPU_ENGINE_1] = ColorPair(Green, Black),
[GPU_ENGINE_2] = ColorPair(Yellow, Black),
[GPU_ENGINE_3] = ColorPair(Red, Black),
[GPU_ENGINE_4] = ColorPair(Blue, Black),
[GPU_RESIDUE] = ColorPair(Magenta, Black),
[PANEL_EDIT] = ColorPair(White, Blue),
[SCREENS_OTH_BORDER] = ColorPair(Blue, Black),
[SCREENS_OTH_TEXT] = ColorPair(Blue, Black),
Expand Down Expand Up @@ -651,6 +671,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = ColorPair(Black, Blue),
[CPU_STEAL] = ColorPair(White, Blue),
[CPU_GUEST] = ColorPair(White, Blue),
[GPU_ENGINE_1] = A_BOLD | ColorPair(Green, Blue),
[GPU_ENGINE_2] = A_BOLD | ColorPair(Yellow, Blue),
[GPU_ENGINE_3] = A_BOLD | ColorPair(Red, Blue),
[GPU_ENGINE_4] = A_BOLD | ColorPair(White, Blue),
[GPU_RESIDUE] = A_BOLD | ColorPair(Magenta, Blue),
[PANEL_EDIT] = ColorPair(White, Blue),
[SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow, Blue),
[SCREENS_OTH_TEXT] = ColorPair(Cyan, Blue),
Expand Down Expand Up @@ -762,6 +787,11 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[CPU_SOFTIRQ] = ColorPair(Blue, Black),
[CPU_STEAL] = ColorPair(Cyan, Black),
[CPU_GUEST] = ColorPair(Cyan, Black),
[GPU_ENGINE_1] = ColorPair(Green, Black),
[GPU_ENGINE_2] = ColorPair(Yellow, Black),
[GPU_ENGINE_3] = ColorPair(Red, Black),
[GPU_ENGINE_4] = ColorPair(Blue, Black),
[GPU_RESIDUE] = ColorPair(Magenta, Black),
[PANEL_EDIT] = ColorPair(White, Cyan),
[SCREENS_OTH_BORDER] = ColorPair(White, Black),
[SCREENS_OTH_TEXT] = ColorPair(Cyan, Black),
Expand Down
5 changes: 5 additions & 0 deletions CRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ typedef enum ColorElements_ {
CPU_SOFTIRQ,
CPU_STEAL,
CPU_GUEST,
GPU_ENGINE_1,
GPU_ENGINE_2,
GPU_ENGINE_3,
GPU_ENGINE_4,
GPU_RESIDUE,
PANEL_EDIT,
SCREENS_OTH_BORDER,
SCREENS_OTH_TEXT,
Expand Down
10 changes: 7 additions & 3 deletions Machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ void Machine_scanTables(Machine* this) {
// set scan timestamp
static bool firstScanDone = false;

if (firstScanDone)
Platform_gettime_monotonic(&this->monotonicMs);
else
if (firstScanDone) {
this->prevMonotonicMs = this->monotonicMs;
} else {
this->prevMonotonicMs = 0;
firstScanDone = true;
}
Platform_gettime_monotonic(&this->monotonicMs);
assert(this->monotonicMs > this->prevMonotonicMs);

this->maxUserId = 0;
Row_resetFieldWidths();
Expand Down
1 change: 1 addition & 0 deletions Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct Machine_ {
struct timeval realtime; /* time of the current sample */
uint64_t realtimeMs; /* current time in milliseconds */
uint64_t monotonicMs; /* same, but from monotonic clock */
uint64_t prevMonotonicMs; /* time in milliseconds from monotonic clock of previous scan */

int64_t iterationsRemaining;

Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ linux_platform_headers = \
generic/hostname.h \
generic/uname.h \
linux/CGroupUtils.h \
linux/GPU.h \
linux/GPUMeter.h \
linux/HugePageMeter.h \
linux/IOPriority.h \
linux/IOPriorityPanel.h \
Expand All @@ -196,6 +198,8 @@ linux_platform_sources = \
generic/hostname.c \
generic/uname.c \
linux/CGroupUtils.c \
linux/GPU.c \
linux/GPUMeter.c \
linux/HugePageMeter.c \
linux/IOPriorityPanel.c \
linux/LibSensors.c \
Expand Down
3 changes: 3 additions & 0 deletions Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ typedef struct ProcessFieldData_ {

/* Whether the column width is dynamically adjusted (the minimum width is determined by the title length) */
bool autoWidth;

/* Whether the title of a column with dynamically adjusted width is right aligned (default is left aligned) */
bool autoTitleRightAlign;
} ProcessFieldData;

#define LAST_PROCESSFIELD LAST_RESERVED_FIELD
Expand Down
10 changes: 9 additions & 1 deletion Row.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static const char* alignedTitleProcessField(ProcessField field, char* titleBuffe
}

if (Process_fields[field].autoWidth) {
if (field == PERCENT_CPU)
if (Process_fields[field].autoTitleRightAlign)
xSnprintf(titleBuffer, titleBufferSize, "%*s ", Row_fieldWidths[field], title);
else
xSnprintf(titleBuffer, titleBufferSize, "%-*.*s ", Row_fieldWidths[field], Row_fieldWidths[field], title);
Expand Down Expand Up @@ -337,6 +337,14 @@ void Row_printTime(RichString* str, unsigned long long totalHundredths, bool col
char buffer[10];
int len;

if (totalHundredths == 0) {
int shadowColor = coloring ? CRT_colors[PROCESS_SHADOW] : CRT_colors[PROCESS];

len = xSnprintf(buffer, sizeof(buffer), " 0:00.00 ");
RichString_appendnAscii(str, shadowColor, buffer, len);
return;
}

int yearColor = coloring ? CRT_colors[LARGE_NUMBER] : CRT_colors[PROCESS];
int dayColor = coloring ? CRT_colors[PROCESS_GIGABYTES] : CRT_colors[PROCESS];
int hourColor = coloring ? CRT_colors[PROCESS_MEGABYTES] : CRT_colors[PROCESS];
Expand Down
10 changes: 10 additions & 0 deletions XUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ static inline bool String_eq(const char* s1, const char* s2) {
return strcmp(s1, s2) == 0;
}

static inline bool String_eq_nullable(const char* s1, const char* s2) {
if (s1 == s2)
return true;

if (s1 && s2)
return String_eq(s1, s2);

return false;
}

ATTR_NONNULL
char* String_cat(const char* s1, const char* s2) ATTR_MALLOC;

Expand Down
2 changes: 1 addition & 1 deletion darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, },
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = " CPU%", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, .defaultSortDesc = true, .autoWidth = true, .autoTitleRightAlign = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, },
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
Expand Down
2 changes: 1 addition & 1 deletion dragonflybsd/DragonFlyBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, },
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = " CPU%", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, .defaultSortDesc = true, .autoWidth = true, .autoTitleRightAlign = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, },
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
Expand Down
2 changes: 1 addition & 1 deletion freebsd/FreeBSDProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, },
[M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_CPU] = { .name = "PERCENT_CPU", .title = " CPU%", .description = "Percentage of the CPU time the process used in the last sampling", .flags = 0, .defaultSortDesc = true, .autoWidth = true, .autoTitleRightAlign = true, },
[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, .defaultSortDesc = true, .autoWidth = true, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, },
[USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
Expand Down
Loading
Loading