<commit_before>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "SystemInfo.h"
#include "ExecutablePath.h"
#include "MooseRevision.h" ///< This file is auto-generated and contains the revision

#include "libmesh/libmesh_config.h"

#include <ctime>
#include <sstream>
#include <sys/stat.h>
#include <iomanip>
#ifdef LIBMESH_HAVE_LOCALE
#include <locale>
#endif

SystemInfo::SystemInfo(int argc, char * argv[]) : _argc(argc), _argv(argv) {}

std::string
SystemInfo::getInfo() const
{
  std::stringstream oss;
  oss << std::left << "Framework Information:\n"
      << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
      << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
#ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
  oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
      << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
      << '\n';
#endif

  // Current Time
  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";

  // Executable Timestamp
  std::string executable(_argv[0]);
  size_t last_slash = executable.find_last_of("/");
  if (last_slash != std::string::npos)
    executable = executable.substr(last_slash + 1);
  std::string executable_path(Moose::getExecutablePath() + executable);
  struct stat attrib;
  stat(executable_path.c_str(), &attrib);
  oss << std::setw(25) << "Executable Timestamp: " << getTimeStamp(&(attrib.st_mtime)) << "\n";

  oss << std::endl;
  return oss.str();
}

// TODO: Update libmesh to handle this function "timestamp.h"
std::string
SystemInfo::getTimeStamp(time_t * time_stamp) const
{
  struct tm * tm_struct;
  time_t local_time;

#ifdef LIBMESH_HAVE_LOCALE
  // Create time_put "facet"
  std::locale loc;
  const std::time_put<char> & tp = std::use_facet<std::time_put<char>>(loc);

  if (!time_stamp)
  {
    // Call C-style time getting functions
    local_time = time(NULL);
    time_stamp = &local_time;
  }
  tm_struct = std::localtime(time_stamp);<commit_msg>Check return value of stat call (#10946)<commit_after>//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "SystemInfo.h"
#include "ExecutablePath.h"
#include "MooseRevision.h" ///< This file is auto-generated and contains the revision

#include "libmesh/libmesh_config.h"

#include <ctime>
#include <sstream>
#include <sys/stat.h>
#include <iomanip>
#ifdef LIBMESH_HAVE_LOCALE
#include <locale>
#endif

SystemInfo::SystemInfo(int argc, char * argv[]) : _argc(argc), _argv(argv) {}

std::string
SystemInfo::getInfo() const
{
  std::stringstream oss;
  oss << std::left << "Framework Information:\n"
      << std::setw(25) << "MOOSE Version: " << MOOSE_REVISION << '\n'
      << std::setw(25) << "LibMesh Version: " << LIBMESH_BUILD_VERSION << '\n';
#ifdef LIBMESH_DETECTED_PETSC_VERSION_MAJOR
  oss << std::setw(25) << "PETSc Version: " << LIBMESH_DETECTED_PETSC_VERSION_MAJOR << '.'
      << LIBMESH_DETECTED_PETSC_VERSION_MINOR << '.' << LIBMESH_DETECTED_PETSC_VERSION_SUBMINOR
      << '\n';
#endif

  // Current Time
  oss << std::setw(25) << "Current Time: " << getTimeStamp() << "\n";

  // Executable Timestamp
  std::string executable(_argv[0]);
  size_t last_slash = executable.find_last_of("/");
  if (last_slash != std::string::npos)
    executable = executable.substr(last_slash + 1);
  std::string executable_path(Moose::getExecutablePath() + executable);
  struct stat attrib;
  if (!stat(executable_path.c_str(), &attrib))
    oss << std::setw(25) << "Executable Timestamp: " << getTimeStamp(&(attrib.st_mtime)) << "\n";

  oss << std::endl;
  return oss.str();
}

// TODO: Update libmesh to handle this function "timestamp.h"
std::string
SystemInfo::getTimeStamp(time_t * time_stamp) const
{
  struct tm * tm_struct;
  time_t local_time;

#ifdef LIBMESH_HAVE_LOCALE
  // Create time_put "facet"
  std::locale loc;
  const std::time_put<char> & tp = std::use_facet<std::time_put<char>>(loc);

  if (!time_stamp)
  {
    // Call C-style time getting functions
    local_time = time(NULL);
    time_stamp = &local_time;
  }
  tm_struct = std::localtime(time_stamp);
{'fraction_non_alphanumeric': 0.16131105398457585, 'fraction_numerical': 0.007926306769494431, 'mean_word_length': 4.571599045346062, 'pattern_counts': {'":': 0, '<': 129, '<?xml version=': 0, '>': 19, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878062', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1678, 'n_words': 354}