diff --git a/src/include/execution/sql/memory_tracker.h b/src/include/execution/sql/memory_tracker.h index 58bbbce43b..867fd321f4 100644 --- a/src/include/execution/sql/memory_tracker.h +++ b/src/include/execution/sql/memory_tracker.h @@ -5,39 +5,42 @@ namespace noisepage::execution::sql { /** - * TODO: track memory usage + * Class for tracking memory on a per-thread granularity. + * Currently tracks allocation size in bytes during thread's execution. */ class EXPORT MemoryTracker { public: - // TODO(pmenon): Fill me in - /** * Reset tracker */ - void Reset() { allocated_bytes_ = 0; } + void Reset() { stats_.local().allocated_bytes_ = 0; } /** * @returns number of allocated bytes */ - size_t GetAllocatedSize() { return allocated_bytes_; } + size_t GetAllocatedSize() { return stats_.local().allocated_bytes_; } /** * Increments number of allocated bytes * @param size number to increment by */ - void Increment(size_t size) { allocated_bytes_ += size; } + void Increment(size_t size) { stats_.local().allocated_bytes_ += size; } /** * Decrements number of allocated bytes * @param size number to decrement by */ - void Decrement(size_t size) { allocated_bytes_ -= size; } + void Decrement(size_t size) { stats_.local().allocated_bytes_ -= size; } private: - struct Stats {}; + /** + * Struct to store per-thread tracking data. + */ + struct Stats { + // Number of bytes allocated + size_t allocated_bytes_ = 0; + }; tbb::enumerable_thread_specific stats_; - // number of bytes allocated - size_t allocated_bytes_; }; } // namespace noisepage::execution::sql