mirror of https://github.com/xzeldon/htop.git
Reading first bits of data!
This commit is contained in:
parent
8a2e235a48
commit
28712f22b1
|
@ -1,39 +1,81 @@
|
||||||
/*
|
/*
|
||||||
htop - UnsupportedProcessList.c
|
htop - FreeBSDProcessList.c
|
||||||
(C) 2014 Hisham H. Muhammad
|
(C) 2014 Hisham H. Muhammad
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
|
#include "FreeBSDProcessList.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
|
|
||||||
|
#include <kvm.h>
|
||||||
|
|
||||||
|
typedef struct FreeBSDProcessList_ {
|
||||||
|
ProcessList super;
|
||||||
|
kvm_t* kd;
|
||||||
|
} FreeBSDProcessList;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
static int MIB_vm_stats_vm_v_wire_count[4];
|
||||||
|
static int MIB_hw_physmem[2];
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList) {
|
||||||
ProcessList* this = calloc(1, sizeof(ProcessList));
|
FreeBSDProcessList* this = calloc(1, sizeof(FreeBSDProcessList));
|
||||||
ProcessList_init(this, usersTable, pidWhiteList);
|
ProcessList* pl = (ProcessList*) this;
|
||||||
|
ProcessList_init((ProcessList*)this, usersTable, pidWhiteList);
|
||||||
|
|
||||||
int cpus = 1;
|
int cpus = 1;
|
||||||
size_t sizeof_cpus = sizeof(cpus);
|
size_t sizeof_cpus = sizeof(cpus);
|
||||||
int err = sysctlbyname("hw.ncpu", &cpus, &sizeof_cpus, NULL, 0);
|
int err = sysctlbyname("hw.ncpu", &cpus, &sizeof_cpus, NULL, 0);
|
||||||
if (err) cpus = 1;
|
if (err) cpus = 1;
|
||||||
this->cpuCount = MAX(cpus, 1);
|
pl->cpuCount = MAX(cpus, 1);
|
||||||
this->cpus = realloc(this->cpus, cpus * sizeof(CPUData));
|
pl->cpus = realloc(pl->cpus, cpus * sizeof(CPUData));
|
||||||
|
|
||||||
for (int i = 0; i < cpus; i++) {
|
for (int i = 0; i < cpus; i++) {
|
||||||
this->cpus[i].totalTime = 1;
|
pl->cpus[i].totalTime = 1;
|
||||||
this->cpus[i].totalPeriod = 1;
|
pl->cpus[i].totalPeriod = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
size_t len = 4;
|
||||||
|
sysctlnametomib("vm.stats.vm.v_wire_count", MIB_vm_stats_vm_v_wire_count, &len);
|
||||||
|
len = 2;
|
||||||
|
sysctlnametomib("hw.physmem", MIB_hw_physmem, &len);
|
||||||
|
|
||||||
|
return (ProcessList*) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void FreeBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||||
|
const FreeBSDProcessList* fpl = (FreeBSDProcessList*) pl;
|
||||||
|
|
||||||
|
unsigned long long int swapFree = 0;
|
||||||
|
size_t len = sizeof(pl->totalMem);
|
||||||
|
sysctl(MIB_hw_physmem, 2, &(pl->totalMem), &len, NULL, 0);
|
||||||
|
pl->totalMem /= 1024;
|
||||||
|
sysctl(MIB_vm_stats_vm_v_wire_count, 4, &(pl->usedMem), &len, NULL, 0);
|
||||||
|
pl->usedMem *= PAGE_SIZE / 1024;
|
||||||
|
pl->freeMem = pl->totalMem - pl->usedMem;
|
||||||
|
|
||||||
|
pl->sharedMem = 0;
|
||||||
|
pl->buffersMem = 0;
|
||||||
|
pl->cachedMem = 0;
|
||||||
|
pl->totalSwap = 0;
|
||||||
|
swapFree = 0;
|
||||||
|
pl->usedSwap = pl->totalSwap - swapFree;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessList_scan(ProcessList* this) {
|
void ProcessList_scan(ProcessList* this) {
|
||||||
(void) this;
|
(void) this;
|
||||||
|
|
||||||
|
FreeBSDProcessList_scanMemoryInfo(this);
|
||||||
|
|
||||||
// stub!
|
// stub!
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,21 @@
|
||||||
#ifndef HEADER_FreeBSDProcessList
|
#ifndef HEADER_FreeBSDProcessList
|
||||||
#define HEADER_FreeBSDProcessList
|
#define HEADER_FreeBSDProcessList
|
||||||
/*
|
/*
|
||||||
htop - UnsupportedProcessList.h
|
htop - FreeBSDProcessList.h
|
||||||
(C) 2014 Hisham H. Muhammad
|
(C) 2014 Hisham H. Muhammad
|
||||||
Released under the GNU GPL, see the COPYING file
|
Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <kvm.h>
|
||||||
|
|
||||||
|
typedef struct FreeBSDProcessList_ {
|
||||||
|
ProcessList super;
|
||||||
|
kvm_t* kd;
|
||||||
|
} FreeBSDProcessList;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList);
|
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue