www.mooseframework.org
Public Member Functions | Protected Attributes | List of all members
SystemInfo Class Reference

#include <SystemInfo.h>

Public Member Functions

 SystemInfo (int argc, char *argv[])
 
std::string getInfo () const
 
std::string getTimeStamp (std::time_t *time_stamp=NULL) const
 
int argc () const
 
char ** argv () const
 

Protected Attributes

int _argc
 
char ** _argv
 

Detailed Description

Definition at line 15 of file SystemInfo.h.

Constructor & Destructor Documentation

◆ SystemInfo()

SystemInfo::SystemInfo ( int  argc,
char *  argv[] 
)

Definition at line 23 of file SystemInfo.C.

23 : _argc(argc), _argv(argv) {}

Member Function Documentation

◆ argc()

int SystemInfo::argc ( ) const
inline

Definition at line 23 of file SystemInfo.h.

23 { return _argc; };

◆ argv()

char** SystemInfo::argv ( ) const
inline

Definition at line 24 of file SystemInfo.h.

24 { return _argv; };

◆ getInfo()

std::string SystemInfo::getInfo ( ) const

Definition at line 26 of file SystemInfo.C.

27 {
28  std::stringstream oss;
29  oss << std::left << "\nFramework Information:\n"
30  << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
31  << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
32 #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
33  oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
34  << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
35  << '\n';
36 #endif
37 #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
38  oss << std::setw(25) << "SLEPc Version: " << LIBMESH_DETECTED_SLEPC_VERSION_MAJOR << '.'
39  << LIBMESH_DETECTED_SLEPC_VERSION_MINOR << '.' << LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR
40  << '\n';
41 #endif
42 
43  // Current Time
44  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";
45 
46  // Executable Timestamp
47  std::string executable(_argv[0]);
48  size_t last_slash = executable.find_last_of("/");
49  if (last_slash != std::string::npos)
50  executable = executable.substr(last_slash + 1);
51  std::string executable_path(Moose::getExecutablePath() + executable);
52  struct stat attrib;
53  if (!stat(executable_path.c_str(), &attrib))
54  oss << std::setw(25) << "Executable Timestamp: " << getTimeStamp(&(attrib.st_mtime)) << "\n";
55 
56  oss << std::endl;
57  return oss.str();
58 }

Referenced by ConsoleUtils::outputFrameworkInformation(), and ExodusFormatter::printInputFile().

◆ getTimeStamp()

std::string SystemInfo::getTimeStamp ( std::time_t *  time_stamp = NULL) const

Definition at line 62 of file SystemInfo.C.

63 {
64  struct tm * tm_struct;
65  std::time_t local_time;
66 
67 #ifdef LIBMESH_HAVE_LOCALE
68  // Create time_put "facet"
69  std::locale loc;
70  const std::time_put<char> & tp = std::use_facet<std::time_put<char>>(loc);
71 
72  if (!time_stamp)
73  {
74  // Call C-style time getting functions
75  local_time = time(NULL);
76  time_stamp = &local_time;
77  }
78  tm_struct = std::localtime(time_stamp);
79 
80  // Date will eventually be stored in this ostringstream's string
81  std::ostringstream date_stream;
82 
83  // See below for documentation on the use of the
84  // std::time_put::put() function
85  tp.put(date_stream, /*s*/
86  date_stream, /*str*/
87  date_stream.fill(), /*fill*/
88  tm_struct, /*tm*/
89  'c'); /*format*/
90 
91  // Another way to use it is to totally customize the format...
92  // char pattern[]="%d %B %Y %I:%M:%S %p";
93  // tp.put(date_stream, /*s*/
94  // date_stream, /*str*/
95  // date_stream.fill(), /*fill*/
96  // tm_struct, /*tm*/
97  // pattern, /*format begin*/
98  // pattern+sizeof(pattern)-1); /*format end */
99 
100  return date_stream.str();
101 #else
102  // C-stye code originally found here:
103  // http://people.sc.fsu.edu/~burkardt/cpp_src/timestamp/timestamp.C
104  // Author: John Burkardt, 24 September 2003
105  const unsigned int time_size = 40;
106  char time_buffer[time_size];
107 
108  if (!time_stamp)
109  {
110  local_time = time(NULL);
111  time_stamp = &local_time;
112  }
113  tm_struct = std::localtime(time_stamp);
114 
115  // No more than time_size characters will be placed into the array. If the
116  // total number of resulting characters, including the terminating
117  // NUL character, is not more than time_size, strftime() returns the
118  // number of characters in the array, not counting the terminating
119  // NUL. Otherwise, zero is returned and the buffer contents are
120  // indeterminate.
121  size_t len = strftime(time_buffer, time_size, "%c", tm_struct);
122 
123  if (len != 0)
124  return std::string(time_buffer);
125  else
126  {
127  libMesh::out << "Error formatting time buffer, returning empty string!" << std::endl;
128  return std::string("");
129  }
130 
131 #endif // LIBMESH_HAVE_LOCALE
132 }

Referenced by getInfo().

Member Data Documentation

◆ _argc

int SystemInfo::_argc
protected

Definition at line 24 of file SystemInfo.h.

Referenced by argc().

◆ _argv

char** SystemInfo::_argv
protected

Definition at line 28 of file SystemInfo.h.

Referenced by argv(), and getInfo().


The documentation for this class was generated from the following files:
SystemInfo::argv
char ** argv() const
Definition: SystemInfo.h:24
SystemInfo::argc
int argc() const
Definition: SystemInfo.h:23
SystemInfo::_argv
char ** _argv
Definition: SystemInfo.h:28
SystemInfo::_argc
int _argc
Definition: SystemInfo.h:24
SystemInfo::getTimeStamp
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:62
Moose::getExecutablePath
std::string getExecutablePath()
This function returns the PATH of the running executable.
Definition: ExecutablePath.C:24