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 16 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:29
int argc() const
Definition: SystemInfo.h:24
char ** argv() const
Definition: SystemInfo.h:25

Member Function Documentation

◆ argc()

int SystemInfo::argc ( ) const
inline

Definition at line 24 of file SystemInfo.h.

24 { return _argc; };

◆ argv()

char** SystemInfo::argv ( ) const
inline

Definition at line 25 of file SystemInfo.h.

25 { return _argv; };
char ** _argv
Definition: SystemInfo.h:29

◆ 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 
38  // Current Time
39  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";
40 
41  // Executable Timestamp
42  std::string executable(_argv[0]);
43  size_t last_slash = executable.find_last_of("/");
44  if (last_slash != std::string::npos)
45  executable = executable.substr(last_slash + 1);
46  std::string executable_path(Moose::getExecutablePath() + executable);
47  struct stat attrib;
48  if (!stat(executable_path.c_str(), &attrib))
49  oss << std::setw(25) << "Executable Timestamp: " << getTimeStamp(&(attrib.st_mtime)) << "\n";
50 
51  oss << std::endl;
52  return oss.str();
53 }
std::string getExecutablePath()
This function returns the PATH of the running executable.
std::string getTimeStamp(std::time_t *time_stamp=NULL) const
Definition: SystemInfo.C:57
char ** _argv
Definition: SystemInfo.h:29

◆ getTimeStamp()

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

Definition at line 57 of file SystemInfo.C.

Referenced by getInfo().

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

Member Data Documentation

◆ _argc

int SystemInfo::_argc
protected

Definition at line 25 of file SystemInfo.h.

Referenced by argc().

◆ _argv

char** SystemInfo::_argv
protected

Definition at line 29 of file SystemInfo.h.

Referenced by argv(), and getInfo().


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