mirror of https://github.com/xzeldon/htop.git
Reduce scope of local variables
This commit is contained in:
parent
ddda739cb2
commit
03f9a86918
|
@ -804,7 +804,6 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
|
||||||
struct nlattr* nlattr;
|
struct nlattr* nlattr;
|
||||||
struct taskstats stats;
|
struct taskstats stats;
|
||||||
int rem;
|
int rem;
|
||||||
unsigned long long int timeDelta;
|
|
||||||
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
LinuxProcess* lp = (LinuxProcess*) linuxProcess;
|
||||||
|
|
||||||
nlhdr = nlmsg_hdr(nlmsg);
|
nlhdr = nlmsg_hdr(nlmsg);
|
||||||
|
@ -817,7 +816,7 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
|
||||||
memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats));
|
memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats));
|
||||||
assert(lp->super.pid == (pid_t)stats.ac_pid);
|
assert(lp->super.pid == (pid_t)stats.ac_pid);
|
||||||
|
|
||||||
timeDelta = stats.ac_etime * 1000 - lp->delay_read_time;
|
unsigned long long int timeDelta = stats.ac_etime * 1000 - lp->delay_read_time;
|
||||||
#define BOUNDS(x) (isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x))
|
#define BOUNDS(x) (isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x))
|
||||||
#define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100)
|
#define DELTAPERC(x,y) BOUNDS((float) ((x) - (y)) / timeDelta * 100)
|
||||||
lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total);
|
lp->cpu_delay_percent = DELTAPERC(stats.cpu_delay_total, lp->cpu_delay_total);
|
||||||
|
|
|
@ -136,7 +136,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
||||||
|
|
||||||
char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
|
char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) {
|
||||||
char *s, **arg;
|
char *s, **arg;
|
||||||
size_t len = 0, n;
|
size_t len = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -160,7 +160,7 @@ char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
||||||
for (i = 0; arg[i] != NULL; i++) {
|
for (i = 0; arg[i] != NULL; i++) {
|
||||||
n = strlcat(s, arg[i], len);
|
size_t n = strlcat(s, arg[i], len);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
/* TODO: rename all basenameEnd to basenameLen, make size_t */
|
/* TODO: rename all basenameEnd to basenameLen, make size_t */
|
||||||
*basenameEnd = MINIMUM(n, len - 1);
|
*basenameEnd = MINIMUM(n, len - 1);
|
||||||
|
@ -188,23 +188,18 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) {
|
||||||
const Settings* settings = this->super.settings;
|
const Settings* settings = this->super.settings;
|
||||||
bool hideKernelThreads = settings->hideKernelThreads;
|
bool hideKernelThreads = settings->hideKernelThreads;
|
||||||
bool hideUserlandThreads = settings->hideUserlandThreads;
|
bool hideUserlandThreads = settings->hideUserlandThreads;
|
||||||
struct kinfo_proc* kproc;
|
|
||||||
bool preExisting;
|
|
||||||
Process* proc;
|
|
||||||
OpenBSDProcess* fp;
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
// use KERN_PROC_KTHREAD to also include kernel threads
|
// use KERN_PROC_KTHREAD to also include kernel threads
|
||||||
struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
|
struct kinfo_proc* kprocs = kvm_getprocs(this->kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count);
|
||||||
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
|
//struct kinfo_proc* kprocs = getprocs(KERN_PROC_ALL, 0, &count);
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
kproc = &kprocs[i];
|
struct kinfo_proc* kproc = &kprocs[i];
|
||||||
|
|
||||||
preExisting = false;
|
bool preExisting = false;
|
||||||
proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
|
Process* proc = ProcessList_getProcess(&this->super, kproc->p_pid, &preExisting, OpenBSDProcess_new);
|
||||||
fp = (OpenBSDProcess*) proc;
|
OpenBSDProcess* fp = (OpenBSDProcess*) proc;
|
||||||
|
|
||||||
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))
|
proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc))
|
||||||
|| (hideUserlandThreads && Process_isUserlandThread(proc)));
|
|| (hideUserlandThreads && Process_isUserlandThread(proc)));
|
||||||
|
|
|
@ -47,10 +47,10 @@ static void ZfsArcMeter_updateValues(Meter* this, char* buffer, int size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZfsArcMeter_display(const Object* cast, RichString* out) {
|
static void ZfsArcMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
|
||||||
const Meter* this = (const Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
|
|
||||||
if (this->values[5] > 0) {
|
if (this->values[5] > 0) {
|
||||||
|
char buffer[50];
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||||
Meter_humanUnit(buffer, this->values[5], 50);
|
Meter_humanUnit(buffer, this->values[5], 50);
|
||||||
|
|
|
@ -43,10 +43,10 @@ static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int si
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
|
static void ZfsCompressedArcMeter_display(const Object* cast, RichString* out) {
|
||||||
char buffer[50];
|
|
||||||
const Meter* this = (const Meter*)cast;
|
const Meter* this = (const Meter*)cast;
|
||||||
|
|
||||||
if (this->values[0] > 0) {
|
if (this->values[0] > 0) {
|
||||||
|
char buffer[50];
|
||||||
Meter_humanUnit(buffer, this->total, 50);
|
Meter_humanUnit(buffer, this->total, 50);
|
||||||
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
RichString_append(out, CRT_colors[METER_VALUE], buffer);
|
||||||
RichString_append(out, CRT_colors[METER_TEXT], " Uncompressed, ");
|
RichString_append(out, CRT_colors[METER_TEXT], " Uncompressed, ");
|
||||||
|
|
Loading…
Reference in New Issue