souffle  2.0.2-371-g6315b36
Logger.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file Logger.h
12  *
13  * A logger is the utility utilized by RAM programs to create logs and
14  * traces.
15  *
16  ***********************************************************************/
17 
18 #pragma once
19 
22 #include <cstddef>
23 #include <functional>
24 #include <string>
25 #include <utility>
26 
27 namespace souffle {
28 
29 /**
30  * The class utilized to times for the souffle profiling tool. This class
31  * is utilized by both -- the interpreted and compiled version -- to conduct
32  * the corresponding measurements.
33  *
34  * To far, only execution times are logged. More events, e.g. the number of
35  * processed tuples may be added in the future.
36  */
37 class Logger {
38 public:
39  Logger(std::string label, size_t iteration) : Logger(label, iteration, []() { return 0; }) {}
40 
41  Logger(std::string label, size_t iteration, std::function<size_t()> size)
42  : label(std::move(label)), start(now()), iteration(iteration), size(size), preSize(size()) {
43 #ifdef WIN32
44  HANDLE hProcess = GetCurrentProcess();
45  PROCESS_MEMORY_COUNTERS processMemoryCounters;
46  GetProcessMemoryInfo(hProcess, &processMemoryCounters, sizeof(processMemoryCounters));
47  startMaxRSS = processMemoryCounters.PeakWorkingSetSize / 1000;
48 #else
49  struct rusage ru {};
50  getrusage(RUSAGE_SELF, &ru);
51  startMaxRSS = ru.ru_maxrss;
52 #endif // WIN32
53  // Assume that if we are logging the progress of an event then we care about usage during that time.
55  }
56 
57  ~Logger() {
58 #ifdef WIN32
59  HANDLE hProcess = GetCurrentProcess();
60  PROCESS_MEMORY_COUNTERS processMemoryCounters;
61  GetProcessMemoryInfo(hProcess, &processMemoryCounters, sizeof(processMemoryCounters));
62  size_t endMaxRSS = processMemoryCounters.PeakWorkingSetSize / 1000;
63 #else
64  struct rusage ru {};
65  getrusage(RUSAGE_SELF, &ru);
66  size_t endMaxRSS = ru.ru_maxrss;
67 #endif // WIN32
69  label, start, now(), startMaxRSS, endMaxRSS, size() - preSize, iteration);
70  }
71 
72 private:
73  std::string label;
75  size_t startMaxRSS;
76  size_t iteration;
77  std::function<size_t()> size;
78  size_t preSize;
79 };
80 } // end of namespace souffle
souffle::Logger::preSize
size_t preSize
Definition: Logger.h:92
souffle::Logger::startMaxRSS
size_t startMaxRSS
Definition: Logger.h:89
souffle::ProfileEventSingleton::instance
static ProfileEventSingleton & instance()
get instance
Definition: ProfileEvent.h:70
souffle::Logger::label
std::string label
Definition: Logger.h:87
souffle::Logger::iteration
size_t iteration
Definition: Logger.h:90
MiscUtil.h
ProfileEvent.h
souffle::now
time_point now()
Definition: MiscUtil.h:89
souffle::Logger::size
std::function< size_t()> size
Definition: Logger.h:91
souffle::Logger::Logger
Logger(std::string label, size_t iteration)
Definition: Logger.h:53
souffle::Logger::~Logger
~Logger()
Definition: Logger.h:71
souffle::time_point
std::chrono::high_resolution_clock::time_point time_point
Definition: MiscUtil.h:85
souffle::Logger::start
time_point start
Definition: Logger.h:88
souffle::ProfileEventSingleton::resetTimerInterval
void resetTimerInterval(uint32_t interval=1)
Definition: ProfileEvent.h:165
std
Definition: Brie.h:3053
souffle
Definition: AggregateOp.h:25
souffle::ProfileEventSingleton::makeTimingEvent
void makeTimingEvent(const std::string &txt, time_point start, time_point end, size_t startMaxRSS, size_t endMaxRSS, size_t size, size_t iteration)
create an event for recording start and end times
Definition: ProfileEvent.h:87