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

Commit

Permalink
Fix Memory Tracking Issue (#1250) (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
17zhangw authored Oct 25, 2020
1 parent d70c1c1 commit 12c2203
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/include/execution/sql/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> stats_;
// number of bytes allocated
size_t allocated_bytes_;
};

} // namespace noisepage::execution::sql

0 comments on commit 12c2203

Please sign in to comment.