|
5 | 5 | namespace noisepage::execution::sql {
|
6 | 6 |
|
7 | 7 | /**
|
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. |
9 | 10 | */
|
10 | 11 | class EXPORT MemoryTracker {
|
11 | 12 | public:
|
12 |
| - // TODO(pmenon): Fill me in |
13 |
| - |
14 | 13 | /**
|
15 | 14 | * Reset tracker
|
16 | 15 | */
|
17 |
| - void Reset() { allocated_bytes_ = 0; } |
| 16 | + void Reset() { stats_.local().allocated_bytes_ = 0; } |
18 | 17 |
|
19 | 18 | /**
|
20 | 19 | * @returns number of allocated bytes
|
21 | 20 | */
|
22 |
| - size_t GetAllocatedSize() { return allocated_bytes_; } |
| 21 | + size_t GetAllocatedSize() { return stats_.local().allocated_bytes_; } |
23 | 22 |
|
24 | 23 | /**
|
25 | 24 | * Increments number of allocated bytes
|
26 | 25 | * @param size number to increment by
|
27 | 26 | */
|
28 |
| - void Increment(size_t size) { allocated_bytes_ += size; } |
| 27 | + void Increment(size_t size) { stats_.local().allocated_bytes_ += size; } |
29 | 28 |
|
30 | 29 | /**
|
31 | 30 | * Decrements number of allocated bytes
|
32 | 31 | * @param size number to decrement by
|
33 | 32 | */
|
34 |
| - void Decrement(size_t size) { allocated_bytes_ -= size; } |
| 33 | + void Decrement(size_t size) { stats_.local().allocated_bytes_ -= size; } |
35 | 34 |
|
36 | 35 | 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 | + }; |
38 | 43 | tbb::enumerable_thread_specific<Stats> stats_;
|
39 |
| - // number of bytes allocated |
40 |
| - size_t allocated_bytes_; |
41 | 44 | };
|
42 | 45 |
|
43 | 46 | } // namespace noisepage::execution::sql
|
0 commit comments