aboutsummaryrefslogtreecommitdiffstats
path: root/pcp
diff options
context:
space:
mode:
Diffstat (limited to 'pcp')
-rw-r--r--pcp/PCPProcess.c4
-rw-r--r--pcp/PCPProcessList.c31
-rw-r--r--pcp/Platform.c25
-rw-r--r--pcp/Platform.h5
4 files changed, 43 insertions, 22 deletions
diff --git a/pcp/PCPProcess.c b/pcp/PCPProcess.c
index a983a96..e686d51 100644
--- a/pcp/PCPProcess.c
+++ b/pcp/PCPProcess.c
@@ -53,11 +53,11 @@ const ProcessFieldData Process_fields[] = {
[M_DRS] = { .name = "M_DRS", .title = " DATA ", .description = "Size of the data segment plus stack usage of the process", .flags = 0, .defaultSortDesc = true, },
[M_LRS] = { .name = "M_LRS", .title = " LIB ", .description = "The library size of the process (unused since Linux 2.6; always 0)", .flags = 0, .defaultSortDesc = true, },
[M_DT] = { .name = "M_DT", .title = " DIRTY ", .description = "Size of the dirty pages of the process (unused since Linux 2.6; always 0)", .flags = 0, .defaultSortDesc = true, },
- [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", .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, .defaultSortDesc = true, },
[PERCENT_NORM_CPU] = { .name = "PERCENT_NORM_CPU", .title = "NCPU%", .description = "Normalized percentage of the CPU time the process used in the last sampling (normalized by cpu count)", .flags = 0, .defaultSortDesc = true, },
[PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", .flags = 0, .defaultSortDesc = true, },
- [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
+ [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, },
[TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, .defaultSortDesc = true, },
[NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, .defaultSortDesc = true, },
[TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, },
diff --git a/pcp/PCPProcessList.c b/pcp/PCPProcessList.c
index 554e43d..cae097f 100644
--- a/pcp/PCPProcessList.c
+++ b/pcp/PCPProcessList.c
@@ -142,10 +142,27 @@ static inline char Metric_instance_char(int metric, int pid, int offset, char fa
return fallback;
}
+static inline ProcessState PCPProcessList_getProcessState(char state) {
+ switch (state) {
+ case '?': return UNKNOWN;
+ case 'R': return RUNNING;
+ case 'W': return WAITING;
+ case 'D': return UNINTERRUPTIBLE_WAIT;
+ case 'P': return PAGING;
+ case 'T': return STOPPED;
+ case 't': return TRACED;
+ case 'Z': return ZOMBIE;
+ case 'X': return DEFUNCT;
+ case 'I': return IDLE;
+ case 'S': return SLEEPING;
+ default: return UNKNOWN;
+ }
+}
+
static void PCPProcessList_updateID(Process* process, int pid, int offset) {
process->tgid = Metric_instance_u32(PCP_PROC_TGID, pid, offset, 1);
process->ppid = Metric_instance_u32(PCP_PROC_PPID, pid, offset, 1);
- process->state = Metric_instance_char(PCP_PROC_STATE, pid, offset, '?');
+ process->state = PCPProcessList_getProcessState(Metric_instance_char(PCP_PROC_STATE, pid, offset, '?'));
}
static void PCPProcessList_updateInfo(Process* process, int pid, int offset, char* command, size_t commLen) {
@@ -283,7 +300,7 @@ static void PCPProcessList_updateUsername(Process* process, int pid, int offset,
static void PCPProcessList_updateCmdline(Process* process, int pid, int offset, const char* comm) {
pmAtomValue value;
if (!PCPMetric_instance(PCP_PROC_PSARGS, pid, offset, &value, PM_TYPE_STRING)) {
- if (process->state != 'Z')
+ if (process->state != ZOMBIE)
process->isKernelThread = true;
Process_updateCmdline(process, NULL, 0, 0);
return;
@@ -351,7 +368,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
if (preExisting && hideKernelThreads && Process_isKernelThread(proc)) {
proc->updated = true;
proc->show = false;
- if (proc->state == 'R')
+ if (proc->state == RUNNING)
pl->runningTasks++;
pl->kernelThreads++;
pl->totalTasks++;
@@ -360,7 +377,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
if (preExisting && hideUserlandThreads && Process_isUserlandThread(proc)) {
proc->updated = true;
proc->show = false;
- if (proc->state == 'R')
+ if (proc->state == RUNNING)
pl->runningTasks++;
pl->userlandThreads++;
pl->totalTasks++;
@@ -398,7 +415,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
PCPProcessList_updateCmdline(proc, pid, offset, command);
Process_fillStarttimeBuffer(proc);
ProcessList_add(pl, proc);
- } else if (settings->updateProcessNames && proc->state != 'Z') {
+ } else if (settings->updateProcessNames && proc->state != ZOMBIE) {
PCPProcessList_updateCmdline(proc, pid, offset, command);
}
@@ -420,7 +437,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
if (settings->flags & PROCESS_FLAG_LINUX_AUTOGROUP)
PCPProcessList_readAutogroup(pp, pid, offset);
- if (proc->state == 'Z' && !proc->cmdline && command[0]) {
+ if (proc->state == ZOMBIE && !proc->cmdline && command[0]) {
Process_updateCmdline(proc, command, 0, strlen(command));
} else if (Process_isThread(proc)) {
if ((settings->showThreadNames || Process_isKernelThread(proc)) && command[0]) {
@@ -439,7 +456,7 @@ static bool PCPProcessList_updateProcesses(PCPProcessList* this, double period,
(hideUserlandThreads && Process_isUserlandThread(proc)));
pl->totalTasks++;
- if (proc->state == 'R')
+ if (proc->state == RUNNING)
pl->runningTasks++;
proc->updated = true;
}
diff --git a/pcp/Platform.c b/pcp/Platform.c
index cd7b1f4..150660a 100644
--- a/pcp/Platform.c
+++ b/pcp/Platform.c
@@ -257,7 +257,7 @@ size_t Platform_addMetric(PCPMetric id, const char* name) {
/* global state from the environment and command line arguments */
pmOptions opts;
-void Platform_init(void) {
+bool Platform_init(void) {
const char* source;
if (opts.context == PM_CONTEXT_ARCHIVE) {
source = opts.archives[0];
@@ -277,12 +277,12 @@ void Platform_init(void) {
}
if (sts < 0) {
fprintf(stderr, "Cannot setup PCP metric source: %s\n", pmErrStr(sts));
- exit(1);
+ return false;
}
/* setup timezones and other general startup preparation completion */
if (pmGetContextOptions(sts, &opts) < 0 || opts.errors) {
pmflush();
- exit(1);
+ return false;
}
pcp = xCalloc(1, sizeof(Platform));
@@ -309,7 +309,8 @@ void Platform_init(void) {
sts = pmLookupName(pcp->totalMetrics, pcp->names, pcp->pmids);
if (sts < 0) {
fprintf(stderr, "Error: cannot lookup metric names: %s\n", pmErrStr(sts));
- exit(1);
+ Platform_done();
+ return false;
}
for (size_t i = 0; i < pcp->totalMetrics; i++) {
@@ -361,6 +362,8 @@ void Platform_init(void) {
Platform_getRelease(0);
Platform_getMaxCPU();
Platform_getMaxPid();
+
+ return true;
}
void Platform_dynamicColumnsDone(Hashtable* columns) {
@@ -697,16 +700,16 @@ void Platform_longOptionsUsage(ATTR_UNUSED const char* name) {
" --timezone=TZ set reporting timezone\n");
}
-bool Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
+CommandLineStatus Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
/* libpcp export without a header definition */
extern void __pmAddOptHost(pmOptions*, char*);
switch (opt) {
case PLATFORM_LONGOPT_HOST: /* --host=HOSTSPEC */
if (argv[optind][0] == '\0')
- return false;
+ return STATUS_ERROR_EXIT;
__pmAddOptHost(&opts, optarg);
- return true;
+ return STATUS_OK;
case PLATFORM_LONGOPT_HOSTZONE: /* --hostzone */
if (opts.timezone) {
@@ -715,23 +718,23 @@ bool Platform_getLongOption(int opt, ATTR_UNUSED int argc, char** argv) {
} else {
opts.tzflag = 1;
}
- return true;
+ return STATUS_OK;
case PLATFORM_LONGOPT_TIMEZONE: /* --timezone=TZ */
if (argv[optind][0] == '\0')
- return false;
+ return STATUS_ERROR_EXIT;
if (opts.tzflag) {
pmprintf("%s: at most one of -Z and -z allowed\n", pmGetProgname());
opts.errors++;
} else {
opts.timezone = optarg;
}
- return true;
+ return STATUS_OK;
default:
break;
}
- return false;
+ return STATUS_ERROR_EXIT;
}
void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
diff --git a/pcp/Platform.h b/pcp/Platform.h
index 37a8799..ad38cbb 100644
--- a/pcp/Platform.h
+++ b/pcp/Platform.h
@@ -34,6 +34,7 @@ in the source distribution for its full text.
#include "ProcessLocksScreen.h"
#include "RichString.h"
#include "SignalsPanel.h"
+#include "CommandLine.h"
#include "pcp/PCPDynamicColumn.h"
#include "pcp/PCPDynamicMeter.h"
@@ -67,7 +68,7 @@ extern const unsigned int Platform_numberOfSignals;
extern const MeterClass* const Platform_meterTypes[];
-void Platform_init(void);
+bool Platform_init(void);
void Platform_done(void);
@@ -126,7 +127,7 @@ enum {
void Platform_longOptionsUsage(const char* name);
-bool Platform_getLongOption(int opt, int argc, char** argv);
+CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv);
extern pmOptions opts;

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