diff --git a/applications/test/HashTable4/Make/files b/applications/test/HashTable4/Make/files index fcc01c49bd..d915fa3711 100644 --- a/applications/test/HashTable4/Make/files +++ b/applications/test/HashTable4/Make/files @@ -1,3 +1,3 @@ -Test-HashTable4.C +Test-HashTable4.cxx EXE = $(FOAM_USER_APPBIN)/Test-HashTable4 diff --git a/applications/test/HashTable4/Test-HashTable4.C b/applications/test/HashTable4/Test-HashTable4.cxx similarity index 99% rename from applications/test/HashTable4/Test-HashTable4.C rename to applications/test/HashTable4/Test-HashTable4.cxx index 76f9712536..e474436870 100644 --- a/applications/test/HashTable4/Test-HashTable4.C +++ b/applications/test/HashTable4/Test-HashTable4.cxx @@ -159,7 +159,6 @@ int main(int argc, char *argv[]) cpuTime timer; - memInfo mem; Info<< "insert " << nElem << " (int) elements"; if (optFnd) @@ -306,7 +305,8 @@ int main(int argc, char *argv[]) } Info<< timer.cpuTimeIncrement() << " s\n"; - Info<< "mem info: " << mem.update() << endl; + Foam::memInfo{}.writeEntry("mem-info", Info); + Info<< endl; return 0; } diff --git a/applications/test/cpuInfo/Make/files b/applications/test/cpuInfo/Make/files index f9302d8ef2..fd5038696f 100644 --- a/applications/test/cpuInfo/Make/files +++ b/applications/test/cpuInfo/Make/files @@ -1,3 +1,3 @@ -Test-cpuInfo.C +Test-cpuInfo.cxx EXE = $(FOAM_USER_APPBIN)/Test-cpuInfo diff --git a/applications/test/cpuInfo/Test-cpuInfo.C b/applications/test/cpuInfo/Test-cpuInfo.cxx similarity index 94% rename from applications/test/cpuInfo/Test-cpuInfo.C rename to applications/test/cpuInfo/Test-cpuInfo.cxx index 148d075dfb..85fff8e463 100644 --- a/applications/test/cpuInfo/Test-cpuInfo.C +++ b/applications/test/cpuInfo/Test-cpuInfo.cxx @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +39,7 @@ using namespace Foam; int main(int argc, char *argv[]) { - cpuInfo().write(Info); + Foam::cpuInfo{}.writeEntry("cpu-info", Info); Info<< endl; return 0; diff --git a/applications/test/memInfo/Make/files b/applications/test/memInfo/Make/files index 1c9d3fff8e..27f9f01973 100644 --- a/applications/test/memInfo/Make/files +++ b/applications/test/memInfo/Make/files @@ -1,3 +1,3 @@ -Test-memInfo.C +Test-memInfo.cxx EXE = $(FOAM_USER_APPBIN)/Test-memInfo diff --git a/applications/test/memInfo/Test-memInfo.C b/applications/test/memInfo/Test-memInfo.cxx similarity index 86% rename from applications/test/memInfo/Test-memInfo.C rename to applications/test/memInfo/Test-memInfo.cxx index 6ecd355104..9807652464 100644 --- a/applications/test/memInfo/Test-memInfo.C +++ b/applications/test/memInfo/Test-memInfo.cxx @@ -47,14 +47,18 @@ int main(int argc, char *argv[]) memInfo mem; Info<< memTags << mem << endl; - List lst(n, vector::one); - Info<< "allocate " << n << " vectors" << nl - << memTags << mem.update() << endl; + List list(n, vector::one); - lst.clear(); - Info<< "clear" << nl - << memTags << mem.update() << endl; + Info<< "allocate " << n << " vectors" << nl; + Info<< memTags << mem.update() << endl; + + list.clear(); + Info<< "clear" << nl; + Info<< memTags << mem.update() << endl; + + mem.writeEntry("memory", Info); + Info<< endl; return 0; } diff --git a/applications/test/sysInfo/Make/files b/applications/test/sysInfo/Make/files index 7406672887..8805fa99a3 100644 --- a/applications/test/sysInfo/Make/files +++ b/applications/test/sysInfo/Make/files @@ -1,3 +1,3 @@ -Test-sysInfo.C +Test-sysInfo.cxx EXE = $(FOAM_USER_APPBIN)/Test-sysInfo diff --git a/applications/test/sysInfo/Test-sysInfo.C b/applications/test/sysInfo/Test-sysInfo.cxx similarity index 95% rename from applications/test/sysInfo/Test-sysInfo.C rename to applications/test/sysInfo/Test-sysInfo.cxx index f4aa4c6633..cf912341f7 100644 --- a/applications/test/sysInfo/Test-sysInfo.C +++ b/applications/test/sysInfo/Test-sysInfo.cxx @@ -43,9 +43,8 @@ using namespace Foam; int main(int argc, char *argv[]) { - profilingSysInfo().write(Info); - - cpuInfo().write(Info); + profilingSysInfo{}.writeEntry("sys-info", Info); + Foam::cpuInfo{}.writeEntry("cpu-info", Info); #ifdef WM_BIG_ENDIAN Info diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H index d81f6f33a4..4ec6f2a679 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.H @@ -64,7 +64,6 @@ SourceFiles #include "fvMesh.H" #include "labelPair.H" #include "HashSet.H" -#include "memInfo.H" #include "point.H" #include "cellSet.H" #include "wallPolyPatch.H" diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C index 7f4ddccb0f..03f37ea67d 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshIO.C @@ -38,6 +38,7 @@ License #include "indexedVertexOps.H" #include "DelaunayMeshTools.H" #include "syncTools.H" +#include "memInfo.H" #include "faceSet.H" #include "OBJstream.H" diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C index 6f0cdc0dfc..d47e941ee0 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C +++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/foamToEnsight.C @@ -463,8 +463,7 @@ int main(int argc, char *argv[]) // ------------------------------------------------------------------------ cpuTime timer; - memInfo mem; - Info<< "Initial memory " << mem.update().size() << " kB" << endl; + Info<< "Initial memory " << Foam::memInfo{}.size() << " kB" << endl; #include "createNamedMeshes.H" #include "createMeshAccounting.H" @@ -496,7 +495,7 @@ int main(int argc, char *argv[]) Info<< "Startup in " << timer.cpuTimeIncrement() << " s, " - << mem.update().size() << " kB" << nl << endl; + << Foam::memInfo{}.size() << " kB" << nl << endl; forAll(timeDirs, timei) @@ -587,7 +586,7 @@ int main(int argc, char *argv[]) Info<< "Wrote in " << timer.cpuTimeIncrement() << " s, " - << mem.update().size() << " kB" << nl << nl; + << Foam::memInfo{}.size() << " kB" << nl << nl; } // Write cases @@ -606,7 +605,7 @@ int main(int argc, char *argv[]) Info<< "\nEnd: " << timer.elapsedCpuTime() << " s, " - << mem.update().peak() << " kB (peak)" << nl << endl; + << Foam::memInfo{}.peak() << " kB (peak)" << nl << endl; return 0; } diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C index 15cbd5ecff..3d69fd3595 100644 --- a/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C +++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/foamToVTK.C @@ -712,15 +712,14 @@ int main(int argc, char *argv[]) // ------------------------------------------------------------------------ cpuTime timer; - memInfo mem; - Info<< "Initial memory " << mem.update().size() << " kB" << endl; + Info<< "Initial memory " << Foam::memInfo{}.size() << " kB" << endl; #include "createNamedMeshes.H" #include "createMeshAccounting.H" Info<< "VTK mesh topology: " << timer.cpuTimeIncrement() << " s, " - << mem.update().size() << " kB" << endl; + << Foam::memInfo{}.size() << " kB" << endl; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -860,13 +859,13 @@ int main(int argc, char *argv[]) Info<< "Wrote in " << timer.cpuTimeIncrement() << " s, " - << mem.update().size() << " kB" << endl; + << Foam::memInfo{}.size() << " kB" << endl; } Info<< "\nEnd: " << timer.elapsedCpuTime() << " s, " - << mem.update().peak() << " kB (peak)\n" << endl; + << Foam::memInfo{}.peak() << " kB (peak)\n" << endl; return 0; } diff --git a/src/OSspecific/MSwindows/cpuInfo/cpuInfo.C b/src/OSspecific/MSwindows/cpuInfo/cpuInfo.C index d073242342..32e4cd291e 100644 --- a/src/OSspecific/MSwindows/cpuInfo/cpuInfo.C +++ b/src/OSspecific/MSwindows/cpuInfo/cpuInfo.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,11 @@ License #include -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::cpuInfo::populate() +{} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -48,7 +52,7 @@ Foam::cpuInfo::cpuInfo() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::cpuInfo::write(Ostream& os) const +void Foam::cpuInfo::writeEntries(Ostream& os) const { if (!vendor_id.empty()) { @@ -67,4 +71,12 @@ void Foam::cpuInfo::write(Ostream& os) const } +void Foam::cpuInfo::writeEntry(const word& keyword, Ostream& os) const +{ + os.beginBlock(keyword); + writeEntries(os); + os.endBlock(); +} + + // ************************************************************************* // diff --git a/src/OSspecific/MSwindows/cpuInfo/cpuInfo.H b/src/OSspecific/MSwindows/cpuInfo/cpuInfo.H index 9a0073bd46..b3ad13a0c1 100644 --- a/src/OSspecific/MSwindows/cpuInfo/cpuInfo.H +++ b/src/OSspecific/MSwindows/cpuInfo/cpuInfo.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,6 +51,7 @@ namespace Foam { // Forward Declarations +class word; class Ostream; /*---------------------------------------------------------------------------*\ @@ -59,9 +60,7 @@ class Ostream; class cpuInfo { - // Private data - - // Various bits from /proc/cpuinfo + // Private Data std::string vendor_id; std::string model_name; @@ -74,14 +73,9 @@ class cpuInfo // Private Member Functions - //- Parse /proc/cpuinfo - void parse(); + //- Populate entries + void populate(); - //- No copy construct - cpuInfo(const cpuInfo&) = delete; - - //- No copy assignment - void operator=(const cpuInfo&) = delete; public: @@ -90,15 +84,14 @@ public: //- Construct and populate with information cpuInfo(); - //- Destructor - ~cpuInfo() = default; - // Member Functions - //- Write content as dictionary entries - void write(Ostream& os) const; + //- Write cpu-info as dictionary entries + void writeEntries(Ostream& os) const; + //- Write cpu-info as dictionary + void writeEntry(const word& keyword, Ostream& os) const; }; diff --git a/src/OSspecific/MSwindows/memInfo/memInfo.C b/src/OSspecific/MSwindows/memInfo/memInfo.C index 2e332c70a0..a57f1c7c9e 100644 --- a/src/OSspecific/MSwindows/memInfo/memInfo.C +++ b/src/OSspecific/MSwindows/memInfo/memInfo.C @@ -27,9 +27,10 @@ License \*---------------------------------------------------------------------------*/ #include "memInfo.H" -#include "OSspecific.H" #include "IOstreams.H" +#include "OSspecific.H" // For pid() +#include #include #include @@ -42,7 +43,7 @@ Foam::memInfo::memInfo() rss_(0), free_(0) { - update(); + populate(); } @@ -56,50 +57,63 @@ bool Foam::memInfo::good() const noexcept void Foam::memInfo::clear() noexcept { - peak_ = size_ = rss_ = 0; - free_ = 0; + peak_ = size_ = rss_ = free_ = 0; +} + + +void Foam::memInfo::populate() +{ + // Not yet supported under Windows } const Foam::memInfo& Foam::memInfo::update() { - clear(); - - // Not supported under Windows - + // Not yet supported under Windows + // clear(); + // populate(); return *this; } -void Foam::memInfo::write(Ostream& os) const +void Foam::memInfo::writeEntries(Ostream& os) const { os.writeEntry("size", size_); os.writeEntry("peak", peak_); os.writeEntry("rss", rss_); os.writeEntry("free", free_); + os.writeEntry("units", "kB"); // kibi-btyes (1024) +} + + +void Foam::memInfo::writeEntry(const word& keyword, Ostream& os) const +{ + os.beginBlock(keyword); + writeEntries(os); + os.endBlock(); } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -Foam::Istream& Foam::operator>>(Istream& is, memInfo& m) -{ - is.readBegin("memInfo"); - is >> m.peak_ >> m.size_ >> m.rss_ >> m.free_; - is.readEnd("memInfo"); - - is.check(FUNCTION_NAME); - return is; -} +// Foam::Istream& Foam::operator>>(Istream& is, memInfo& m) +// { +// is.readBegin("memInfo"); +// is >> m.peak_ >> m.size_ >> m.rss_ >> m.free_; +// is.readEnd("memInfo"); +// +// is.check(FUNCTION_NAME); +// return is; +// } Foam::Ostream& Foam::operator<<(Ostream& os, const memInfo& m) { os << token::BEGIN_LIST - << m.peak_ << token::SPACE - << m.size_ << token::SPACE - << m.rss_ << token::SPACE - << m.free_ + << m.peak() << token::SPACE + << m.size() << token::SPACE + << m.rss() << token::SPACE + << m.free() << token::END_LIST; os.check(FUNCTION_NAME); diff --git a/src/OSspecific/MSwindows/memInfo/memInfo.H b/src/OSspecific/MSwindows/memInfo/memInfo.H index 9e8b8c0c1f..41a7714c17 100644 --- a/src/OSspecific/MSwindows/memInfo/memInfo.H +++ b/src/OSspecific/MSwindows/memInfo/memInfo.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -42,6 +42,8 @@ SourceFiles #ifndef Foam_memInfo_H #define Foam_memInfo_H +#include + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -49,13 +51,11 @@ namespace Foam // Forward Declarations class memInfo; -class Istream; +class word; class Ostream; -Istream& operator>>(Istream& is, memInfo& m); Ostream& operator<<(Ostream& os, const memInfo& m); - /*---------------------------------------------------------------------------*\ Class memInfo Declaration \*---------------------------------------------------------------------------*/ @@ -64,17 +64,24 @@ class memInfo { // Private Data - //- Peak memory used by the process (VmPeak in /proc/PID/status) - int peak_; + //- Peak memory used by the process + int64_t peak_; - //- Memory used by the process (VmSize in /proc/PID/status) - int size_; + //- Memory used by the process + int64_t size_; - //- Resident set size of the process (VmRSS in /proc/PID/status) - int rss_; + //- Resident set size of the process + int64_t rss_; + + //- System memory free + int64_t free_; + + + // Private Member Functions + + //- Populate entries + void populate(); - //- System memory free (MemFree in /proc/meminfo) - int free_; public: @@ -84,53 +91,48 @@ public: memInfo(); - //- Destructor - ~memInfo() = default; - - // Member Functions + // Access + //- True if the memory information appears valid bool good() const noexcept; + //- Peak memory at last update + int64_t peak() const noexcept { return peak_; } + + //- Memory size at last update + int64_t size() const noexcept { return size_; } + + //- Resident set size at last update + int64_t rss() const noexcept { return rss_; } + + //- System memory free + int64_t free() const noexcept { return free_; } + + + // Edit + //- Reset to zero void clear() noexcept; - //- Update according to /proc/PID/status and /proc/memory contents + //- Update const memInfo& update(); - //- Peak memory (VmPeak in /proc/PID/status) at last update() - int peak() const noexcept { return peak_; } - - //- Memory size (VmSize in /proc/PID/status) at last update() - int size() const noexcept { return size_; } - - //- Resident set size (VmRSS in /proc/PID/status) at last update() - int rss() const noexcept { return rss_; } - - //- System memory free (MemFree in /proc/meminfo) - int free() const noexcept { return free_; } - - - // Write - - //- Write content as dictionary entries - void write(Ostream& os) const; - // IOstream Operators - //- Read peak/size/rss from stream - friend Istream& operator>>(Istream& is, memInfo& m); - //- Write peak/size/rss to stream friend Ostream& operator<<(Ostream& os, const memInfo& m); - // Housekeeping + // Write - //- True if the memory information appears valid - bool valid() const noexcept { return good(); } + //- Write mem-info as dictionary entries + void writeEntries(Ostream& os) const; + + //- Write mem-info as dictionary + void writeEntry(const word& keyword, Ostream& os) const; }; diff --git a/src/OSspecific/POSIX/cpuInfo/cpuInfo.C b/src/OSspecific/POSIX/cpuInfo/cpuInfo.C index 7fac0d572e..7d383b5cb6 100644 --- a/src/OSspecific/POSIX/cpuInfo/cpuInfo.C +++ b/src/OSspecific/POSIX/cpuInfo/cpuInfo.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,7 +35,7 @@ License // file-scope function // split things like "a key word\t: value information" // into ("a_key_word", "value information") -// + static bool split(const std::string& line, std::string& key, std::string& val) { key.clear(); @@ -109,7 +109,7 @@ static bool split(const std::string& line, std::string& key, std::string& val) // address sizes : 46 bits physical, 48 bits virtual // power management: -void Foam::cpuInfo::parse() +void Foam::cpuInfo::populate() { int ncpu = 0; std::string line, key, val; @@ -152,13 +152,13 @@ Foam::cpuInfo::cpuInfo() siblings(0), cpu_cores(0) { - parse(); + populate(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::cpuInfo::write(Ostream& os) const +void Foam::cpuInfo::writeEntries(Ostream& os) const { if (!vendor_id.empty()) { @@ -177,4 +177,12 @@ void Foam::cpuInfo::write(Ostream& os) const } +void Foam::cpuInfo::writeEntry(const word& keyword, Ostream& os) const +{ + os.beginBlock(keyword); + writeEntries(os); + os.endBlock(); +} + + // ************************************************************************* // diff --git a/src/OSspecific/POSIX/cpuInfo/cpuInfo.H b/src/OSspecific/POSIX/cpuInfo/cpuInfo.H index 349f0859c0..e9d5bedd87 100644 --- a/src/OSspecific/POSIX/cpuInfo/cpuInfo.H +++ b/src/OSspecific/POSIX/cpuInfo/cpuInfo.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,6 +51,7 @@ namespace Foam { // Forward Declarations +class word; class Ostream; /*---------------------------------------------------------------------------*\ @@ -59,9 +60,7 @@ class Ostream; class cpuInfo { - // Private data - - // Various bits from /proc/cpuinfo + // Private Data std::string vendor_id; std::string model_name; @@ -71,17 +70,10 @@ class cpuInfo int siblings; int cpu_cores; - // Private Member Functions - //- Parse /proc/cpuinfo - void parse(); - - //- No copy construct - cpuInfo(const cpuInfo&) = delete; - - //- No copy assignment - void operator=(const cpuInfo&) = delete; + //- Populate entries + void populate(); public: @@ -91,15 +83,13 @@ public: cpuInfo(); - //- Destructor - ~cpuInfo() = default; - - // Member Functions - //- Write content as dictionary entries - void write(Ostream& os) const; + //- Write cpu-info as dictionary entries + void writeEntries(Ostream& os) const; + //- Write cpu-info as dictionary + void writeEntry(const word& keyword, Ostream& os) const; }; diff --git a/src/OSspecific/POSIX/memInfo/memInfo.C b/src/OSspecific/POSIX/memInfo/memInfo.C index 63fc7cbd3c..a59d31f822 100644 --- a/src/OSspecific/POSIX/memInfo/memInfo.C +++ b/src/OSspecific/POSIX/memInfo/memInfo.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2016-2017 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,9 +27,10 @@ License \*---------------------------------------------------------------------------*/ #include "memInfo.H" -#include "OSspecific.H" #include "IOstreams.H" +#include "OSspecific.H" // For pid() +#include #include #include @@ -42,7 +43,7 @@ Foam::memInfo::memInfo() rss_(0), free_(0) { - update(); + populate(); } @@ -56,66 +57,14 @@ bool Foam::memInfo::good() const noexcept void Foam::memInfo::clear() noexcept { - peak_ = size_ = rss_ = 0; - free_ = 0; + peak_ = size_ = rss_ = free_ = 0; } -const Foam::memInfo& Foam::memInfo::update() +void Foam::memInfo::populate() { - clear(); std::string line; - // "/proc/PID/status" - // =========================== - // VmPeak: 15920 kB - // VmSize: 15916 kB - // VmLck: 0 kB - // VmPin: 0 kB - // VmHWM: 6972 kB - // VmRSS: 6972 kB - // ... - // Stop parsing when known keys have been extracted - { - std::ifstream is("/proc/" + std::to_string(Foam::pid()) + "/status"); - - for - ( - unsigned nkeys = 3; - nkeys && is.good() && std::getline(is, line); - /*nil*/ - ) - { - const auto delim = line.find(':'); - if (delim == std::string::npos) - { - continue; - } - - const std::string key(line.substr(0, delim)); - - // std::stoi() skips whitespace before using as many digits as - // possible. So just need to skip over the ':' and let stoi do - // the rest - - if (key == "VmPeak") - { - peak_ = std::stoi(line.substr(delim+1)); - --nkeys; - } - else if (key == "VmSize") - { - size_ = std::stoi(line.substr(delim+1)); - --nkeys; - } - else if (key == "VmRSS") - { - rss_ = std::stoi(line.substr(delim+1)); - --nkeys; - } - } - } - // "/proc/meminfo" // =========================== // MemTotal: 65879268 kB @@ -140,53 +89,120 @@ const Foam::memInfo& Foam::memInfo::update() continue; } - const std::string key = line.substr(0, delim); + const std::string key(line.substr(0, delim)); - // std::stoi() skips whitespace before using as many digits as - // possible. So just need to skip over the ':' and let stoi do + // std::stol() skips whitespace before using as many digits as + // possible. So just need to skip over the ':' and let stol do // the rest if (key == "MemFree") { - free_ = std::stoi(line.substr(delim+1)); + free_ = std::stol(line.substr(delim+1)); --nkeys; } } } + // "/proc/PID/status" + // =========================== + // VmPeak: 15920 kB + // VmSize: 15916 kB + // VmLck: 0 kB + // VmPin: 0 kB + // VmHWM: 6972 kB + // VmRSS: 6972 kB + // ... + // Stop parsing when known keys have been extracted + + // These units are kibi-btyes (1024) + { + std::ifstream is("/proc/" + std::to_string(Foam::pid()) + "/status"); + + for + ( + unsigned nkeys = 3; + nkeys && is.good() && std::getline(is, line); + /*nil*/ + ) + { + const auto delim = line.find(':'); + if (delim == std::string::npos) + { + continue; + } + + const std::string key(line.substr(0, delim)); + + // std::stoi() skips whitespace before using as many digits as + // possible. So just need to skip over the ':' and let stoi do + // the rest + + if (key == "VmPeak") + { + peak_ = std::stol(line.substr(delim+1)); + --nkeys; + } + else if (key == "VmSize") + { + size_ = std::stol(line.substr(delim+1)); + --nkeys; + } + else if (key == "VmRSS") + { + rss_ = std::stol(line.substr(delim+1)); + --nkeys; + } + } + } +} + + +const Foam::memInfo& Foam::memInfo::update() +{ + clear(); + populate(); return *this; } -void Foam::memInfo::write(Ostream& os) const +void Foam::memInfo::writeEntries(Ostream& os) const { os.writeEntry("size", size_); os.writeEntry("peak", peak_); os.writeEntry("rss", rss_); os.writeEntry("free", free_); + os.writeEntry("units", "kB"); +} + + +void Foam::memInfo::writeEntry(const word& keyword, Ostream& os) const +{ + os.beginBlock(keyword); + writeEntries(os); + os.endBlock(); } // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // -Foam::Istream& Foam::operator>>(Istream& is, memInfo& m) -{ - is.readBegin("memInfo"); - is >> m.peak_ >> m.size_ >> m.rss_ >> m.free_; - is.readEnd("memInfo"); - - is.check(FUNCTION_NAME); - return is; -} +// Foam::Istream& Foam::operator>>(Istream& is, memInfo& m) +// { +// is.readBegin("memInfo"); +// is >> m.peak_ >> m.size_ >> m.rss_ >> m.free_; +// is.readEnd("memInfo"); +// +// is.check(FUNCTION_NAME); +// return is; +// } Foam::Ostream& Foam::operator<<(Ostream& os, const memInfo& m) { os << token::BEGIN_LIST - << m.peak_ << token::SPACE - << m.size_ << token::SPACE - << m.rss_ << token::SPACE - << m.free_ + << m.peak() << token::SPACE + << m.size() << token::SPACE + << m.rss() << token::SPACE + << m.free() << token::END_LIST; os.check(FUNCTION_NAME); diff --git a/src/OSspecific/POSIX/memInfo/memInfo.H b/src/OSspecific/POSIX/memInfo/memInfo.H index 0dd54af18c..23b384e9fd 100644 --- a/src/OSspecific/POSIX/memInfo/memInfo.H +++ b/src/OSspecific/POSIX/memInfo/memInfo.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -42,6 +42,8 @@ SourceFiles #ifndef Foam_memInfo_H #define Foam_memInfo_H +#include + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -49,13 +51,11 @@ namespace Foam // Forward Declarations class memInfo; -class Istream; +class word; class Ostream; -Istream& operator>>(Istream& is, memInfo& m); Ostream& operator<<(Ostream& os, const memInfo& m); - /*---------------------------------------------------------------------------*\ Class memInfo Declaration \*---------------------------------------------------------------------------*/ @@ -65,16 +65,23 @@ class memInfo // Private Data //- Peak memory used by the process (VmPeak in /proc/PID/status) - int peak_; + int64_t peak_; //- Memory used by the process (VmSize in /proc/PID/status) - int size_; + int64_t size_; //- Resident set size of the process (VmRSS in /proc/PID/status) - int rss_; + int64_t rss_; //- System memory free (MemFree in /proc/meminfo) - int free_; + int64_t free_; + + + // Private Member Functions + + //- Populate entries + void populate(); + public: @@ -84,15 +91,28 @@ public: memInfo(); - //- Destructor - ~memInfo() = default; - - // Member Functions + // Access + //- True if the memory information appears valid bool good() const noexcept; + //- Peak memory at last update - (VmPeak in /proc/PID/status) + int64_t peak() const noexcept { return peak_; } + + //- Memory size at last update - (VmSize in /proc/PID/status) + int64_t size() const noexcept { return size_; } + + //- Resident set size at last update - (VmRSS in /proc/PID/status) + int64_t rss() const noexcept { return rss_; } + + //- System memory free (MemFree in /proc/meminfo) + int64_t free() const noexcept { return free_; } + + + // Edit + //- Reset to zero void clear() noexcept; @@ -100,38 +120,19 @@ public: const memInfo& update(); - //- Peak memory (VmPeak in /proc/PID/status) at last update() - int peak() const noexcept { return peak_; } - - //- Memory size (VmSize in /proc/PID/status) at last update() - int size() const noexcept { return size_; } - - //- Resident set size (VmRSS in /proc/PID/status) at last update() - int rss() const noexcept { return rss_; } - - //- System memory free (MemFree in /proc/meminfo) - int free() const noexcept { return free_; } - - - // Write - - //- Write content as dictionary entries - void write(Ostream& os) const; - - // IOstream Operators - //- Read peak/size/rss from stream - friend Istream& operator>>(Istream& is, memInfo& m); - //- Write peak/size/rss to stream friend Ostream& operator<<(Ostream& os, const memInfo& m); - // Housekeeping + // Write - //- True if the memory information appears valid - bool valid() const noexcept { return good(); } + //- Write mem-info as dictionary entries + void writeEntries(Ostream& os) const; + + //- Write mem-info as dictionary + void writeEntry(const word& keyword, Ostream& os) const; }; diff --git a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C index 590cea90db..56aaaf4838 100644 --- a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C +++ b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C @@ -2154,14 +2154,14 @@ Foam::indexedOctree::indexedOctree contents_(), nodeTypes_() { - int oldMemSize = 0; + int64_t oldMemSize = 0; if (debug) { Pout<< "indexedOctree::indexedOctree:" << nl << " shapes:" << shapes.size() << nl << " bb:" << bb << nl << endl; - oldMemSize = memInfo().size(); + oldMemSize = Foam::memInfo{}.size(); } if (shapes.size() == 0) @@ -2296,7 +2296,7 @@ Foam::indexedOctree::indexedOctree maxEntries = max(maxEntries, num); } - label memSize = memInfo().size(); + int64_t memSize = Foam::memInfo{}.size(); Pout<< "indexedOctree::indexedOctree" << " : finished construction of tree of:" << shapes.typeName diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 2b1673a1f5..f384919c50 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -371,7 +371,8 @@ void Foam::Time::setMonitoring(const bool forceProfiling) "uniform", *this, IOobjectOption::NO_READ, - IOobjectOption::AUTO_WRITE + IOobjectOption::AUTO_WRITE, + IOobjectOption::REGISTER ), *this ); @@ -392,7 +393,8 @@ void Foam::Time::setMonitoring(const bool forceProfiling) "uniform", *this, IOobjectOption::NO_READ, - IOobjectOption::AUTO_WRITE + IOobjectOption::AUTO_WRITE, + IOobjectOption::REGISTER ), *this ); diff --git a/src/OpenFOAM/global/profiling/profiling.C b/src/OpenFOAM/global/profiling/profiling.C index 7d4f10908f..305cbcd854 100644 --- a/src/OpenFOAM/global/profiling/profiling.C +++ b/src/OpenFOAM/global/profiling/profiling.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2016 Bernhard Gschaider - Copyright (C) 2016-2022 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,6 +36,7 @@ License // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // int Foam::profiling::allowed(Foam::debug::infoSwitch("allowProfiling", 1)); + std::unique_ptr Foam::profiling::singleton_(nullptr); @@ -62,7 +63,7 @@ Foam::profilingInformation* Foam::profiling::create() Foam::profilingInformation* Foam::profiling::create ( profilingInformation *parent, - const string& descr + const std::string& descr ) { const label parentId = parent->id(); @@ -110,13 +111,13 @@ Foam::profilingInformation* Foam::profiling::endTimer() // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -bool Foam::profiling::active() +bool Foam::profiling::active() noexcept { return allowed && singleton_; } -void Foam::profiling::disable() +void Foam::profiling::disable() noexcept { allowed = 0; } @@ -124,7 +125,7 @@ void Foam::profiling::disable() bool Foam::profiling::print(Ostream& os) { - if (active()) + if (allowed && singleton_) { return singleton_->writeData(os); } @@ -135,7 +136,7 @@ bool Foam::profiling::print(Ostream& os) bool Foam::profiling::writeNow() { - if (active()) + if (allowed && singleton_) { return singleton_->regIOobject::write(); } @@ -180,7 +181,7 @@ void Foam::profiling::stop(const Time& owner) } -Foam::profilingInformation* Foam::profiling::New(const string& descr) +Foam::profilingInformation* Foam::profiling::New(const std::string& descr) { Information *info = nullptr; @@ -193,10 +194,12 @@ Foam::profilingInformation* Foam::profiling::New(const string& descr) if (singleton_->memInfo_) { + singleton_->memInfo_->update(); + info->maxMem_ = Foam::max ( info->maxMem_, - singleton_->memInfo_->update().size() + singleton_->memInfo_->size() ); } } @@ -236,14 +239,7 @@ Foam::profiling::profiling ) : IOdictionary(io), - owner_(owner), - pool_(), - children_(), - stack_(), - times_(), - sysInfo_(nullptr), - cpuInfo_(nullptr), - memInfo_(nullptr) + owner_(owner) { if (allEnabled) { @@ -268,17 +264,21 @@ Foam::profiling::profiling : profiling(io, owner, false) { - if (dict.getOrDefault("sysInfo", false)) { - sysInfo_.reset(new profilingSysInfo); - } - if (dict.getOrDefault("cpuInfo", false)) - { - cpuInfo_.reset(new cpuInfo); - } - if (dict.getOrDefault("memInfo", false)) - { - memInfo_.reset(new memInfo); + bool on = false; + + if (dict.readIfPresent("sysInfo", on) && on) + { + sysInfo_.reset(new profilingSysInfo); + } + if (dict.readIfPresent("cpuInfo", on) && on) + { + cpuInfo_.reset(new cpuInfo); + } + if (dict.readIfPresent("memInfo", on) && on) + { + memInfo_.reset(new memInfo); + } } } @@ -296,7 +296,7 @@ Foam::profiling::~profiling() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::Time& Foam::profiling::owner() const +const Foam::Time& Foam::profiling::owner() const noexcept { return owner_; } @@ -355,28 +355,20 @@ bool Foam::profiling::writeData(Ostream& os) const if (sysInfo_) { os << nl; - os.beginBlock("sysInfo"); - sysInfo_->write(os); - os.endBlock(); + sysInfo_->writeEntry("sysInfo", os); } if (cpuInfo_) { os << nl; - os.beginBlock("cpuInfo"); - cpuInfo_->write(os); - os.endBlock(); + cpuInfo_->writeEntry("cpuInfo", os); } if (memInfo_) { memInfo_->update(); - os << nl; - os.beginBlock("memInfo"); - memInfo_->write(os); - os.writeEntry("units", "kB"); - os.endBlock(); + memInfo_->writeEntry("memInfo", os); } return os.good(); @@ -393,7 +385,7 @@ bool Foam::profiling::writeObject regIOobject::writeObject ( IOstreamOption(IOstreamOption::ASCII), - true + true // always writeOnProc ); } diff --git a/src/OpenFOAM/global/profiling/profiling.H b/src/OpenFOAM/global/profiling/profiling.H index 472a6b2c18..52fe39dc1c 100644 --- a/src/OpenFOAM/global/profiling/profiling.H +++ b/src/OpenFOAM/global/profiling/profiling.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2016 Bernhard Gschaider - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -118,7 +118,7 @@ private: PtrDynList pool_; //- Parent/child relationships for lookup purposes - DynamicList> children_; + DynamicList> children_; //- LIFO stack of profiling information DynamicList stack_; @@ -136,15 +136,6 @@ private: std::unique_ptr memInfo_; - // Private Member Functions - - //- No copy construct - profiling(const profiling&) = delete; - - //- No copy assignment - void operator=(const profiling&) = delete; - - protected: // Friendship @@ -153,6 +144,15 @@ protected: friend class Time; + // Generated Methods + + //- No copy construct + profiling(const profiling&) = delete; + + //- No copy assignment + void operator=(const profiling&) = delete; + + // Constructors //- Construct IO object, everything enabled @@ -184,7 +184,7 @@ protected: Information* create ( Information* parent, - const string& descr + const std::string& descr ); //- Add to stack of active information and begin timer datum @@ -217,7 +217,7 @@ protected: //- Existing or new element on pool, add to stack. // Returns nullptr if profiling has not been initialized - static profilingInformation* New(const string& descr); + static profilingInformation* New(const std::string& descr); //- Remove the information from the top of the stack static void unstack(const profilingInformation* info); @@ -232,10 +232,10 @@ public: // Static Member Functions //- True if profiling is allowed and is active - static bool active(); + static bool active() noexcept; - //- Disallow profiling by forcing the InfoSwitch off. - static void disable(); + //- Disallow profiling - turns the InfoSwitch off + static void disable() noexcept; //- Print profiling information to specified output // Forwards to writeData member of top-level object @@ -248,7 +248,7 @@ public: // Member Functions //- The owner of the profiling - const Time& owner() const; + const Time& owner() const noexcept; //- The size of the current stack label size() const noexcept; diff --git a/src/OpenFOAM/global/profiling/profilingInformation.C b/src/OpenFOAM/global/profiling/profilingInformation.C index 93c769ca87..b15d8c6eec 100644 --- a/src/OpenFOAM/global/profiling/profilingInformation.C +++ b/src/OpenFOAM/global/profiling/profilingInformation.C @@ -48,7 +48,7 @@ Foam::profilingInformation::profilingInformation() Foam::profilingInformation::profilingInformation ( profilingInformation *parent, - const string& descr, + const std::string& descr, const label id ) : diff --git a/src/OpenFOAM/global/profiling/profilingInformation.H b/src/OpenFOAM/global/profiling/profilingInformation.H index deab20270d..7a552e759a 100644 --- a/src/OpenFOAM/global/profiling/profilingInformation.H +++ b/src/OpenFOAM/global/profiling/profilingInformation.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2016 Bernhard Gschaider - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -62,7 +62,7 @@ class profilingInformation const label id_; //- What this timer does - const string description_; + const std::string description_; //- Pointer to the parent object (or self for top-level) profilingInformation* parent_; @@ -97,18 +97,18 @@ protected: //- Default construct - only the master-element profilingInformation(); - - // Protected Member Functions - - //- Mark as being active or passive) - void setActive(bool state) const; - //- No copy construct profilingInformation(const profilingInformation&) = delete; //- No copy assignment void operator=(const profilingInformation&) = delete; + + // Protected Member Functions + + //- Mark as being active or passive + void setActive(bool state) const; + public: // Constructors @@ -117,7 +117,7 @@ public: profilingInformation ( profilingInformation* parent, - const string& descr, + const std::string& descr, const label id ); @@ -132,7 +132,7 @@ public: label id() const noexcept { return id_; } - const string& description() const noexcept { return description_; } + const std::string& description() const noexcept { return description_; } profilingInformation& parent() const noexcept { return *parent_; } @@ -167,6 +167,8 @@ public: }; +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + // Global Operators Ostream& operator<<(Ostream& os, const profilingInformation& info); diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.C b/src/OpenFOAM/global/profiling/profilingSysInfo.C index 70bacecab8..e7e41e18cc 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.C +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2021 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -56,10 +56,7 @@ inline void printEnv // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::Ostream& Foam::profilingSysInfo::write -( - Ostream& os -) const +void Foam::profilingSysInfo::writeEntries(Ostream& os) const { os.writeEntry("host", Foam::hostName()); // short name os.writeEntry("date", Foam::clock::dateTime()); @@ -73,8 +70,14 @@ Foam::Ostream& Foam::profilingSysInfo::write printEnv(os, "compiler", "WM_COMPILER"); printEnv(os, "mplib", "WM_MPLIB"); printEnv(os, "options", "WM_OPTIONS"); +} - return os; + +void Foam::profilingSysInfo::writeEntry(const word& keyword, Ostream& os) const +{ + os.beginBlock(keyword); + writeEntries(os); + os.endBlock(); } diff --git a/src/OpenFOAM/global/profiling/profilingSysInfo.H b/src/OpenFOAM/global/profiling/profilingSysInfo.H index 6b1ce31f32..c4e7a7a347 100644 --- a/src/OpenFOAM/global/profiling/profilingSysInfo.H +++ b/src/OpenFOAM/global/profiling/profilingSysInfo.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +34,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef profilingSysInfo_H -#define profilingSysInfo_H +#ifndef Foam_profilingSysInfo_H +#define Foam_profilingSysInfo_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -43,6 +43,7 @@ namespace Foam { // Forward Declarations +class word; class Ostream; /*---------------------------------------------------------------------------*\ @@ -55,8 +56,11 @@ public: // Member Functions - //- Write the profiling system-info, use dictionary format. - Ostream& write(Ostream& os) const; + //- Write system-info as dictionary entries + void writeEntries(Ostream& os) const; + + //- Write system-info as dictionary + void writeEntry(const word& keyword, Ostream& os) const; }; diff --git a/src/OpenFOAM/global/profiling/profilingTrigger.C b/src/OpenFOAM/global/profiling/profilingTrigger.C index aa3bd643c6..341baae0a8 100644 --- a/src/OpenFOAM/global/profiling/profilingTrigger.C +++ b/src/OpenFOAM/global/profiling/profilingTrigger.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2016 Bernhard Gschaider - Copyright (C) 2016-2018 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,7 +32,7 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::profilingTrigger::profilingTrigger() +Foam::profilingTrigger::profilingTrigger() noexcept : ptr_(nullptr) {} @@ -40,14 +40,15 @@ Foam::profilingTrigger::profilingTrigger() Foam::profilingTrigger::profilingTrigger(const char* name) : - ptr_(profiling::New(name)) + profilingTrigger(std::string(name)) {} -Foam::profilingTrigger::profilingTrigger(const string& name) +Foam::profilingTrigger::profilingTrigger(const std::string& name) : ptr_(profiling::New(name)) -{} +{ +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // @@ -60,7 +61,7 @@ Foam::profilingTrigger::~profilingTrigger() // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -bool Foam::profilingTrigger::running() const +bool Foam::profilingTrigger::running() const noexcept { return ptr_; } diff --git a/src/OpenFOAM/global/profiling/profilingTrigger.H b/src/OpenFOAM/global/profiling/profilingTrigger.H index 639c6eac70..e1242a06cb 100644 --- a/src/OpenFOAM/global/profiling/profilingTrigger.H +++ b/src/OpenFOAM/global/profiling/profilingTrigger.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2009-2016 Bernhard Gschaider - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,8 +59,9 @@ class profilingTrigger //- The profiling information profilingInformation *ptr_; +public: - // Private Member Functions + // Generated Methods //- No copy construct profilingTrigger(const profilingTrigger&) = delete; @@ -69,22 +70,20 @@ class profilingTrigger void operator=(const profilingTrigger&) = delete; -public: - // Constructors //- Default construct, no profiling trigger - profilingTrigger(); + profilingTrigger() noexcept; //- Construct profiling with given description. // Descriptions beginning with 'application::' are reserved for // internal use. - profilingTrigger(const char* name); + explicit profilingTrigger(const char* name); //- Construct profiling with given description. // Descriptions beginning with 'application::' are reserved for // internal use. - profilingTrigger(const string& name); + explicit profilingTrigger(const std::string& name); //- Destructor @@ -94,7 +93,7 @@ public: // Member Functions //- True if the triggered profiling is active - bool running() const; + bool running() const noexcept; //- Stop triggered profiling void stop(); @@ -111,25 +110,22 @@ public: //- Define profiling trigger with specified name and description string // \sa endProfiling -#define addProfiling(name,descr) \ - ::Foam::profilingTrigger profilingTriggerFor##name(descr) +#define addProfiling(Name,Descr) \ + ::Foam::profilingTrigger profilingTriggerFor##Name(Descr) + +//- Remove profiling with specified name +// \sa addProfiling +#define endProfiling(Name) profilingTriggerFor##Name.stop() //- Define profiling trigger with specified name and description //- corresponding to the compiler-defined function name string // \sa addProfiling -// \sa endProfiling #ifdef __GNUC__ - #define addProfilingInFunction(name) \ - ::Foam::profilingTrigger profilingTriggerFor##name(__PRETTY_FUNCTION__) +#define addProfilingInFunction(Name) addProfiling(Name, __PRETTY_FUNCTION__) #else - #define addProfilingInFunction(name) \ - ::Foam::profilingTrigger profilingTriggerFor##name(__func__) +#define addProfilingInFunction(Name) addProfiling(Name, __func__) #endif -//- Remove profiling with specified name -// \sa addProfiling -#define endProfiling(name) profilingTriggerFor##name.stop() - #endif