24 #include <stk_util/util/FeatureTest.hpp> 25 #include <stk_util/diag/Env.hpp> 26 #include <stk_util/diag/Platform.hpp> 28 #include <stk_util/parallel/ExceptionReport.hpp> 29 #include <stk_util/parallel/MPI.hpp> 30 #ifdef STK_BUILT_IN_SIERRA 33 #include <stk_util/environment/ProductRegistry.hpp> 35 #include <stk_util/diag/Writer.hpp> 36 #include <stk_util/diag/SlibDiagWriter.hpp> 37 #include <stk_util/diag/Timer.hpp> 38 #include <stk_util/diag/Trace.hpp> 47 #include <sys/malloc.h> 51 #include <sys/resource.h> 52 #if __GNUC__ == 3 || __GNUC__ == 4 61 #include <sys/resource.h> 66 #include <sys/resource.h> 67 #include <sys/systeminfo.h> 68 #include <sys/utsname.h> 71 #elif defined(__SUNPRO_CC) 72 #include <sys/resource.h> 74 #include <sys/utsname.h> 78 #if defined(__PUMAGON__) 81 #include <sys/param.h> 86 #include <sys/resource.h> 89 #include <sys/param.h> 90 #include <sys/utsname.h> 92 #include <sys/resource.h> 94 #include <catamount/catmalloc.h> 95 extern void *__heap_start;
96 extern void *__heap_end;
99 #include <sys/param.h> 100 #include <sys/utsname.h> 101 #include <sys/time.h> 102 #include <sys/resource.h> 103 #include <sys/wait.h> 106 #elif defined(__IBMC__) || defined(__IBMCPP__) 107 #include <sys/utsname.h> 108 #include <sys/time.h> 109 #include <sys/resource.h> 113 #include <sys/utsname.h> 114 #include <sys/time.h> 118 #include <stk_util/util/MallocUsed.h> 128 size_t get_redstorm_base_available_memory();
134 #ifdef SIERRA_USE_PLATFORM_DEMANGLER 137 #if defined(__GNUC__) 156 char *demangled_symbol = abi::__cxa_demangle(symbol, 0, &len, &status);
158 if (demangled_symbol) {
159 s = std::string(demangled_symbol);
160 free(demangled_symbol);
164 s = std::string(symbol);
170 #elif (__GNUC__ == 4) 188 char *demangled_symbol = __cxxabiv1::__cxa_demangle(symbol, 0, &len, &status);
190 if (demangled_symbol) {
191 s = std::string(demangled_symbol);
192 free(demangled_symbol);
196 s = std::string(symbol);
201 #endif // (__GNUC__ == 3) 204 std::string
demangle(
const char *symbol) {
207 #endif // defined(__GNUC__) 213 #endif // SIERRA_USE_PLATFORM_DEMANGLER 223 static char redstorm_cout_buf[32678];
224 std::cout.rdbuf()->pubsetbuf(redstorm_cout_buf,
sizeof(redstorm_cout_buf));
226 static char redstorm_stdout_buf[32678];
227 std::setvbuf(stdout, redstorm_stdout_buf, _IOFBF,
sizeof(redstorm_stdout_buf));
229 static char redstorm_cerr_buf[32678];
230 std::cerr.rdbuf()->pubsetbuf(redstorm_cerr_buf,
sizeof(redstorm_cerr_buf));
232 static char redstorm_stderr_buf[32678];
233 std::setvbuf(stderr, redstorm_stderr_buf, _IOFBF,
sizeof(redstorm_stderr_buf));
243 std::locale loc(
"POSIX");
245 std::locale::global(loc);
246 std::cout.imbue(loc);
249 std::ostringstream strout;
250 strout <<
"Don't ask why the IBM locale works if I do this " << 10000000 << std::endl;
265 gettimeofday(&tp, &tz);
266 return (tp.tv_sec + (((
double)(tp.tv_usec))/1000000.0));
274 struct rusage my_rusage;
276 getrusage(RUSAGE_SELF, &my_rusage);
278 return (
double) (my_rusage.ru_utime.tv_sec)
279 + ((
double)(my_rusage.ru_utime.tv_usec))*1.0e-6;
281 #elif ! defined(__PGI) 282 struct rusage my_rusage;
284 getrusage(RUSAGE_SELF, &my_rusage);
286 return (
double) (my_rusage.ru_utime.tv_sec + my_rusage.ru_stime.tv_sec)
287 + ((
double)(my_rusage.ru_utime.tv_usec + my_rusage.ru_stime.tv_usec))*1.0e-6;
297 size_t & largest_free)
302 #if defined(SIERRA_HEAP_INFO) 304 # if defined(SIERRA_PTMALLOC3_ALLOCATOR) || defined(SIERRA_PTMALLOC2_ALLOCATOR) 305 heap_size = malloc_used();
307 # elif 0 // if defined(REDS) // Redstorm now links in gnu's malloc 308 static size_t reds_fragments;
309 static unsigned long reds_total_free;
310 static unsigned long reds_heap_size;
311 static unsigned long reds_largest_free;
313 ::heap_info(&reds_fragments, &reds_total_free, &reds_largest_free, &reds_heap_size);
315 heap_size = reds_heap_size;
316 largest_free = reds_largest_free;
318 slibout.m(Slib::LOG_MEMORY) <<
"reds_fragments " << reds_fragments
319 <<
", reds_total_free " << reds_total_free
320 <<
", reds_largest_free " << reds_largest_free
321 <<
", reds_heap_size " << reds_heap_size <<
Diag::dendl;
323 # elif ( defined(__linux__) || defined(REDS) ) && ! defined(__IBMCPP__) 324 static struct mallinfo minfo;
326 heap_size = (
unsigned int) minfo.uordblks + (
unsigned int) minfo.hblkhd;
327 largest_free = (
unsigned int) minfo.fordblks;
329 slibout.m(Slib::LOG_MEMORY) <<
"size_t size " <<
sizeof(size_t)*8 <<
" bits" 330 <<
", heap size " << heap_size
331 <<
", arena " << (
unsigned int) minfo.arena
332 <<
", ordblks " << minfo.ordblks
333 <<
", smblks " << minfo.smblks
334 <<
", hblks " << minfo.hblks
335 <<
", hblkhd " << (
unsigned int) minfo.hblkhd
336 <<
", usmblks " << minfo.usmblks
337 <<
", fsmblks " << minfo.fsmblks
338 <<
", uordblks " << (
unsigned int) minfo.uordblks
339 <<
", fordblks " << (
unsigned int) minfo.fordblks
343 # elif defined(__sun)
344 pstatus_t proc_status;
346 std::ifstream proc(
"/proc/self/status", std::ios_base::in|std::ios_base::binary);
348 proc.read((
char *)&proc_status,
sizeof(proc_status));
349 heap_size = proc_status.pr_brksize;
350 slibout.m(Slib::LOG_MEMORY) <<
"pr_brksize " << proc_status.pr_brksize
351 <<
", pr_stksize " << proc_status.pr_stksize <<
Diag::dendl;
354 #endif // defined(SIERRA_HEAP_INFO) 364 #if !defined(__APPLE__) && !defined(__FreeBSD__) 365 static size_t pagesize = getpagesize();
366 size_t avail = sysconf(_SC_AVPHYS_PAGES);
367 return avail * pagesize;
377 static size_t initial_memory_size = 0;
378 if (initial_memory_size == 0) {
379 initial_memory_size = get_redstorm_base_available_memory();
387 size_t & memory_usage,
393 #if defined(SIERRA_MEMORY_INFO) 397 # elif defined(__linux__) 398 std::ifstream proc(
"/proc/self/stat", std::ios_base::in|std::ios_base::binary);
403 for (i = 0; i < 11; ++i)
412 proc >> memory_usage;
415 # elif defined(__sun) 420 std::ifstream proc(
"/proc/self/psinfo", std::ios_base::in|std::ios_base::binary);
422 proc.read((
char *)&proc_info,
sizeof(proc_info));
423 memory_usage = proc_info.pr_size*1024;
428 prusage_t proc_usage;
430 std::ifstream proc(
"/proc/self/usage", std::ios_base::in|std::ios_base::binary);
432 proc.read((
char *)&proc_usage,
sizeof(proc_usage));
433 faults = proc_usage.pr_majf;
437 #endif // defined(SIERRA_MEMORY_INFO) 449 return (
double) memory_usage;
457 ::gethostname(buf,
sizeof(buf));
458 return std::string(buf);
465 #if defined(__PUMAGON__) || defined(REDS) 466 return std::string(
".sandia.gov");
469 std::string domain(
".");
472 ::sysinfo(SI_SRPC_DOMAIN, buf,
sizeof(buf));
473 if (std::strlen(buf)) {
478 #else //#elif defined(__linux) || defined(__sgi) || defined(_AIX) 479 std::string domain(
".");
482 ::getdomainname(buf,
sizeof(buf));
495 #if defined(REDS) || defined(__CRAYXT_COMPUTE_LINUX_TARGET) 501 struct passwd *user_info = ::getpwuid(::geteuid());
503 return (user_info ? user_info->pw_name :
"unknown");
512 struct utsname uts_name;
516 return uts_name.machine;
528 struct utsname uts_name;
532 return uts_name.sysname;
544 struct utsname uts_name;
548 return uts_name.release;
566 #if defined(__PUMAGON__) || defined(REDS) 576 const std::string & name,
580 return !name.empty() && ::access(name.c_str(), mode) == 0;
586 const std::string & name)
594 const std::string & name)
602 const std::string & name)
616 static struct flock ret;
619 ret.l_whence = whence;
631 int i =::fcntl(fd, F_SETLK, file_lock(F_WRLCK, SEEK_SET));
643 int i =::fcntl(fd, F_SETLK, file_lock(F_UNLCK, SEEK_SET));
655 return ::fcntl(fd, F_SETLK, file_lock(F_RDLCK, SEEK_SET)) != -1;
663 return ::fcntl(fd, F_SETLK, file_lock(F_WRLCK, SEEK_END)) != -1;
671 #if defined(__GNUC__) 673 size_t get_redstorm_base_available_memory()
680 #include <catamount/data.h> 683 void stk_ptr (
unsigned long *sp) {
684 asm (
"movq %rsp, (%rdi)");
687 size_t get_redstorm_base_available_memory()
695 size_t unmapped_top = 4 * 1048576;
696 size_t os_foot = 140 * 1048576;
703 stk_ptr (&stack_top);
708 stack_top &= ~0x1fffff;
709 stack_top += 0x200000;
716 avail_mem = stack_top + unmapped_top;
721 avail_mem -= os_foot;
727 avail_mem /= _my_pcb->upcb_vnm_degree;
733 p1 = (
char *) malloc (1);
734 heap_base = (size_t) p1;
742 avail_heap = avail_mem - heap_base;
748 stack_base = (size_t) _my_pcb;
749 stack_base &= ~0x1fffff;
750 stack_base += 0x400000;
757 stack_size = stack_top - stack_base;
758 avail_heap -= unmapped_top;
759 avail_heap -= stack_size;
size_t get_available_memory()
Function get_available_memory returns an estimation of the amount of memory available to the process...
double cpu_now()
Member function cpu_now returns the accumlated cpu time for the process as a double precision value i...
std::string osversion()
Function osversion returns the hardware type of the host running the application. ...
double wall_now()
Member function wall_now returns the epoch as a double precision value in seconds to "millisecond" ac...
int pid()
Function pid returns the process id of the process running the application.
void get_memory_info(size_t &memory_usage, size_t &faults)
Function get_memory_info returns the total memory usage of the process and the number of page faults ...
bool path_write_access(const std::string &name)
Function path_write_access returns true if the process has write access to the path.
const char * demangle(const char *symbol)
Function demangle returns the demangled C++ symbol from the mangled C++ symbol. The mangled named is ...
void startup_preparallel_platform()
Function startup_preparallel_platform ...
bool release_lock(int fd)
Function release_lock returns true if the process was able to release a lock previously palced on the...
void get_heap_info(size_t &heap_size, size_t &largest_free)
Member function get_heap_info returns the amount of heap memory used in bytes and the largest free bl...
bool write_lock(int fd)
Function write_lock returns true if the process was able to place an exclusive lock on the specified ...
size_t get_heap_usage()
Function get_heap_usage returns the number of bytes used by the heap.
bool append_lock(int fd)
Function append_lock returns true if the process was able to place an exclusive lock on the end of th...
double vm_now()
Member function vm_now returns the virtual memory in use for the process as a double precision value ...
bool path_access(const std::string &name, int mode)
Function path_access returns true if the process has permission to access path with the specified mod...
Writer & dendl(Writer &dout)
Writer function dendl calls the Writer::dendl manipulator.
std::string hardware()
Function hardware returns the hardware type of the host running the application.
std::string domainname()
Function domainname returns the domainname of the domain running the application. ...
bool read_lock(int fd)
Function read_lock returns true if the process was able to place a shared lock on the specified file ...
bool path_exists(const std::string &name)
Function path_exists returns true if the path exists.
const std::string & get_param(const char *const option)
Function query_env_param searches the command line options for the specified option. If not found, a const reference to an empty string is returned.
std::string username()
Function username returns the username of the user running the application.
bool path_read_access(const std::string &name)
Function path_read_access returns true if the process has read access to the path.
int pgrp()
Function pgrp returns the process group id of the process running the application.
std::string osname()
Function osname returns the operating system nameof the host running the application.
std::string hostname()
Function hostname returns the hostname of the host running the application.