https://mooseframework.inl.gov
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
 
std::string getExecutable () const
 
std::string getExecutableTimeStamp () const
 
std::string getExecutableTimeStamp (const std::string &exe) 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 27 of file SystemInfo.C.

27 : _argc(argc), _argv(argv) {}
char ** _argv
Definition: SystemInfo.h:31
int argc() const
Definition: SystemInfo.h:26
char ** argv() const
Definition: SystemInfo.h:27

Member Function Documentation

◆ argc()

int SystemInfo::argc ( ) const
inline

Definition at line 26 of file SystemInfo.h.

26 { return _argc; };

◆ argv()

char** SystemInfo::argv ( ) const
inline

Definition at line 27 of file SystemInfo.h.

27 { return _argv; };
char ** _argv
Definition: SystemInfo.h:31

◆ getExecutable()

std::string SystemInfo::getExecutable ( ) const

Definition at line 138 of file SystemInfo.C.

Referenced by getExecutableTimeStamp(), getInfo(), and to_json().

139 {
140  std::string executable(_argv[0]);
141  size_t last_slash = executable.find_last_of("/");
142  if (last_slash != std::string::npos)
143  executable = executable.substr(last_slash + 1);
144  std::string exe(Moose::getExecutablePath() + executable);
145  return exe;
146 }
std::string getExecutablePath()
This function returns the PATH of the running executable.
char ** _argv
Definition: SystemInfo.h:31

◆ getExecutableTimeStamp() [1/2]

std::string SystemInfo::getExecutableTimeStamp ( ) const

Definition at line 149 of file SystemInfo.C.

Referenced by getInfo(), and to_json().

150 {
151  const std::string exe = getExecutable();
152  return getExecutableTimeStamp(exe);
153 }
std::string getExecutable() const
Definition: SystemInfo.C:138
std::string getExecutableTimeStamp() const
Definition: SystemInfo.C:149

◆ getExecutableTimeStamp() [2/2]

std::string SystemInfo::getExecutableTimeStamp ( const std::string &  exe) const

Definition at line 156 of file SystemInfo.C.

157 {
158  struct stat attrib;
159  if (!stat(exe.c_str(), &attrib))
160  return getTimeStamp(&(attrib.st_mtime));
161  return "";
162 }
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:65

◆ getInfo()

std::string SystemInfo::getInfo ( ) const

Definition at line 30 of file SystemInfo.C.

Referenced by ConsoleUtils::outputFrameworkInformation().

31 {
32  std::stringstream oss;
33  oss << std::left << "Framework Information:\n"
34  << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
35  << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
36 #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
37  oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
38  << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
39  << '\n';
40 #endif
41 #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
42  oss << std::setw(25) << "SLEPc Version: " << LIBMESH_DETECTED_SLEPC_VERSION_MAJOR << '.'
43  << LIBMESH_DETECTED_SLEPC_VERSION_MINOR << '.' << LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR
44  << '\n';
45 #endif
46 #ifdef MOOSE_LIBTORCH_ENABLED
47  oss << std::setw(25) << "Libtorch Version: " << TORCH_VERSION << '\n';
48 #endif
49 
50  // Current Time
51  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";
52 
53  // Executable Timestamp
54  std::string executable_path = getExecutable();
55  std::string executable_time = getExecutableTimeStamp(executable_path);
56  if (!executable_time.empty())
57  oss << std::setw(25) << "Executable Timestamp: " << executable_time << "\n";
58 
59  oss << std::endl;
60  return oss.str();
61 }
std::string getExecutable() const
Definition: SystemInfo.C:138
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:65
std::string getExecutableTimeStamp() const
Definition: SystemInfo.C:149

◆ getTimeStamp()

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

Definition at line 65 of file SystemInfo.C.

Referenced by getExecutableTimeStamp(), getInfo(), and to_json().

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

Member Data Documentation

◆ _argc

int SystemInfo::_argc
protected

Definition at line 27 of file SystemInfo.h.

Referenced by argc().

◆ _argv

char** SystemInfo::_argv
protected

Definition at line 31 of file SystemInfo.h.

Referenced by argv(), and getExecutable().


The documentation for this class was generated from the following files: