14 #include <framework/utilities/Utils.h> 
   16 #include <framework/gearbox/Unit.h> 
   17 #include <framework/logging/Logger.h> 
   19 #include <boost/process.hpp> 
   40   std::pair<unsigned long, unsigned long> getStatmSize()
 
   43     const static long pageSizeKb = sysconf(_SC_PAGESIZE) / 1024;
 
   44     static FILE* stream = 
nullptr;
 
   46     int currentPid = getpid();
 
   47     if (currentPid != pid) {
 
   49       std::string statm = 
"/proc/" + std::to_string(pid) + 
"/statm";
 
   50       stream = fopen(statm.c_str(), 
"r");
 
   53       setvbuf(stream, 
nullptr, _IONBF, 0);
 
   55     unsigned long vmSizePages{0};
 
   56     unsigned long rssPages{0};
 
   58     fscanf(stream, 
"%lu %lu", &vmSizePages, &rssPages);
 
   59     return std::make_pair(vmSizePages * pageSizeKb, rssPages * pageSizeKb);
 
   68     clock_gettime(CLOCK_REALTIME, &ts);
 
   74     clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
 
   80     return getStatmSize().first;
 
   85     return getStatmSize().second;
 
   90     m_text(std::move(text))
 
   96     B2INFO(
m_text << 
" " << std::fixed << std::setprecision(3) << elapsed << 
" ms");
 
   99   std::string 
getCommandOutput(
const std::string& command, 
const std::vector<std::string>& arguments,
 
  102     namespace bp = boost::process;
 
  103     auto cmd = searchPath ? bp::search_path(command) : boost::filesystem::path(command);
 
  105     bp::child child(cmd, bp::args(arguments), bp::std_in.close(), bp::std_out > cmdOut);
 
  108     while (child.running() && cmdOut.read(buffer, 
sizeof(buffer))) {
 
  109       result.append(buffer, 
sizeof(buffer));
 
  111     if (cmdOut.gcount()) result.append(buffer, cmdOut.gcount());
 
static const double ms
[millisecond]
static const double ns
Standard of [time].
static const double s
[second]
double m_startTime
time at start (in ns).
std::string m_text
identifying text (printed at end).
Timer(std::string text="")
Constructor, with some identifying text.
General utility functions.
std::string getCommandOutput(const std::string &command, const std::vector< std::string > &arguments={}, bool searchPath=true)
Execute a shell command and return its output.
double getCPUClock()
Return current value of the per-thread CPU clock.
double getClock()
Return current value of the real-time clock.
unsigned long getRssMemoryKB()
Returns the amount of memory the process actually occupies in the physical RAM of the machine.
unsigned long getVirtualMemoryKB()
Returns currently used virtual memory in KB, includes swapped and not occupied memory pages and memor...
Abstract base class for different kinds of events.