mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 18:32:10 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b013377e5 |
@@ -26,30 +26,13 @@ jobs:
|
||||
- name: uname -a
|
||||
run: uname -a
|
||||
|
||||
- name: install required packages with MacPorts # Homebrew dropped Intel support
|
||||
if: inputs.arch == 'amd64'
|
||||
run: |
|
||||
curl -fsSL https://github.com/macports/macports-base/releases/download/v2.12.6/MacPorts-2.12.6-15-Sequoia.pkg -o "$RUNNER_TEMP/MacPorts.pkg"
|
||||
sudo installer -pkg "$RUNNER_TEMP/MacPorts.pkg" -target /
|
||||
echo /opt/local/bin >> "$GITHUB_PATH"
|
||||
echo /opt/local/sbin >> "$GITHUB_PATH"
|
||||
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
|
||||
sudo port selfupdate
|
||||
sudo port install vulkan-loader vulkan-headers MoltenVK ImageMagick7 chafa lua quickjs-ng jq
|
||||
|
||||
- name: install required packages with Homebrew
|
||||
if: inputs.arch == 'aarch64'
|
||||
- name: install required packages
|
||||
run: |
|
||||
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew update
|
||||
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 brew install --overwrite vulkan-loader vulkan-headers molten-vk imagemagick chafa lua quickjs-ng jq
|
||||
|
||||
- name: configure project
|
||||
run: |
|
||||
if [ "${{ inputs.arch }}" = "amd64" ]; then
|
||||
export CMAKE_PREFIX_PATH=/opt/local
|
||||
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
|
||||
fi
|
||||
cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
|
||||
run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On .
|
||||
|
||||
- name: build project
|
||||
run: cmake --build . --target package --verbose -j4
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
# Unreleased
|
||||
|
||||
Features:
|
||||
* Added CPU name and frequency detection support on SPARC. (CPU, Linux)
|
||||
|
||||
# 2.68.1
|
||||
|
||||
Changes:
|
||||
|
||||
+4
-4
@@ -1458,11 +1458,10 @@ if(yyjson_FOUND)
|
||||
# `target_link_libraries(yyjson::yyjson)` sets rpath implicitly
|
||||
endif()
|
||||
|
||||
# Used for dlopen finding dylibs installed by package managers
|
||||
# `/opt/homebrew/lib`, `/usr/local/lib` and `/opt/local/lib` are not on the
|
||||
# dlopen search path by default
|
||||
# Used for dlopen finding dylibs installed by homebrew
|
||||
# `/opt/homebrew/lib` is not on in dlopen search path by default
|
||||
if(APPLE AND BINARY_LINK_TYPE STREQUAL "dlopen")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib -Wl,-rpath,/opt/local/lib")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib")
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
@@ -1931,6 +1930,7 @@ elseif(FreeBSD)
|
||||
elseif(OpenBSD)
|
||||
target_link_libraries(libfastfetch
|
||||
PRIVATE "m"
|
||||
PRIVATE "kvm"
|
||||
PRIVATE "sndio"
|
||||
PRIVATE "util"
|
||||
)
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"home": "https://github.com/ibireme/yyjson",
|
||||
"license": "MIT ( embed in source )",
|
||||
"version": "0.13.0",
|
||||
"version": "0.12.0",
|
||||
"author": "ibireme"
|
||||
}
|
||||
|
||||
Vendored
+285
-700
File diff suppressed because it is too large
Load Diff
Vendored
+674
-911
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,6 @@
|
||||
#include "common/strutil.h"
|
||||
#include "common/io.h"
|
||||
#include "common/path.h"
|
||||
#include "common/mallocHelper.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
@@ -20,6 +19,7 @@
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <kvm.h>
|
||||
#include "common/path.h"
|
||||
#elif defined(__HAIKU__)
|
||||
#include <image.h>
|
||||
@@ -68,14 +68,13 @@ static void getExePath(FFPlatform* platform) {
|
||||
// Current implementation uses argv[0], which can be easily spoofed.
|
||||
// See #2195
|
||||
size_t exePathLen = 0;
|
||||
{
|
||||
char argvBuf[ARG_MAX];
|
||||
size_t argvSize = sizeof(argvBuf);
|
||||
int argvMib[] = { CTL_KERN, KERN_PROC_ARGS, (pid_t) platform->pid, KERN_PROC_ARGV };
|
||||
if (sysctl(argvMib, ARRAY_SIZE(argvMib), argvBuf, &argvSize, nullptr, 0) == 0) {
|
||||
// The buffer is filled with an array of char pointers followed by the strings themselves
|
||||
char** argv = (char**) argvBuf;
|
||||
if (argv[0] && (char*) argv[0] >= argvBuf && (char*) argv[0] < argvBuf + argvSize) {
|
||||
kvm_t* kd = kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
if (kd) {
|
||||
int kpCount;
|
||||
struct kinfo_proc* kp = kvm_getprocs(kd, KERN_PROC_PID, (pid_t) platform->pid, sizeof(*kp), &kpCount);
|
||||
if (kp && kpCount == 1) {
|
||||
char** argv = kvm_getargv(kd, kp, 0);
|
||||
if (argv && argv[0]) {
|
||||
char* arg0 = argv[0];
|
||||
if (arg0[0]) {
|
||||
if (strchr(arg0, '/') != nullptr) // likely a path (absolute or relative)
|
||||
@@ -98,38 +97,25 @@ static void getExePath(FFPlatform* platform) {
|
||||
if (exePathLen > 0) {
|
||||
struct stat st;
|
||||
if (stat(exePath, &st) == 0 && S_ISREG(st.st_mode)) {
|
||||
// Replicate kvm_getfiles()'s live path: {CTL_KERN, KERN_FILE, KERN_FILE_BYPID, pid, esize, count}
|
||||
int fileMib[6] = { CTL_KERN, KERN_FILE, KERN_FILE_BYPID, (pid_t) platform->pid, (int) sizeof(struct kinfo_file), 0 };
|
||||
size_t fileSize = 0;
|
||||
if (sysctl(fileMib, ARRAY_SIZE(fileMib), nullptr, &fileSize, nullptr, 0) == 0) {
|
||||
fileSize += fileSize / 8; // add ~10%
|
||||
FF_AUTO_FREE struct kinfo_file* kf = (struct kinfo_file*) malloc(fileSize);
|
||||
if (kf) {
|
||||
int rv;
|
||||
do {
|
||||
fileMib[5] = (int) (fileSize / sizeof(struct kinfo_file));
|
||||
rv = sysctl(fileMib, ARRAY_SIZE(fileMib), kf, &fileSize, nullptr, 0);
|
||||
} while (rv == -1 && errno == ENOMEM);
|
||||
|
||||
if (rv == 0) {
|
||||
int cntp = (int) (fileSize / sizeof(struct kinfo_file));
|
||||
int i;
|
||||
for (i = 0; i < cntp; i++) {
|
||||
if (kf[i].fd_fd == KERN_FILE_TEXT) {
|
||||
// KERN_FILE_TEXT is the executable file, not a shared library, and should be unique in the list.
|
||||
if (st.st_dev != (dev_t) kf[i].va_fsid || st.st_ino != (ino_t) kf[i].va_fileid) {
|
||||
i = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < 0) {
|
||||
exePathLen = 0;
|
||||
int cntp;
|
||||
struct kinfo_file* kf = kvm_getfiles(kd, KERN_FILE_BYPID, (pid_t) platform->pid, sizeof(*kf), &cntp);
|
||||
if (kf) {
|
||||
int i;
|
||||
for (i = 0; i < cntp; i++) {
|
||||
if (kf[i].fd_fd == KERN_FILE_TEXT) {
|
||||
// KERN_FILE_TEXT is the executable file, not a shared library, and should be unique in the list.
|
||||
if (st.st_dev != (dev_t) kf[i].va_fsid || st.st_ino != (ino_t) kf[i].va_fileid) {
|
||||
i = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// If we can't get the list of open files, we can't verify that the file is actually the executable
|
||||
// Assume it is
|
||||
}
|
||||
if (i < 0) {
|
||||
exePathLen = 0;
|
||||
}
|
||||
} else {
|
||||
// If we can't get the list of open files, we can't verify that the file is actually the executable
|
||||
// Assume it is
|
||||
}
|
||||
} else {
|
||||
exePathLen = 0;
|
||||
@@ -138,6 +124,7 @@ static void getExePath(FFPlatform* platform) {
|
||||
}
|
||||
}
|
||||
}
|
||||
kvm_close(kd);
|
||||
}
|
||||
#elif defined(__sun)
|
||||
ssize_t exePathLen = readlink("/proc/self/path/a.out", exePath, sizeof(exePath) - 1);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#elif defined(__NetBSD__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
@@ -422,13 +423,12 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
char argvBuf[ARG_MAX];
|
||||
size_t argvSize = sizeof(argvBuf);
|
||||
int argvMib[] = { CTL_KERN, KERN_PROC_ARGS, pid, KERN_PROC_ARGV };
|
||||
if (sysctl(argvMib, ARRAY_SIZE(argvMib), argvBuf, &argvSize, nullptr, 0) == 0) {
|
||||
// The buffer is filled with an array of char pointers followed by the strings themselves
|
||||
char** argv = (char**) argvBuf;
|
||||
if (argv[0] && (char*) argv[0] >= argvBuf && (char*) argv[0] < argvBuf + argvSize) {
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
int count = 0;
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
|
||||
if (proc) {
|
||||
char** argv = kvm_getargv(kd, proc, 0);
|
||||
if (argv) {
|
||||
const char* arg0 = argv[0];
|
||||
if (arg0[0] == '-') {
|
||||
arg0++;
|
||||
@@ -436,6 +436,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
|
||||
ffStrbufSetS(exe, arg0);
|
||||
}
|
||||
}
|
||||
kvm_close(kd);
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
@@ -632,19 +633,21 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
|
||||
struct kinfo_proc proc;
|
||||
size_t size = sizeof(proc);
|
||||
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, (int) sizeof(struct kinfo_proc), 1 };
|
||||
if (sysctl(mib, ARRAY_SIZE(mib), &proc, &size, nullptr, 0) == 0) {
|
||||
ffStrbufSetS(name, proc.p_comm);
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
int count = 0;
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count);
|
||||
if (proc) {
|
||||
ffStrbufSetS(name, proc->p_comm);
|
||||
if (ppid) {
|
||||
*ppid = proc.p_ppid;
|
||||
*ppid = proc->p_ppid;
|
||||
}
|
||||
if (tty) {
|
||||
*tty = (int) proc.p_tdev;
|
||||
*tty = (int) proc->p_tdev;
|
||||
}
|
||||
} else {
|
||||
return "sysctl(KERN_PROC_PID) failed";
|
||||
}
|
||||
kvm_close(kd);
|
||||
if (!proc) {
|
||||
return "kvm_getprocs() failed";
|
||||
}
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
||||
@@ -619,9 +619,6 @@ static const char* parseCpuInfo(
|
||||
(cpu->name.length == 0 && ffParsePropLine(line, "cpu :", &cpu->name)) ||
|
||||
#elif __sh__
|
||||
(cpu->name.length == 0 && ffParsePropLine(line, "cpu type :", &cpu->name)) ||
|
||||
#elif __sparc__ || __sparc
|
||||
(cpu->name.length == 0 && ffParsePropLine(line, "cpu :", &cpu->name)) ||
|
||||
(cpuMHz->length == 0 && ffParsePropLine(line, "Cpu0ClkTck :", cpuMHz)) ||
|
||||
#else
|
||||
(cpu->name.length == 0 && ffParsePropLine(line, "model name :", &cpu->name)) ||
|
||||
(cpu->name.length == 0 && ffParsePropLine(line, "model :", &cpu->name)) ||
|
||||
@@ -1104,10 +1101,6 @@ static const char* detectPhysicalCores(FFCPUResult* cpu) {
|
||||
if (cpu->name.length) {
|
||||
ffStrbufPrependS(&cpu->name, "Machine ");
|
||||
}
|
||||
#elif __sparc__ || __sparc
|
||||
// Cpu0ClkTck is in Hz, printed as "%016lx" by sparc64 and "%ld" by sparc32. A 32-bit userland can run
|
||||
// on a 64-bit kernel, so take the base from the width of the value rather than from our own bitness.
|
||||
cpu->frequencyBase = (uint32_t) (strtoull(cpuMHz.chars, nullptr, cpuMHz.length == 16 ? 16 : 10) / 1000000);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#elif __OpenBSD__
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#elif __sun
|
||||
#include <procfs.h>
|
||||
#elif __NetBSD__
|
||||
@@ -310,33 +311,25 @@ static const char* getFromProcesses(FFDisplayServerResult* result) {
|
||||
}
|
||||
}
|
||||
#elif __OpenBSD__
|
||||
int request[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) userId, (int) sizeof(struct kinfo_proc), 0 };
|
||||
size_t length = 0;
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
int count = 0;
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, (int) userId, sizeof(*proc), &count);
|
||||
if (proc) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (result->dePrettyName.length == 0) {
|
||||
applyPrettyNameIfDE(result, proc[i].p_comm);
|
||||
}
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed";
|
||||
}
|
||||
if (result->wmPrettyName.length == 0) {
|
||||
applyNameIfWM(result, proc[i].p_comm);
|
||||
}
|
||||
|
||||
FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length);
|
||||
request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch
|
||||
if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed";
|
||||
}
|
||||
|
||||
int count = (int) (length / sizeof(struct kinfo_proc));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
if (result->dePrettyName.length == 0) {
|
||||
applyPrettyNameIfDE(result, procs[i].p_comm);
|
||||
}
|
||||
|
||||
if (result->wmPrettyName.length == 0) {
|
||||
applyNameIfWM(result, procs[i].p_comm);
|
||||
}
|
||||
|
||||
if (result->dePrettyName.length > 0 && result->wmPrettyName.length > 0) {
|
||||
break;
|
||||
if (result->dePrettyName.length > 0 && result->wmPrettyName.length > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
kvm_close(kd);
|
||||
#elif __sun
|
||||
FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc");
|
||||
if (procdir == nullptr) {
|
||||
|
||||
+13
-20
@@ -18,6 +18,7 @@
|
||||
#elif __OpenBSD__
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
#elif __sun
|
||||
#include <procfs.h>
|
||||
#elif __NetBSD__
|
||||
@@ -54,7 +55,7 @@ static const char* getSshdVersion(FFstrbuf* version) {
|
||||
#ifdef FF_HAVE_ZLIB
|
||||
#include "common/library.h"
|
||||
#include "common/path.h"
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
|
||||
@@ -273,27 +274,19 @@ const char* detectByProcesses(FFLMResult* result) {
|
||||
}
|
||||
}
|
||||
#elif __OpenBSD__
|
||||
int request[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, 0, (int) sizeof(struct kinfo_proc), 0 };
|
||||
size_t length = 0;
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, nullptr) failed";
|
||||
}
|
||||
|
||||
FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length);
|
||||
request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch
|
||||
if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_UID}, procs) failed";
|
||||
}
|
||||
|
||||
int count = (int) (length / sizeof(struct kinfo_proc));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const char* lm = testLms(procs[i].p_comm);
|
||||
if (lm) {
|
||||
ffStrbufSetStatic(&result->service, lm);
|
||||
break;
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
int count = 0;
|
||||
const struct kinfo_proc* proc = kvm_getprocs(kd, KERN_PROC_UID, 0, sizeof(*proc), &count);
|
||||
if (proc) {
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const char* lm = testLms(proc[i].p_comm);
|
||||
if (lm) {
|
||||
ffStrbufSetStatic(&result->service, lm);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
kvm_close(kd);
|
||||
#elif __sun
|
||||
FF_AUTO_CLOSE_DIR DIR* procdir = opendir("/proc");
|
||||
if (procdir == nullptr) {
|
||||
|
||||
@@ -31,10 +31,10 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu
|
||||
|
||||
pid_t pid = proc->kp_proc.p_pid;
|
||||
struct proc_taskinfo taskInfo;
|
||||
if (proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &taskInfo, sizeof(taskInfo)) == sizeof(taskInfo)) {
|
||||
// NOTE: This fails for system processes
|
||||
result->threads += (uint32_t) taskInfo.pti_threadnum;
|
||||
if (proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &taskInfo, sizeof(taskInfo)) != sizeof(taskInfo)) {
|
||||
continue;
|
||||
}
|
||||
result->threads += (uint32_t) taskInfo.pti_threadnum;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
||||
@@ -4,22 +4,25 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
|
||||
const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResult* result) {
|
||||
int request[] = { CTL_KERN, KERN_PROC, (options->countKprocs ? KERN_PROC_KTHREAD : KERN_PROC_ALL) | KERN_PROC_SHOW_THREADS, 0, (int) sizeof(struct kinfo_proc), 0 };
|
||||
size_t length = 0;
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed";
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
if (!kd) {
|
||||
return "kvm_open() failed";
|
||||
}
|
||||
|
||||
FF_AUTO_FREE struct kinfo_proc* procs = (struct kinfo_proc*) malloc(length);
|
||||
request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch
|
||||
if (sysctl(request, ARRAY_SIZE(request), procs, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, procs) failed";
|
||||
int count = 0;
|
||||
// KERN_PROC_ALL returns all user-level processes
|
||||
// KERN_PROC_KTHREAD returns all processes, including user-level processes (despite the name)
|
||||
const struct kinfo_proc* procs = kvm_getprocs(kd,
|
||||
(options->countKprocs ? KERN_PROC_KTHREAD : KERN_PROC_ALL) | KERN_PROC_SHOW_THREADS,
|
||||
0, sizeof(struct kinfo_proc), &count);
|
||||
if (!procs) {
|
||||
kvm_close(kd);
|
||||
return "kvm_getprocs() failed";
|
||||
}
|
||||
|
||||
int count = (int) (length / sizeof(struct kinfo_proc));
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const struct kinfo_proc* proc = &procs[i];
|
||||
|
||||
@@ -29,5 +32,6 @@ const char* ffDetectProcesses(const FFProcessesOptions* options, FFProcessesResu
|
||||
}
|
||||
}
|
||||
|
||||
kvm_close(kd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -6,46 +6,59 @@
|
||||
#include <libproc.h>
|
||||
|
||||
const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) {
|
||||
int npids = proc_listallpids(nullptr, 0);
|
||||
if (npids <= 0) {
|
||||
return "proc_listallpids(nullptr, 0) failed";
|
||||
}
|
||||
FF_AUTO_FREE pid_t* pids = malloc((uint32_t) (npids + npids / 8 + 1) * sizeof(pid_t));
|
||||
npids = proc_listallpids(pids, npids);
|
||||
if (npids <= 0) {
|
||||
return "proc_listallpids(pids, bufferSize) failed";
|
||||
int request[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
|
||||
size_t length;
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, nullptr}) failed";
|
||||
}
|
||||
|
||||
uint32_t count = (uint32_t) npids;
|
||||
// The process table may change between the two sysctl calls; retry with a larger buffer.
|
||||
length += length / 8 + sizeof(struct kinfo_proc);
|
||||
FF_AUTO_FREE struct kinfo_proc* processes = malloc(length);
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL, processes}) failed";
|
||||
}
|
||||
|
||||
uint32_t count = (uint32_t) (length / sizeof(struct kinfo_proc));
|
||||
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
pid_t pid = pids[i];
|
||||
|
||||
struct proc_taskallinfo proc;
|
||||
if (proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &proc, sizeof(proc)) != sizeof(proc)) {
|
||||
const struct kinfo_proc* proc = &processes[i];
|
||||
if (proc->kp_proc.p_flag & P_SYSTEM) {
|
||||
continue;
|
||||
}
|
||||
pid_t pid = proc->kp_proc.p_pid;
|
||||
|
||||
if (proc.pbsd.pbi_flags & PROC_FLAG_SYSTEM) {
|
||||
continue;
|
||||
struct rusage_info_v2 rusage;
|
||||
if (proc_pid_rusage(pid, RUSAGE_INFO_V2, (rusage_info_t*) &rusage) != 0) {
|
||||
continue; // The process may have exited
|
||||
}
|
||||
|
||||
FFTopProcessSnapshot* item = FF_LIST_ADD(FFTopProcessSnapshot, *snapshots);
|
||||
ffStrbufInitS(&item->name, proc.pbsd.pbi_name);
|
||||
if (item->name.length == 0) {
|
||||
ffStrbufInitS(&item->name, proc.pbsd.pbi_comm);
|
||||
}
|
||||
ffStrbufInitS(&item->name, proc->kp_proc.p_comm);
|
||||
item->pid = (uint32_t) pid;
|
||||
item->cpuTime = (proc.ptinfo.pti_total_user + proc.ptinfo.pti_total_system) / 1000000u; // ns -> ms
|
||||
item->memBytes = proc.ptinfo.pti_resident_size;
|
||||
item->startTime = proc.pbsd.pbi_start_tvsec * 1000u + proc.pbsd.pbi_start_tvusec / 1000u; // convert to ms
|
||||
item->threads = (uint32_t) proc.ptinfo.pti_threadnum;
|
||||
|
||||
if (showTypes & FF_TOP_TYPE_DISK) {
|
||||
struct rusage_info_v2 rusage;
|
||||
if (proc_pid_rusage(pid, RUSAGE_INFO_V2, (rusage_info_t*) &rusage) == 0) {
|
||||
item->bytesRead = rusage.ri_diskio_bytesread;
|
||||
item->bytesWritten = rusage.ri_diskio_byteswritten;
|
||||
// Note: Do NOT use proc->kp_proc.p_pctcpu for CPU usage. p_pctcpu is a
|
||||
// decaying average (fixpt_t with FSCALE=2048) updated roughly once per
|
||||
// second by the kernel. It is heavily smoothed, lags short bursts, has
|
||||
// low resolution, and its multicore scaling (>100%) is inconsistent
|
||||
// across XNU versions. It also breaks the unified model where
|
||||
// FFTopProcessSnapshot.cpuTime is cumulative time and top.c computes
|
||||
// (new - old) / elapsed * 100 for all platforms. proc_pid_rusage with
|
||||
// RUSAGE_INFO_V2 provides precise cumulative ri_user_time +
|
||||
// ri_system_time in nanoseconds and is the modern recommended API on
|
||||
// Darwin, consistent with Linux/BSD differential sampling and accurate
|
||||
// for the short waitTime interval (e.g. 100ms).
|
||||
item->cpuTime = (rusage.ri_user_time + rusage.ri_system_time) / 1000000u; // ns -> ms
|
||||
item->memBytes = rusage.ri_resident_size;
|
||||
item->bytesRead = rusage.ri_diskio_bytesread;
|
||||
item->bytesWritten = rusage.ri_diskio_byteswritten;
|
||||
item->startTime = rusage.ri_proc_start_abstime;
|
||||
item->threads = 0;
|
||||
if (showTypes & FF_TOP_TYPE_THREADS) {
|
||||
struct proc_taskinfo taskInfo;
|
||||
if (proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &taskInfo, sizeof(taskInfo)) == sizeof(taskInfo)) {
|
||||
item->threads = (uint32_t) taskInfo.pti_threadnum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,24 @@
|
||||
#include "top.h"
|
||||
|
||||
#include "common/mallocHelper.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h> // DEV_BSIZE
|
||||
#include <sys/sysctl.h>
|
||||
#include <kvm.h>
|
||||
|
||||
const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) {
|
||||
int request[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0, (int) sizeof(struct kinfo_proc), 0 };
|
||||
size_t length = 0;
|
||||
|
||||
if (sysctl(request, ARRAY_SIZE(request), nullptr, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, nullptr) failed";
|
||||
kvm_t* kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr);
|
||||
if (!kd) {
|
||||
return "kvm_open() failed";
|
||||
}
|
||||
|
||||
FF_AUTO_FREE struct kinfo_proc* processes = (struct kinfo_proc*) malloc(length);
|
||||
request[5] = (int) (length / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch
|
||||
if (sysctl(request, ARRAY_SIZE(request), processes, &length, nullptr, 0) != 0) {
|
||||
return "sysctl({CTL_KERN, KERN_PROC, KERN_PROC_ALL}, processes) failed";
|
||||
int count = 0;
|
||||
// KERN_PROC_ALL returns all user-level processes, excluding kernel processes and threads
|
||||
const struct kinfo_proc* processes = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
|
||||
if (!processes) {
|
||||
kvm_close(kd);
|
||||
return "kvm_getprocs() failed";
|
||||
}
|
||||
|
||||
int count = (int) (length / sizeof(struct kinfo_proc));
|
||||
const uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
@@ -43,24 +41,21 @@ const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) {
|
||||
}
|
||||
|
||||
if (showTypes & FF_TOP_TYPE_THREADS) {
|
||||
int threadRequest[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL | KERN_PROC_SHOW_THREADS, 0, (int) sizeof(struct kinfo_proc), 0 };
|
||||
size_t threadLength = 0;
|
||||
if (sysctl(threadRequest, ARRAY_SIZE(threadRequest), nullptr, &threadLength, nullptr, 0) == 0 && threadLength > 0) {
|
||||
FF_AUTO_FREE struct kinfo_proc* threads = (struct kinfo_proc*) malloc(threadLength);
|
||||
threadRequest[5] = (int) (threadLength / sizeof(struct kinfo_proc)); // count must be non-zero for data fetch
|
||||
if (sysctl(threadRequest, ARRAY_SIZE(threadRequest), threads, &threadLength, nullptr, 0) == 0) {
|
||||
int threadCount = (int) (threadLength / sizeof(struct kinfo_proc));
|
||||
for (uint32_t i = 0; i < snapshots->length; ++i) {
|
||||
FFTopProcessSnapshot* item = FF_LIST_GET(FFTopProcessSnapshot, *snapshots, i);
|
||||
for (int j = 0; j < threadCount; ++j) {
|
||||
if (threads[j].p_pid == (pid_t) item->pid && threads[j].p_tid != -1) {
|
||||
++item->threads;
|
||||
}
|
||||
int threadCount = 0;
|
||||
const struct kinfo_proc* threads = kvm_getprocs(kd,
|
||||
KERN_PROC_ALL | KERN_PROC_SHOW_THREADS, 0, sizeof(struct kinfo_proc), &threadCount);
|
||||
if (threads) {
|
||||
for (uint32_t i = 0; i < snapshots->length; ++i) {
|
||||
FFTopProcessSnapshot* item = FF_LIST_GET(FFTopProcessSnapshot, *snapshots, i);
|
||||
for (int j = 0; j < threadCount; ++j) {
|
||||
if (threads[j].p_pid == (pid_t) item->pid && threads[j].p_tid != -1) {
|
||||
++item->threads;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kvm_close(kd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
#include "common/color.h"
|
||||
|
||||
static const FFlogo Z[] = {
|
||||
#ifdef FASTFETCH_DATATEXT_LOGO_ZERENE
|
||||
// Zerene
|
||||
{
|
||||
.names = { "Zerene" },
|
||||
.lines = FASTFETCH_DATATEXT_LOGO_ZERENE,
|
||||
.colors = {
|
||||
FF_COLOR_FG_BLUE,
|
||||
},
|
||||
.colorKeys = FF_COLOR_FG_BLUE,
|
||||
.colorTitle = FF_COLOR_FG_BLUE,
|
||||
},
|
||||
#endif
|
||||
#ifdef FASTFETCH_DATATEXT_LOGO_ZORIN
|
||||
// Zorin
|
||||
{
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
MMM
|
||||
MMMM
|
||||
MMMMM
|
||||
MMMMMM
|
||||
MMMMMMa
|
||||
MMMMMMMa
|
||||
MMMMMMM
|
||||
MMMMMM
|
||||
MMMM
|
||||
M
|
||||
oxdo aMa
|
||||
aMd aMMMMMMMMM
|
||||
aMMMMM MMMMMMMMMMMMMMa
|
||||
MMMMMMMa MMMMMMMMMMMMMMMa
|
||||
MMMMMMMMa
|
||||
MMMMMMMMa
|
||||
MMMMMMM
|
||||
MMMM
|
||||
Reference in New Issue
Block a user