18 struct zbuf : std::filebuf
20 void rewind() { std::filebuf::seekpos(0, std::ios_base::out); }
30int main(
int argc,
char **argv)
44 JParser<> zap(
"Auxiliary program to continually monitor processes.");
46 zap[
'P'] =
make_field(process,
"name of process");
48 zap[
'T'] =
make_field(T_us,
"interval time [us]") = 1000;
49 zap[
'n'] =
make_field(prescale,
"pre-scale for logging") = 1000;
50 zap[
'M'] =
make_field(master,
"stop when master does") =
"";
55 catch(
const exception &error) {
56 FATAL(error.what() << endl);
59 if (process.empty()) {
60 FATAL(
"No process." << endl);
68 os <<
"ps -o comm= -o pid=";
70 for (vector<string>::const_iterator i = process.begin(); i != process.end(); ++i) {
75 os <<
" -C " << master;
89 ostream os(
outputFile !=
"" ? &buffer : cout.rdbuf());
97 int monitor = (master !=
"" ? UNDEFINED : RUNNING);
99 const auto start = chrono::system_clock::now();
103 for (
long int count = 1;
monitor != STOPPED; usleep(T_us)) {
105 if (master !=
"" &&
monitor == RUNNING) {
111 for (
string buffer; shell.
getline(buffer); ) {
116 istringstream is(buffer);
118 if (is >> command >> pid) {
122 if (command == master) {
128 ERROR(
"Error reading \"" << buffer <<
"\"" << endl);
136 if (count%prescale == 0) {
140 os <<
"top " <<
FIXED(9,1) << chrono::duration<double>(chrono::system_clock::now() - start).count() <<
" [s]" << endl;
144 for (vector<string>::const_iterator i = process.begin(); i != process.end(); ++i) {
146 const long int value = top[*i];
148 os << setw(24) << left << *i <<
' ' <<
FIXED(5,3) << (double) value / (
double) count << endl;
153 os << setw(24) << left <<
"Total" <<
' ' <<
FIXED(5,3) << (double) total / (
double) count << endl;
std::ostream & rewind(std::ostream &out)
Rewind character.
General purpose messaging.
#define DEBUG(A)
Message macros.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
I/O formatting auxiliaries.
Shell interaction via I/O streams.
int main(int argc, char **argv)
Utility class to parse command line options.
The JShell clas can be used to interact with the shell via I/O streams.
bool getline(std::string &buffer, const char eol='\n')
Get line of text.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.