9 #ifndef __libutilxx__sella__util__Process_H__
10 #define __libutilxx__sella__util__Process_H__
12 #include "../../common.h"
13 #include "ProcessException.h"
15 #include <sys/vtimes.h>
16 #include <sys/sysinfo.h>
26 IOPRIO_CLASS_NONE = 0,
32 #define IOPRIO_BE_NR (8)
35 IOPRIO_WHO_PROCESS = 1,
40 #define IOPRIO_CLASS_SHIFT (13)
41 #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
42 #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
43 #define IOPRIO_PRIO_DATA(mask) ((mask) & IOPRIO_PRIO_MASK)
44 #define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
56 Process()
throw (ProcessException);
59 void update(
void)
throw (ProcessException);
61 uint64_t getUpdateIntervalUsec(
void)
const throw ();
62 uint64_t getUpdateIntervalSec(
void)
const throw ();
64 uint64_t getStartTime(
void)
const throw ();
65 uint64_t getUptime(
void)
const throw ();
67 int getCPU(
bool scale =
false)
const throw ();
68 int getUserCPU(
bool scale =
false)
const throw ();
69 int getSystemCPU(
bool scale =
false)
const throw ();
71 int getMemory(
void)
const throw ();
73 char getState(
void)
const throw ();
74 uint64_t getFDs(
void)
const throw ();
75 uint64_t getFDSize(
void)
const throw ();
76 uint64_t getVMPeak(
void)
const throw ();
77 uint64_t getVMSize(
void)
const throw ();
78 uint64_t getLocked(
void)
const throw ();
79 uint64_t getRSSHighWaterMark(
void)
const throw ();
80 uint64_t getRSS(
void)
const throw ();
81 uint64_t getData(
void)
const throw ();
82 uint64_t getStack(
void)
const throw ();
83 uint64_t getEXE(
void)
const throw ();
84 uint64_t getLib(
void)
const throw ();
85 uint64_t getPTE(
void)
const throw ();
86 uint64_t getSwap(
void)
const throw ();
87 uint64_t getThreads(
void)
const throw ();
88 uint64_t getVoluntaryContextSwitch(
void)
const throw ();
89 uint64_t getNonVoluntaryContextSwitch(
void)
const throw ();
91 uint64_t getBytesRead(
void)
const throw ();
92 uint64_t getBytesWrite(
void)
const throw ();
93 uint64_t getReadSyscall(
void)
const throw ();
94 uint64_t getWriteSyscall(
void)
const throw ();
95 uint64_t getBytesReadStorage(
void)
const throw ();
96 uint64_t getBytesWriteStorage(
void)
const throw ();
97 int64_t getCancelledBytesWrite(
void)
const throw ();
98 uint64_t getBlockIOWait(
void)
const throw ();
100 int getClockTicks(
void)
const throw ();
101 int getProcessorCount(
void)
const throw ();
103 uint64_t getSystemUptime(
void)
const throw ();
104 uint64_t getSystemLoadAverage(
int min = 1)
const throw ();
105 uint64_t getSystemMemory(
void)
const throw ();
106 uint64_t getSystemFree(
void)
const throw ();
107 uint64_t getSystemShared(
void)
const throw ();
108 uint64_t getSystemBuffer(
void)
const throw ();
109 uint64_t getSystemSwap(
void)
const throw ();
110 uint64_t getSystemProcesses(
void)
const throw ();
111 uint64_t getSystemTotalHigh(
void)
const throw ();
112 uint64_t getSystemFreeHigh(
void)
const throw ();
113 uint64_t getSystemMemUnitSize(
void)
const throw ();
115 static std::string getBaseName(
void)
throw ();
116 static std::string getDirName(
void)
throw ();
117 static std::string getPath(
void)
throw ();
118 static void setName(
const std::string &name)
throw (ProcessException);
119 static std::string getName(
void)
throw (ProcessException);
120 static void setThreadName(pthread_t tid,
const std::string &name)
throw (ProcessException);
121 static std::string getThreadName(pthread_t tid)
throw (ProcessException);
122 static void setTitle(
const std::string &title)
throw (ProcessException);
123 static pid_t getPID(
void)
throw ();
124 static pid_t getParentPID(
void)
throw ();
125 static bool isRunning(pid_t pid)
throw ();
126 static uint64_t getStartTime(pid_t pid)
throw (ProcessException);
127 static uint64_t getBlockIOWait(pid_t pid)
throw (ProcessException);
129 static std::string runCommand(
const std::string &command)
throw (ProcessException);
130 static std::string stackTrace(
const std::string &executableFilename)
throw ();
132 static void setNice(
int niceness,
int which = IOPRIO_WHO_PGRP,
int who = 0)
throw (ProcessException);
133 static int getNice(
int which = IOPRIO_WHO_PGRP,
int who = 0)
throw (ProcessException);
136 static void setIONice(
int ioclass = IOPRIO_CLASS_BE,
int level = 7,
int which = IOPRIO_WHO_PGRP,
int who = 0)
throw (ProcessException);
137 static int getIONice(
int &ioclass,
int &level,
int which = IOPRIO_WHO_PROCESS,
int who = 0)
throw (ProcessException);
140 std::vector<uint64_t> stats, iostats;
141 int cpu, userCPU, sysCPU, ncpu, jiffies, fds;
142 struct timespec prev, last;
143 clock_t lastCPU, lastUserCPU, lastSysCPU;
146 void updateCPU(
void)
throw ();
147 void updateFDs(
void)
throw (ProcessException);
148 void updateStats(
void)
throw (ProcessException);
149 void updateIOStats(
void)
throw (ProcessException);