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 (time_t *time_stamp=NULL) const
 
int argc () const
 
char ** argv () const
 

Protected Attributes

int _argc
 
char ** _argv
 

Detailed Description

Definition at line 20 of file SystemInfo.h.

Constructor & Destructor Documentation

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

Definition at line 29 of file SystemInfo.C.

29 : _argc(argc), _argv(argv) {}
char ** _argv
Definition: SystemInfo.h:33
char ** argv() const
Definition: SystemInfo.h:29
int argc() const
Definition: SystemInfo.h:28

Member Function Documentation

int SystemInfo::argc ( ) const
inline

Definition at line 28 of file SystemInfo.h.

28 { return _argc; };
char** SystemInfo::argv ( ) const
inline

Definition at line 29 of file SystemInfo.h.

29 { return _argv; };
char ** _argv
Definition: SystemInfo.h:33
std::string SystemInfo::getInfo ( ) const

Definition at line 32 of file SystemInfo.C.

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

33 {
34  std::stringstream oss;
35  oss << std::left << "Framework Information:\n"
36  << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
37  << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
38 #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
39  oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
40  << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
41  << '\n';
42 #endif
43 
44  // Current Time
45  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";
46 
47  // Executable Timestamp
48  std::string executable(_argv[0]);
49  size_t last_slash = executable.find_last_of("/");
50  if (last_slash != std::string::npos)
51  executable = executable.substr(last_slash + 1);
52  std::string executable_path(Moose::getExecutablePath() + executable);
53  struct stat attrib;
54  stat(executable_path.c_str(), &attrib);
55  oss << std::setw(25) << "Executable Timestamp: " << getTimeStamp(&(attrib.st_mtime)) << "\n";
56 
57  oss << std::endl;
58  return oss.str();
59 }
std::string getExecutablePath()
This function returns the PATH of the running executable.
std::string getTimeStamp(time_t *time_stamp=NULL) const
Definition: SystemInfo.C:63
char ** _argv
Definition: SystemInfo.h:33
std::string SystemInfo::getTimeStamp ( time_t *  time_stamp = NULL) const

Definition at line 63 of file SystemInfo.C.

Referenced by getInfo().

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

Member Data Documentation

int SystemInfo::_argc
protected

Definition at line 29 of file SystemInfo.h.

Referenced by argc(), and argv().

char** SystemInfo::_argv
protected

Definition at line 33 of file SystemInfo.h.

Referenced by argv(), and getInfo().


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