www.mooseframework.org
SystemInfo.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "SystemInfo.h"
16 #include "ExecutablePath.h"
17 #include "MooseRevision.h"
18 
19 #include "libmesh/libmesh_config.h"
20 
21 #include <ctime>
22 #include <sstream>
23 #include <sys/stat.h>
24 #include <iomanip>
25 #ifdef LIBMESH_HAVE_LOCALE
26 #include <locale>
27 #endif
28 
29 SystemInfo::SystemInfo(int argc, char * argv[]) : _argc(argc), _argv(argv) {}
30 
31 std::string
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 }
60 
61 // TODO: Update libmesh to handle this function "timestamp.h"
62 std::string
63 SystemInfo::getTimeStamp(time_t * time_stamp) const
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 }
SystemInfo(int argc, char *argv[])
Definition: SystemInfo.C:29
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 getInfo() const
Definition: SystemInfo.C:32