Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ int CommandLine_run(int argc, char** argv) {

ScreenManager_run(scr, NULL, NULL, NULL);

Platform_done();
Platform_done(host);

CRT_done();

Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ linux_platform_headers = \
linux/LinuxMachine.h \
linux/LinuxProcess.h \
linux/LinuxProcessTable.h \
linux/NetSpeed.h \
linux/OpenRCMeter.h \
linux/Platform.h \
linux/PressureStallMeter.h \
Expand Down Expand Up @@ -226,6 +227,7 @@ linux_platform_sources = \
linux/LinuxMachine.c \
linux/LinuxProcess.c \
linux/LinuxProcessTable.c \
linux/NetSpeed.c \
linux/OpenRCMeter.c \
linux/Platform.c \
linux/PressureStallMeter.c \
Expand Down
3 changes: 2 additions & 1 deletion darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ double Platform_schedulerTicksToNanoseconds(const double scheduler_ticks) {
return scheduler_ticks * Platform_nanosecondsPerSchedulerTick;
}

void Platform_done(void) {
void Platform_done(Machine* host) {
(void)host;
/* no platform-specific cleanup needed */
}

Expand Down
2 changes: 1 addition & 1 deletion darwin/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uint64_t Platform_machTicksToNanoseconds(uint64_t mach_ticks);
// See `sysconf(_SC_CLK_TCK)`, as used to define the `Platform_nanosecondsPerSchedulerTick` constant.
double Platform_schedulerTicksToNanoseconds(const double scheduler_ticks);

void Platform_done(void);
void Platform_done(Machine* host);

void Platform_setBindings(Htop_Action* keys);

Expand Down
3 changes: 2 additions & 1 deletion dragonflybsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ bool Platform_init(void) {
return true;
}

void Platform_done(void) {
void Platform_done(Machine* host) {
(void)host;
/* no platform-specific cleanup needed */
}

Expand Down
2 changes: 1 addition & 1 deletion dragonflybsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern const MeterClass* const Platform_meterTypes[];

bool Platform_init(void);

void Platform_done(void);
void Platform_done(Machine* host);

void Platform_setBindings(Htop_Action* keys);

Expand Down
3 changes: 2 additions & 1 deletion freebsd/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ bool Platform_init(void) {
return true;
}

void Platform_done(void) {
void Platform_done(Machine* host) {
(void) host;
/* no platform-specific cleanup needed */
}

Expand Down
2 changes: 1 addition & 1 deletion freebsd/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern const MeterClass* const Platform_meterTypes[];

bool Platform_init(void);

void Platform_done(void);
void Platform_done(Machine* host);

void Platform_setBindings(Htop_Action* keys);

Expand Down
8 changes: 7 additions & 1 deletion linux/LinuxMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ in the source distribution for its full text.

#include "CRT.h"
#include "Macros.h"
#include "ProcessTable.h"
#include "NetSpeed.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the duplicate include, and restore ProcessTable.h if it was removed.

NetSpeed.h is included twice, at Line 28 and at Line 35 as linux/NetSpeed.h. Keep only linux/NetSpeed.h. The change summary says that the ProcessTable.h include was removed. Confirm that this file still compiles without it through an indirect include.

#include "Row.h"
#include "Settings.h"
#include "UsersTable.h"

#include "linux/Compat.h"
#include "linux/Platform.h" // needed for GNU/hurd to get PATH_MAX // IWYU pragma: keep
#include "linux/NetSpeed.h"

#ifdef HAVE_SENSORS_SENSORS_H
#include "LibSensors.h"
Expand Down Expand Up @@ -861,6 +862,10 @@ static void LinuxMachine_scanCPUFrequency(LinuxMachine* this) {
scanCPUFrequencyFromCPUinfo(this);
}

static void LinuxMachine_scanNetworkSpeed(LinuxMachine* this) {
NetSpeed_monitor(this);
}

void Machine_scan(Machine* super) {
LinuxMachine* this = (LinuxMachine*) super;

Expand All @@ -870,6 +875,7 @@ void Machine_scan(Machine* super) {
LinuxMachine_scanZfsArcstats(this);
LinuxMachine_scanZramInfo(this);
LinuxMachine_scanCPUTime(this);
LinuxMachine_scanNetworkSpeed(this);

const Settings* settings = super->settings;
if (settings->showCPUFrequency
Expand Down
8 changes: 8 additions & 0 deletions linux/LinuxMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ in the source distribution for its full text.
#include <stdbool.h>
#include <stddef.h>

#include "linux/NetSpeed.h"
#include "Machine.h"
#include "linux/ZramStats.h"
#include "linux/ZswapStats.h"
Expand Down Expand Up @@ -60,6 +61,12 @@ typedef struct CPUData_ {
bool online;
} CPUData;

typedef struct NetMonitoringData_ {
int socket;
uint32_t seq;
NetworkSpeedMeterData networkSpeedMeterData;
} NetMonitoringData;

typedef struct GPUEngineData_ {
unsigned long long int prevTime, curTime; /* absolute GPU time in nano seconds */
char* key; /* engine name */
Expand Down Expand Up @@ -95,6 +102,7 @@ typedef struct LinuxMachine_ {

unsigned long long int prevGpuTime, curGpuTime; /* total absolute GPU time in nano seconds */
GPUEngineData* gpuEngineData;
NetMonitoringData* netMonitoringData;

ZfsArcStats zfs;
ZramStats zram;
Expand Down
12 changes: 12 additions & 0 deletions linux/LinuxProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
#endif
[GPU_TIME] = { .name = "GPU_TIME", .title = "GPU_TIME ", .description = "Total GPU time", .flags = PROCESS_FLAG_LINUX_GPU, .defaultSortDesc = true, },
[GPU_PERCENT] = { .name = "GPU_PERCENT", .title = " GPU% ", .description = "Percentage of the GPU time the process used in the last sampling", .flags = PROCESS_FLAG_LINUX_GPU, .defaultSortDesc = true, },
[TCP_UPLOAD_RATE] = { .name = "TCP_UPLOAD_RATE", .title = " TCP UPLOAD ", .description = "Upload rate of the TCP in seconds", .flags = PROCESS_FLAG_LINUX_NET_MONITOR, .defaultSortDesc = true },
[TCP_DOWNLOAD_RATE] = { .name = "TCP_DOWNLOAD_RATE", .title = " TCP DOWNLOAD ", .description = "Download rate of the TCP in seconds", .flags = PROCESS_FLAG_LINUX_NET_MONITOR, .defaultSortDesc = true },
Comment on lines +110 to +111

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Correct the field descriptions.

The descriptions say "Upload rate of the TCP in seconds". These are rates in bytes per second. Use "TCP upload rate in bytes per second" and "TCP download rate in bytes per second".

};

Process* LinuxProcess_new(const Machine* host) {
Expand Down Expand Up @@ -355,6 +357,12 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces
xSnprintf(buffer, n, "N/A ");
}
break;
case TCP_DOWNLOAD_RATE:
Row_printRate(str, lp->tcp_rate.download, coloring);
return;
case TCP_UPLOAD_RATE:
Row_printRate(str, lp->tcp_rate.upload, coloring);
return;
default:
Process_writeField(this, str, field);
return;
Expand Down Expand Up @@ -451,6 +459,10 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
return SPACESHIP_NUMBER(p1->gpu_time, p2->gpu_time);
case ISCONTAINER:
return SPACESHIP_NUMBER(v1->isRunningInContainer, v2->isRunningInContainer);
case TCP_DOWNLOAD_RATE:
return compareRealNumbers(p1->tcp_rate.download, p2->tcp_rate.download);
case TCP_UPLOAD_RATE:
return compareRealNumbers(p1->tcp_rate.upload, p2->tcp_rate.upload);
default:
return Process_compareByKey_Base(v1, v2, key);
}
Expand Down
11 changes: 11 additions & 0 deletions linux/LinuxProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ in the source distribution for its full text.
#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
#define PROCESS_FLAG_LINUX_GPU 0x00100000
#define PROCESS_FLAG_LINUX_CONTAINER 0x00200000
#define PROCESS_FLAG_LINUX_NET_MONITOR 0x00400000


struct TransceptionRate {
double upload;
double download;
uint64_t last_updated;
size_t generation;
};

typedef struct LinuxProcess_ {
Process super;
Expand Down Expand Up @@ -110,6 +119,8 @@ typedef struct LinuxProcess_ {
/* Autogroup scheduling (CFS) information */
long int autogroup_id;
int autogroup_nice;

struct TransceptionRate tcp_rate;
} LinuxProcess;

extern int pageSize;
Expand Down
5 changes: 5 additions & 0 deletions linux/LinuxProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ in the source distribution for its full text.
#include "Hashtable.h"
#include "Machine.h"
#include "Macros.h"
#include "NetSpeed.h"
#include "Object.h"
#include "Process.h"
#include "Row.h"
Expand Down Expand Up @@ -1779,6 +1780,10 @@ static bool LinuxProcessTable_recurseProcTree(LinuxProcessTable* this, openat_ar
}
}

if (ss->flags & PROCESS_FLAG_LINUX_NET_MONITOR) {
NetSpeed_dirty(lp);
}

Comment on lines +1783 to +1786

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

This block calls a function that does nothing.

NetSpeed_dirty is a no-op. Use this hook to reset stale tcp_rate values (see the comment on NetSpeed.c Line 168-173), or remove it.

/*
* Final section after all data has been gathered
*/
Expand Down
Loading