Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MemUsage.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 /*
21  */
22 
30 #pragma once
31 #include <atomic>
32 namespace galois {
33 namespace runtime {
34 
39  std::atomic<int64_t>
40  currentMemUsage;
41  int64_t maxMemUsage;
42 
43 public:
45  MemUsageTracker() : currentMemUsage(0), maxMemUsage(0) {}
46 
52  inline void incrementMemUsage(uint64_t size) {
53  currentMemUsage += size;
54  if (currentMemUsage > maxMemUsage)
55  maxMemUsage = currentMemUsage;
56  }
57 
63  inline void decrementMemUsage(uint64_t size) { currentMemUsage -= size; }
64 
68  inline void resetMemUsage() {
69  currentMemUsage = 0;
70  maxMemUsage = 0;
71  }
72 
78  inline int64_t getMaxMemUsage() const { return maxMemUsage; }
79 };
80 
81 } // namespace runtime
82 } // namespace galois
void resetMemUsage()
Reset mem usage and max mem usage to 0.
Definition: MemUsage.h:68
int64_t getMaxMemUsage() const
Get max mem usage.
Definition: MemUsage.h:78
Class that tracks memory usage (mainly of send and receive buffers).
Definition: MemUsage.h:38
MemUsageTracker()
Default constructor initializes everything to 0.
Definition: MemUsage.h:45
void incrementMemUsage(uint64_t size)
Increment memory usage.
Definition: MemUsage.h:52
void decrementMemUsage(uint64_t size)
Decrement memory usage.
Definition: MemUsage.h:63