aboutsummaryrefslogtreecommitdiffstats
path: root/darwin/Platform.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /darwin/Platform.c
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'darwin/Platform.c')
-rw-r--r--darwin/Platform.c194
1 files changed, 157 insertions, 37 deletions
diff --git a/darwin/Platform.c b/darwin/Platform.c
index a8ca45b..e24b67b 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -2,27 +2,36 @@
htop - darwin/Platform.c
(C) 2014 Hisham H. Muhammad
(C) 2015 David C. Hunt
-Released under the GNU GPL, see the COPYING file
+Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
#include "Platform.h"
+#include "Macros.h"
#include "CPUMeter.h"
#include "MemoryMeter.h"
#include "SwapMeter.h"
#include "TasksMeter.h"
#include "LoadAverageMeter.h"
#include "ClockMeter.h"
+#include "DateMeter.h"
+#include "DateTimeMeter.h"
#include "HostnameMeter.h"
+#include "ProcessLocksScreen.h"
#include "UptimeMeter.h"
#include "zfs/ZfsArcMeter.h"
#include "zfs/ZfsCompressedArcMeter.h"
#include "DarwinProcessList.h"
+#include <math.h>
#include <stdlib.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreFoundation/CFString.h>
+#include <IOKit/ps/IOPowerSources.h>
+#include <IOKit/ps/IOPSKeys.h>
-ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
+ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
const SignalItem Platform_signals[] = {
{ .name = " 0 Cancel", .number = 0 },
@@ -60,7 +69,7 @@ const SignalItem Platform_signals[] = {
{ .name = "31 SIGUSR2", .number = 31 },
};
-const unsigned int Platform_numberOfSignals = sizeof(Platform_signals)/sizeof(SignalItem);
+const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals);
ProcessFieldData Process_fields[] = {
[0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, },
@@ -79,7 +88,7 @@ ProcessFieldData Process_fields[] = {
[STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, },
[PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, },
- [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
+ [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, },
[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, },
@@ -91,9 +100,11 @@ ProcessFieldData Process_fields[] = {
[100] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
};
-MeterClass* Platform_meterTypes[] = {
+const MeterClass* const Platform_meterTypes[] = {
&CPUMeter_class,
&ClockMeter_class,
+ &DateMeter_class,
+ &DateTimeMeter_class,
&LoadAverageMeter_class,
&LoadMeter_class,
&MemoryMeter_class,
@@ -104,22 +115,37 @@ MeterClass* Platform_meterTypes[] = {
&UptimeMeter_class,
&AllCPUsMeter_class,
&AllCPUs2Meter_class,
+ &AllCPUs4Meter_class,
+ &AllCPUs8Meter_class,
&LeftCPUsMeter_class,
&RightCPUsMeter_class,
&LeftCPUs2Meter_class,
&RightCPUs2Meter_class,
+ &LeftCPUs4Meter_class,
+ &RightCPUs4Meter_class,
+ &LeftCPUs8Meter_class,
+ &RightCPUs8Meter_class,
&ZfsArcMeter_class,
&ZfsCompressedArcMeter_class,
&BlankMeter_class,
NULL
};
+int Platform_numberOfFields = 100;
+
+void Platform_init(void) {
+ /* no platform-specific setup needed */
+}
+
+void Platform_done(void) {
+ /* no platform-specific cleanup needed */
+}
+
void Platform_setBindings(Htop_Action* keys) {
+ /* no platform-specific key bindings */
(void) keys;
}
-int Platform_numberOfFields = 100;
-
int Platform_getUptime() {
struct timeval bootTime, currTime;
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
@@ -137,7 +163,7 @@ int Platform_getUptime() {
void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
double results[3];
- if(3 == getloadavg(results, 3)) {
+ if (3 == getloadavg(results, 3)) {
*one = results[0];
*five = results[1];
*fifteen = results[2];
@@ -164,8 +190,8 @@ ProcessPidColumn Process_pidColumns[] = {
};
static double Platform_setCPUAverageValues(Meter* mtr) {
- DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
- int cpus = dpl->super.cpuCount;
+ const ProcessList* dpl = mtr->pl;
+ int cpus = dpl->cpuCount;
double sumNice = 0.0;
double sumNormal = 0.0;
double sumKernel = 0.0;
@@ -188,36 +214,37 @@ double Platform_setCPUValues(Meter* mtr, int cpu) {
return Platform_setCPUAverageValues(mtr);
}
- DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
- processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];
- processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1];
+ const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl;
+ const processor_cpu_load_info_t prev = &dpl->prev_load[cpu - 1];
+ const processor_cpu_load_info_t curr = &dpl->curr_load[cpu - 1];
double total = 0;
/* Take the sums */
- for(size_t i = 0; i < CPU_STATE_MAX; ++i) {
+ for (size_t i = 0; i < CPU_STATE_MAX; ++i) {
total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i];
}
mtr->values[CPU_METER_NICE]
- = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total;
+ = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE]) * 100.0 / total;
mtr->values[CPU_METER_NORMAL]
- = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total;
+ = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER]) * 100.0 / total;
mtr->values[CPU_METER_KERNEL]
- = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total;
+ = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM]) * 100.0 / total;
- Meter_setItems(mtr, 3);
+ mtr->curItems = 3;
/* Convert to percent and return */
total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL];
- mtr->values[CPU_METER_FREQUENCY] = -1;
+ mtr->values[CPU_METER_FREQUENCY] = NAN;
+ mtr->values[CPU_METER_TEMPERATURE] = NAN;
return CLAMP(total, 0.0, 100.0);
}
void Platform_setMemoryValues(Meter* mtr) {
- DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
- vm_statistics_t vm = &dpl->vm_stats;
+ const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl;
+ const struct vm_statistics* vm = &dpl->vm_stats;
double page_K = (double)vm_page_size / (double)1024;
mtr->total = dpl->host_info.max_mem / 1024;
@@ -227,23 +254,23 @@ void Platform_setMemoryValues(Meter* mtr) {
}
void Platform_setSwapValues(Meter* mtr) {
- int mib[2] = {CTL_VM, VM_SWAPUSAGE};
- struct xsw_usage swapused;
- size_t swlen = sizeof(swapused);
- sysctl(mib, 2, &swapused, &swlen, NULL, 0);
+ int mib[2] = {CTL_VM, VM_SWAPUSAGE};
+ struct xsw_usage swapused;
+ size_t swlen = sizeof(swapused);
+ sysctl(mib, 2, &swapused, &swlen, NULL, 0);
- mtr->total = swapused.xsu_total / 1024;
- mtr->values[0] = swapused.xsu_used / 1024;
+ mtr->total = swapused.xsu_total / 1024;
+ mtr->values[0] = swapused.xsu_used / 1024;
}
void Platform_setZfsArcValues(Meter* this) {
- DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
+ const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl;
ZfsArcMeter_readStats(this, &(dpl->zfs));
}
void Platform_setZfsCompressedArcValues(Meter* this) {
- DarwinProcessList* dpl = (DarwinProcessList*) this->pl;
+ const DarwinProcessList* dpl = (const DarwinProcessList*) this->pl;
ZfsCompressedArcMeter_readStats(this, &(dpl->zfs));
}
@@ -263,33 +290,33 @@ char* Platform_getProcessEnv(pid_t pid) {
mib[0] = CTL_KERN;
mib[1] = KERN_PROCARGS2;
mib[2] = pid;
- size_t bufsz = argmax;
+ bufsz = argmax;
if (sysctl(mib, 3, buf, &bufsz, 0, 0) == 0) {
if (bufsz > sizeof(int)) {
char *p = buf, *endp = buf + bufsz;
- int argc = *(int*)p;
+ int argc = *(int*)(void*)p;
p += sizeof(int);
// skip exe
- p = strchr(p, 0)+1;
+ p = strchr(p, 0) + 1;
// skip padding
- while(!*p && p < endp)
+ while (!*p && p < endp)
++p;
// skip argv
- for (; argc-- && p < endp; p = strrchr(p, 0)+1)
+ for (; argc-- && p < endp; p = strrchr(p, 0) + 1)
;
// skip padding
- while(!*p && p < endp)
+ while (!*p && p < endp)
++p;
size_t size = endp - p;
- env = xMalloc(size+2);
+ env = xMalloc(size + 2);
memcpy(env, p, size);
env[size] = 0;
- env[size+1] = 0;
+ env[size + 1] = 0;
}
}
free(buf);
@@ -298,3 +325,96 @@ char* Platform_getProcessEnv(pid_t pid) {
return env;
}
+
+char* Platform_getInodeFilename(pid_t pid, ino_t inode) {
+ (void)pid;
+ (void)inode;
+ return NULL;
+}
+
+FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) {
+ (void)pid;
+ return NULL;
+}
+
+bool Platform_getDiskIO(DiskIOData* data) {
+ // TODO
+ (void)data;
+ return false;
+}
+
+bool Platform_getNetworkIO(unsigned long int* bytesReceived,
+ unsigned long int* packetsReceived,
+ unsigned long int* bytesTransmitted,
+ unsigned long int* packetsTransmitted) {
+ // TODO
+ *bytesReceived = 0;
+ *packetsReceived = 0;
+ *bytesTransmitted = 0;
+ *packetsTransmitted = 0;
+ return false;
+}
+
+void Platform_getBattery(double* percent, ACPresence* isOnAC) {
+ CFTypeRef power_sources = IOPSCopyPowerSourcesInfo();
+
+ *percent = NAN;
+ *isOnAC = AC_ERROR;
+
+ if (NULL == power_sources)
+ return;
+
+ CFArrayRef list = IOPSCopyPowerSourcesList(power_sources);
+ CFDictionaryRef battery = NULL;
+ int len;
+
+ if (NULL == list) {
+ CFRelease(power_sources);
+
+ return;
+ }
+
+ len = CFArrayGetCount(list);
+
+ /* Get the battery */
+ for (int i = 0; i < len && battery == NULL; ++i) {
+ CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources,
+ CFArrayGetValueAtIndex(list, i)); /* GET rule */
+ CFStringRef type;
+
+ if (NULL != candidate) {
+ type = (CFStringRef) CFDictionaryGetValue(candidate,
+ CFSTR(kIOPSTransportTypeKey)); /* GET rule */
+
+ if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) {
+ CFRetain(candidate);
+ battery = candidate;
+ }
+ }
+ }
+
+ if (NULL != battery) {
+ /* Determine the AC state */
+ CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey));
+
+ *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0))
+ ? AC_PRESENT
+ : AC_ABSENT;
+
+ /* Get the percentage remaining */
+ double current;
+ double max;
+
+ CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)),
+ kCFNumberDoubleType, &current);
+ CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)),
+ kCFNumberDoubleType, &max);
+
+ *percent = (current * 100.0) / max;
+
+ CFRelease(battery);
+ }
+
+ CFRelease(list);
+ CFRelease(power_sources);
+}

© 2014-2024 Faster IT GmbH | imprint | privacy policy