Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 12c2203

Browse files
authored
Fix Memory Tracking Issue (#1250) (#1269)
1 parent d70c1c1 commit 12c2203

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/include/execution/sql/memory_tracker.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,42 @@
55
namespace noisepage::execution::sql {
66

77
/**
8-
* TODO: track memory usage
8+
* Class for tracking memory on a per-thread granularity.
9+
* Currently tracks allocation size in bytes during thread's execution.
910
*/
1011
class EXPORT MemoryTracker {
1112
public:
12-
// TODO(pmenon): Fill me in
13-
1413
/**
1514
* Reset tracker
1615
*/
17-
void Reset() { allocated_bytes_ = 0; }
16+
void Reset() { stats_.local().allocated_bytes_ = 0; }
1817

1918
/**
2019
* @returns number of allocated bytes
2120
*/
22-
size_t GetAllocatedSize() { return allocated_bytes_; }
21+
size_t GetAllocatedSize() { return stats_.local().allocated_bytes_; }
2322

2423
/**
2524
* Increments number of allocated bytes
2625
* @param size number to increment by
2726
*/
28-
void Increment(size_t size) { allocated_bytes_ += size; }
27+
void Increment(size_t size) { stats_.local().allocated_bytes_ += size; }
2928

3029
/**
3130
* Decrements number of allocated bytes
3231
* @param size number to decrement by
3332
*/
34-
void Decrement(size_t size) { allocated_bytes_ -= size; }
33+
void Decrement(size_t size) { stats_.local().allocated_bytes_ -= size; }
3534

3635
private:
37-
struct Stats {};
36+
/**
37+
* Struct to store per-thread tracking data.
38+
*/
39+
struct Stats {
40+
// Number of bytes allocated
41+
size_t allocated_bytes_ = 0;
42+
};
3843
tbb::enumerable_thread_specific<Stats> stats_;
39-
// number of bytes allocated
40-
size_t allocated_bytes_;
4144
};
4245

4346
} // namespace noisepage::execution::sql

0 commit comments

Comments
 (0)