profilingSysInfo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "profilingSysInfo.H"
29 #include "foamVersion.H"
30 #include "clock.H"
31 #include "Ostream.H"
32 #include "OSspecific.H"
33 
34 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
35 
36 namespace
37 {
38 
39 // Write environment entry
40 inline void printEnv
41 (
43  const Foam::word& key,
44  const std::string& envName
45 )
46 {
47  const std::string value(Foam::getEnv(envName));
48  if (!value.empty())
49  {
50  os.writeEntry(key, value);
51  }
52 }
53 
54 } // End anonymous namespace
55 
56 
57 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
58 
59 void Foam::profilingSysInfo::writeEntries(Ostream& os) const
60 {
61  os.writeEntry("host", Foam::hostName()); // short name
62  os.writeEntry("date", Foam::clock::dateTime());
63 
64  // compile-time information
65  os.writeEntry("version", foamVersion::version);
66  os.writeEntry("build", foamVersion::build);
67 
68  printEnv(os, "arch", "WM_ARCH");
69  printEnv(os, "compilerType", "WM_COMPILER_TYPE");
70  printEnv(os, "compiler", "WM_COMPILER");
71  printEnv(os, "mplib", "WM_MPLIB");
72  printEnv(os, "options", "WM_OPTIONS");
73 }
74 
75 
76 void Foam::profilingSysInfo::writeEntry(const word& keyword, Ostream& os) const
77 {
78  os.beginBlock(keyword);
79  writeEntries(os);
80  os.endBlock();
81 }
82 
83 
84 // ************************************************************************* //
string getEnv(const std::string &envName)
Get environment value for given envName.
Definition: POSIX.C:339
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:108
static std::string dateTime()
The current wall-clock date/time (in local time) as a string in ISO-8601 format (yyyy-mm-ddThh:mm:ss)...
Definition: clock.C:53
void writeEntries(Ostream &os) const
Write system-info as dictionary entries.
void writeEntry(const word &keyword, Ostream &os) const
Write system-info as dictionary.
string hostName()
Return the system&#39;s host name, as per hostname(1)
Definition: POSIX.C:371
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
Definition: Ostream.C:90
const std::string build
OpenFOAM build information as a std::string.