OpenMS
Loading...
Searching...
No Matches
SysInfo.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Chris Bielow $
6// $Authors: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
13
14#include <vector>
15
16namespace OpenMS
17{
18
20 OPENMS_DLLAPI std::string bytesToHumanReadable(UInt64 bytes);
21
28 class OPENMS_DLLAPI SysInfo
29 {
30 public:
37 static bool getProcessMemoryConsumption(size_t& mem_virtual);
38
45 static bool getProcessPeakMemoryConsumption(size_t& mem_virtual);
46
56 static bool getFreeSystemMemory(size_t& mem_available);
57
62
77 static UInt getAvailablePhysicalCores(const std::vector<int>& cpus = {});
78
89
93 static void setOmpThreadsOfThisThread(int threads);
94
121 struct OPENMS_DLLAPI MemUsage
122 {
123 size_t mem_before, mem_before_peak, mem_after, mem_after_peak;
124
127
129 void reset();
131 void before();
133 void after();
136 std::string delta(const std::string& event = "delta");
137
140 std::string usage();
141
142 private:
143 // convert difference to string
144 std::string diff_str_(size_t mem_before, size_t mem_after);
145
146 };
147 };
148}
Some functions to get system information.
Definition SysInfo.h:29
static UInt getAvailablePhysicalCores(const std::vector< int > &cpus={})
The number of physical cores the process may run on (at least 1).
static int ompThreadsOfThisThread()
The OpenMP threads for the parallel regions that the calling thread starts.
static bool getProcessMemoryConsumption(size_t &mem_virtual)
static Int64 getProcessId()
static bool getProcessPeakMemoryConsumption(size_t &mem_virtual)
static bool getFreeSystemMemory(size_t &mem_available)
Get currently available physical system memory in KiloBytes (KB).
static bool ompThreadCountIsGlobal()
Whether the OpenMP runtime keeps one process-wide number of threads.
static void setOmpThreadsOfThisThread(int threads)
Sets the OpenMP threads that ompThreadsOfThisThread() reports for the calling thread (0: omp_get_max_...
int64_t Int64
Signed integer type (64bit)
Definition Types.h:40
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::string bytesToHumanReadable(UInt64 bytes)
convert bytes to a human readable unit (TiB, GiB, MiB, KiB), e.g. "45.34 MiB"
A convenience class to report either absolute or delta (between two timepoints) RAM usage.
Definition SysInfo.h:122
std::string diff_str_(size_t mem_before, size_t mem_after)
void before()
record data for the first timepoint
void after()
record data for the second timepoint
size_t mem_after
Definition SysInfo.h:123
MemUsage()
C'tor, calls before() automatically.
void reset()
forget all data (you need to call before() again)
std::string delta(const std::string &event="delta")