LCOV - code coverage report
Current view: top level - src/utils - SystemInfo.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 40 41 97.6 %
Date: 2026-05-29 20:35:17 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "SystemInfo.h"
      11             : #include "ExecutablePath.h"
      12             : #include "CommandLine.h"
      13             : #include "MooseRevision.h" ///< This file is auto-generated and contains the revision
      14             : 
      15             : #include "libmesh/libmesh_config.h"
      16             : 
      17             : #include <sstream>
      18             : #include <sys/stat.h>
      19             : #include <iomanip>
      20             : #ifdef LIBMESH_HAVE_LOCALE
      21             : #include <locale>
      22             : #endif
      23             : 
      24             : #ifdef MOOSE_LIBTORCH_ENABLED
      25             : #include <torch/version.h>
      26             : #endif
      27             : 
      28             : std::string
      29       88328 : SystemInfo::getInfo() const
      30             : {
      31       88328 :   std::stringstream oss;
      32       88328 :   oss << std::left << "Framework Information:\n"
      33             :       << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
      34       88328 :       << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
      35             : #ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
      36       88328 :   oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
      37       88328 :       << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
      38       88328 :       << '\n';
      39             : #endif
      40             : #ifdef LIBMESH_DETECTED_SLEPC_VERSION_MAJOR
      41       88328 :   oss << std::setw(25) << "SLEPc Version: " << LIBMESH_DETECTED_SLEPC_VERSION_MAJOR << '.'
      42       88328 :       << LIBMESH_DETECTED_SLEPC_VERSION_MINOR << '.' << LIBMESH_DETECTED_SLEPC_VERSION_SUBMINOR
      43       88328 :       << '\n';
      44             : #endif
      45             : #ifdef MOOSE_LIBTORCH_ENABLED
      46        2521 :   oss << std::setw(25) << "Libtorch Version: " << TORCH_VERSION << '\n';
      47             : #endif
      48             : #ifdef MOOSE_MFEM_ENABLED
      49       66026 :   oss << std::setw(25) << "MFEM Version: " << MFEM_VERSION_STRING << '\n';
      50             : #endif
      51             : 
      52             :   // Current Time
      53       88328 :   oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";
      54             : 
      55             :   // Executable Timestamp
      56       88328 :   const std::string executable_time = getExecutableTimeStamp();
      57       88328 :   if (!executable_time.empty())
      58       88328 :     oss << std::setw(25) << "Executable Timestamp: " << executable_time << "\n";
      59             : 
      60       88328 :   oss << std::endl;
      61      176656 :   return oss.str();
      62       88328 : }
      63             : 
      64             : // TODO: Update libmesh to handle this function "timestamp.h"
      65             : std::string
      66      178114 : SystemInfo::getTimeStamp(std::time_t * time_stamp) const
      67             : {
      68             :   struct tm * tm_struct;
      69             :   std::time_t local_time;
      70             : 
      71             : #ifdef LIBMESH_HAVE_LOCALE
      72             :   // Create time_put "facet"
      73      178114 :   std::locale loc;
      74      178114 :   const std::time_put<char> & tp = std::use_facet<std::time_put<char>>(loc);
      75             : 
      76      178114 :   if (!time_stamp)
      77             :   {
      78             :     // Call C-style time getting functions
      79       89057 :     local_time = time(NULL);
      80       89057 :     time_stamp = &local_time;
      81             :   }
      82      178114 :   tm_struct = std::localtime(time_stamp);
      83             : 
      84             :   // Date will eventually be stored in this ostringstream's string
      85      178114 :   std::ostringstream date_stream;
      86             : 
      87             :   // See below for documentation on the use of the
      88             :   // std::time_put::put() function
      89      178114 :   tp.put(date_stream,        /*s*/
      90             :          date_stream,        /*str*/
      91      178114 :          date_stream.fill(), /*fill*/
      92             :          tm_struct,          /*tm*/
      93             :          'c');               /*format*/
      94             : 
      95             :   // Another way to use it is to totally customize the format...
      96             :   //    char pattern[]="%d %B %Y %I:%M:%S %p";
      97             :   //    tp.put(date_stream,                /*s*/
      98             :   //     date_stream,                /*str*/
      99             :   //     date_stream.fill(),         /*fill*/
     100             :   //     tm_struct,                  /*tm*/
     101             :   //     pattern,                    /*format begin*/
     102             :   //     pattern+sizeof(pattern)-1); /*format end  */
     103             : 
     104      356228 :   return date_stream.str();
     105             : #else
     106             :   // C-stye code originally found here:
     107             :   // http://people.sc.fsu.edu/~burkardt/cpp_src/timestamp/timestamp.C
     108             :   // Author: John Burkardt, 24 September 2003
     109             :   const unsigned int time_size = 40;
     110             :   char time_buffer[time_size];
     111             : 
     112             :   if (!time_stamp)
     113             :   {
     114             :     local_time = time(NULL);
     115             :     time_stamp = &local_time;
     116             :   }
     117             :   tm_struct = std::localtime(time_stamp);
     118             : 
     119             :   // No more than time_size characters will be placed into the array.  If the
     120             :   // total number of resulting characters, including the terminating
     121             :   // NUL character, is not more than time_size, strftime() returns the
     122             :   // number of characters in the array, not counting the terminating
     123             :   // NUL.  Otherwise, zero is returned and the buffer contents are
     124             :   // indeterminate.
     125             :   size_t len = strftime(time_buffer, time_size, "%c", tm_struct);
     126             : 
     127             :   if (len != 0)
     128             :     return std::string(time_buffer);
     129             :   else
     130             :   {
     131             :     libMesh::out << "Error formatting time buffer, returning empty string!" << std::endl;
     132             :     return std::string("");
     133             :   }
     134             : 
     135             : #endif // LIBMESH_HAVE_LOCALE
     136      178114 : }
     137             : 
     138             : std::string
     139       89057 : SystemInfo::getExecutable() const
     140             : {
     141       89057 :   return Moose::getExec();
     142             : }
     143             : 
     144             : std::string
     145       88328 : SystemInfo::getExecutableTimeStamp() const
     146             : {
     147       88328 :   const std::string exe = getExecutable();
     148      176656 :   return getExecutableTimeStamp(exe);
     149       88328 : }
     150             : 
     151             : std::string
     152       89057 : SystemInfo::getExecutableTimeStamp(const std::string & exe) const
     153             : {
     154             :   struct stat attrib;
     155       89057 :   if (!stat(exe.c_str(), &attrib))
     156       89057 :     return getTimeStamp(&(attrib.st_mtime));
     157           0 :   return "";
     158             : }

Generated by: LCOV version 1.14