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
 
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 23 of file SystemInfo.C.

23 : _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 131 of file SystemInfo.C.

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

132 {
133  std::string executable(_argv[0]);
134  size_t last_slash = executable.find_last_of("/");
135  if (last_slash != std::string::npos)
136  executable = executable.substr(last_slash + 1);
137  std::string exe(Moose::getExecutablePath() + executable);
138  return exe;
139 }
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 142 of file SystemInfo.C.

Referenced by getInfo(), and to_json().

143 {
144  const std::string exe = getExecutable();
145  return getExecutableTimeStamp(exe);
146 }
std::string getExecutable() const
Definition: SystemInfo.C:131
std::string getExecutableTimeStamp() const
Definition: SystemInfo.C:142

◆ getExecutableTimeStamp() [2/2]

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

Definition at line 149 of file SystemInfo.C.

150 {
151  struct stat attrib;
152  if (!stat(exe.c_str(), &attrib))
153  return getTimeStamp(&(attrib.st_mtime));
154  return "";
155 }
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:58

◆ getInfo()

std::string SystemInfo::getInfo ( ) const

Definition at line 26 of file SystemInfo.C.

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

27 {
28  std::stringstream oss;
29  oss << std::left << "Framework 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_path = getExecutable();
48  std::string executable_time = getExecutableTimeStamp(executable_path);
49  if (!executable_time.empty())
50  oss << std::setw(25) << "Executable Timestamp: " << executable_time << "\n";
51 
52  oss << std::endl;
53  return oss.str();
54 }
std::string getExecutable() const
Definition: SystemInfo.C:131
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:58
std::string getExecutableTimeStamp() const
Definition: SystemInfo.C:142

◆ getTimeStamp()

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

Definition at line 58 of file SystemInfo.C.

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

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