pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

btop-git: Fix some memory stats.



Module Name:	pkgsrc-wip
Committed By:	Santhosh Raju <fox%NetBSD.org@localhost>
Pushed By:	fox
Date:		Thu Feb 22 15:48:59 2024 +0100
Changeset:	ef568bfa3e30aebee1673aa75279b512769c4bb2

Modified Files:
	btop-git/patches/patch-src_netbsd_btop__collect.cpp

Log Message:
btop-git: Fix some memory stats.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=ef568bfa3e30aebee1673aa75279b512769c4bb2

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 .../patches/patch-src_netbsd_btop__collect.cpp     | 45 +++++++++++-----------
 1 file changed, 22 insertions(+), 23 deletions(-)

diffs:
diff --git a/btop-git/patches/patch-src_netbsd_btop__collect.cpp b/btop-git/patches/patch-src_netbsd_btop__collect.cpp
index a09f8c8874..5b5ec89f5e 100644
--- a/btop-git/patches/patch-src_netbsd_btop__collect.cpp
+++ b/btop-git/patches/patch-src_netbsd_btop__collect.cpp
@@ -2,9 +2,9 @@ $NetBSD$
 
 Add support for NetBSD.
 
---- src/netbsd/btop_collect.cpp.orig	2024-02-20 04:23:40.288593132 +0000
+--- src/netbsd/btop_collect.cpp.orig	2024-02-22 14:43:00.208906303 +0000
 +++ src/netbsd/btop_collect.cpp
-@@ -0,0 +1,1284 @@
+@@ -0,0 +1,1283 @@
 +/* Copyright 2021 Aristocratos (jakob%qvantnet.com@localhost)
 +
 +   Licensed under the Apache License, Version 2.0 (the "License");
@@ -125,6 +125,7 @@ Add support for NetBSD.
 +	long pageSize, clkTck, coreCount, physicalCoreCount, arg_max;
 +	int totalMem_len, kfscale;
 +	long bootTime;
++	size_t size;
 +
 +	void init() {
 +		//? Shared global variables init
@@ -139,8 +140,8 @@ Add support for NetBSD.
 +			coreCount = ncpu;
 +		}
 +
-+		pageSize = sysconf(_SC_PAGE_SIZE);
-+		if (pageSize <= 0) {
++		size = sizeof(pageSize);
++		if (sysctlbyname("hw.pagesize", &pageSize, &size, nullptr, 0) < 0) {
 +			pageSize = 4096;
 +			Logger::warning("Could not get system page size. Defaulting to 4096, processes memory usage might be incorrect.");
 +		}
@@ -151,12 +152,10 @@ Add support for NetBSD.
 +			Logger::warning("Could not get system clock ticks per second. Defaulting to 100, processes cpu usage might be incorrect.");
 +		}
 +
-+		int64_t memsize = 0;
-+		size_t size = sizeof(memsize);
-+		if (sysctlbyname("hw.physmem", &memsize, &size, nullptr, 0) < 0) {
++		size = sizeof(totalMem);
++		if (sysctlbyname("hw.physmem", &totalMem, &size, nullptr, 0) < 0) {
 +			Logger::warning("Could not get memory size");
 +		}
-+		totalMem = memsize;
 +
 +		struct timeval result;
 +		size = sizeof(result);
@@ -606,9 +605,9 @@ Add support for NetBSD.
 +		auto &mem = current_mem;
 +		static bool snapped = (getenv("BTOP_SNAPPED") != nullptr);
 +
-+		u_int memActive, memWire, cachedMem;
-+		// u_int freeMem;
++		uint64_t memActive, memWired, memCached, memFree, memInactive;
 +		size_t size;
++
 +		static int uvmexp_mib[] = {CTL_VM, VM_UVMEXP2};
 +		struct uvmexp_sysctl uvmexp;
 +		size = sizeof(uvmexp);
@@ -616,21 +615,21 @@ Add support for NetBSD.
 +			Logger::error("uvmexp sysctl failed");
 +			bzero(&uvmexp, sizeof(uvmexp));
 +		}
-+		memActive = (uvmexp.active + uvmexp.wired) * Shared::pageSize;
-+		memWire = uvmexp.wired;
-+		// freeMem = uvmexp.free * Shared::pageSize;
-+		cachedMem = (uvmexp.filepages + uvmexp.execpages) * Shared::pageSize;
-+		mem.stats.at("used") = memActive;
-+		mem.stats.at("available") = Shared::totalMem - memActive - memWire;
-+   		mem.stats.at("cached") = cachedMem;
-+  		mem.stats.at("free") = Shared::totalMem - memActive - memWire;
++
++		memActive = (uvmexp.active + uvmexp.bootpages) * Shared::pageSize;
++		memWired = uvmexp.wired * Shared::pageSize;
++		memInactive = uvmexp.inactive * Shared::pageSize;
++		memFree = uvmexp.free * Shared::pageSize;
++		memCached = (uvmexp.filepages + uvmexp.execpages + uvmexp.anonpages) * Shared::pageSize;
++		mem.stats.at("used") = memActive + memWired;
++		mem.stats.at("available") = memInactive + memCached;
++		mem.stats.at("cached") = memCached;
++		mem.stats.at("free") = memFree;
 +
 +		if (show_swap) {
-+			uint64_t total = uvmexp.swpages * Shared::pageSize;
-+			mem.stats.at("swap_total") = total;
-+			uint64_t swapped = uvmexp.swpginuse * Shared::pageSize;
-+			mem.stats.at("swap_used") = swapped;
-+			mem.stats.at("swap_free") = total - swapped;
++			mem.stats.at("swap_total") = uvmexp.swpages * Shared::pageSize;
++			mem.stats.at("swap_used") = uvmexp.swpginuse * Shared::pageSize;
++			mem.stats.at("swap_free") = (uvmexp.swpages - uvmexp.swpginuse) * Shared::pageSize;
 +		}
 +
 +		if (show_swap and mem.stats.at("swap_total") > 0) {


Home | Main Index | Thread Index | Old Index