21 std::string hostName(buf);
23 hostName = hostName.substr(0,hostName.find(
"."));
31 outStream <<
"Hostname: " << platformInfo.
hostName << std::endl;
37 outStream <<
"Processors: " << platformInfo.
numProcessors << std::endl;
39 outStream <<
"Cores/Proc: " << platformInfo.
numCores << std::endl;
41 outStream <<
"Threads/Core: " << platformInfo.
numThreads << std::endl;
51 std::istringstream Istr(systemInfo);
54 while(std::getline(Istr,line)){
55 std::istringstream lineStream(line);
56 std::ostringstream keyWordStream;
59 while(lineStream && keyWord.empty()){
61 if(token.find(
":") != std::string::npos) {
62 keyWord = keyWordStream.str()+token;
64 keyWordStream << token <<
" ";
68 std::string valueWord;
69 std::getline(lineStream,valueWord);
70 std::istringstream wordStream(valueWord);
73 }
else if (keyWord ==
"Hostname:"){
75 }
else if (keyWord ==
"Machine:") {
77 }
else if (keyWord ==
"Core(s) per socket:") {
79 }
else if (keyWord ==
"Thread(s) per core:") {
81 }
else if (keyWord ==
"Socket(s):") {
83 }
else if (keyWord ==
"machdep.cpu.core_count:") {
85 }
else if (keyWord ==
"machdep.cpu.thread_count:") {
87 }
else if (keyWord ==
"hw.physicalcpu:"){
101 struct utsname sysInfo;
104 std::ostringstream outStream;
105 outStream <<
"Hostname: " << hostName << std::endl
106 <<
"OS: " << sysInfo.sysname << std::endl
107 <<
"Node: " << sysInfo.nodename << std::endl
108 <<
"Release: " << sysInfo.release << std::endl
109 <<
"Version: " << sysInfo.version << std::endl
110 <<
"Machine: " << sysInfo.machine << std::endl;
113 std::string commandString(
"sysctl -a hw | grep -v optional");
115 std::string commandString(
"lscpu");
117 sysInfoProcess.
Execute(commandString);
119 while(std::getline(sysInfoProcess,outLine))
120 outStream << outLine << std::endl;
122 std::ostringstream commandStream;
123 commandStream <<
"sysctl -a machdep.cpu | grep -v thermal | grep -v feature" 124 <<
" | grep -v mwait | grep -v arch_perf";
125 sysInfoProcess.
Execute(commandStream.str());
126 while(std::getline(sysInfoProcess,outLine))
127 outStream << outLine << std::endl;
129 return(outStream.str());
132 int Rename(
const std::string &source_file,
const std::string &target_file)
134 return(rename(source_file.c_str(),target_file.c_str()));
136 int SymLink(
const std::string &source,
const std::string &target)
138 return(symlink(source.c_str(),target.c_str()));
146 if(RemoveDir.size() != 0){
147 for(std::vector<std::string>::iterator it = RemoveDir.begin() ; it != RemoveDir.end(); ++it){
148 if(
Remove(fname +
"/" + *it) < 0)
153 return(rmdir(fname.c_str()));
157 return(unlink(fname.c_str()));
165 std::string format(
"[%m/%d/%y%%%X]: ");
166 strftime(timesbuf,64,format.c_str(),gmtime(&t_ptr));
167 std::string retval(timesbuf);
170 void SafeRemove(
const std::string &fname,
const std::string &ext)
175 unlink(fname.c_str());
178 std::string savename_base(fname+
"."+ext);
179 std::string savename(savename_base);
182 std::ostringstream Ostr;
183 Ostr << savename_base << n++;
184 savename.assign(Ostr.str());
186 rename(fname.c_str(),savename.c_str());
192 if(lstat(fname.c_str(),&fstat))
197 bool ISDIR(
const std::string &fname)
200 if(stat(fname.c_str(),&fstat))
202 if(S_ISDIR(fstat.st_mode))
210 if(lstat(fname.c_str(),&fstat))
212 if(S_ISLNK(fstat.st_mode))
219 return(mkdir(fname.c_str(),S_IRGRP | S_IXGRP | S_IRWXU));
226 size_t s = readlink(path.c_str(),buf,1024);
231 std::string::size_type
x = retVal.find_last_of(
"/");
232 if(x != std::string::npos)
244 std::cerr <<
"Directory::Error: Could not open " << path
245 <<
" as a directory." << std::endl;
254 Directory::operator
void* ()
256 return(_good ?
this : NULL);
278 if(!(_dir = opendir(path.c_str())))
282 struct dirent *entry;
284 while((entry = readdir(_dir)) != NULL){
285 if(std::string(entry->d_name) !=
"." && std::string(entry->d_name) !=
"..")
286 this->push_back(entry->d_name);
294 return(std::string(getcwd(buf,1024)));
299 return(chdir(path.c_str()));
306 std::string::size_type
x = pname.find(
"/");
307 if(x == std::string::npos)
309 return(pname.substr(pname.find_last_of(
"/")+1));
316 std::string tstub(stub);
318 char *name =
new char [tstub.length() + 1];
319 std::strcpy(name,tstub.c_str());
320 name[tstub.length()] =
'\0';
336 std::string tstub(stub);
338 char *name =
new char [tstub.length() + 1];
339 std::strcpy(name,tstub.c_str());
340 name[tstub.length()] =
'\0';
353 std::istringstream Istr(path);
355 while(std::getline(Istr,tok,
'/'))
369 std::vector<std::string> raw_env;
372 raw_env.push_back(
environ[i++]);
374 std::vector<std::string>::iterator rei = raw_env.begin();
375 while(rei != raw_env.end()){
376 unsigned int x = (*rei).find(
"=");
377 std::string var((*rei).substr(0,x));
378 std::string val((*rei).substr(x+1));
379 this->push_back(make_pair(var,val));
387 int retVal = setenv(var.c_str(),val.c_str(),(int)ow);
395 unsetenv(var.c_str());
412 Environment::const_iterator ei = this->begin();
413 while(ei != this->end()){
414 if((*ei).first == var)
415 return((*ei).second);
418 return(std::string(
""));
424 Environment::iterator ei = this->begin();
425 while(ei != this->end()){
426 if((*ei).first == var)
427 return((*ei).second);
430 empty_string.clear();
431 return(empty_string);
437 int retVal = putenv(envs);
456 std::vector< std::pair<std::string,std::string> >::const_iterator ei = env.begin();
457 while(ei != env.end()){
458 output << (*ei).first <<
" = " << (*ei).second << std::endl;
Directory(const std::string &s="")
bool ISDIR(const std::string &fname)
int Remove(const std::string &fname)
std::ostream & operator<<(std::ostream &outStream, const platform_info &platformInfo)
const std::string GetEnv(const std::string &) const
int ChDir(const std::string &path)
Defines MPI-specific parallel global and program classes.
const std::string StripDirs(const std::string &)
const std::string ResolveLink(const std::string &path)
int OpenTemp(std::string &stub)
void const size_t const size_t const size_t const double const double * x
std::string TempFileName(const std::string &stub)
bool ISLINK(const std::string &fname)
void SafeRemove(const std::string &fname, const std::string &ext)
int CreateDirectory(const std::string &fname)
int SymLink(const std::string &source, const std::string &target)
int SetEnv(const std::string &, const std::string &, bool)
bool FILEEXISTS(const std::string &fname)
int Rename(const std::string &source_file, const std::string &target_file)
const std::string Hostname(bool longname=false)
Unix System Tools interface.
virtual int Execute(const std::string &command)
Implementation of stream object for Unix file descriptors.
int open(const std::string &s="")
void UnSetEnv(const std::string &)
platform_info PlatformInfo(const std::string &systemInfo)
void TokenizePath(std::vector< std::string > rv, const std::string &path)