[MemTracker] make all MemTrackers shared (#4135)

We make all MemTrackers shared, in order to show MemTracker real-time consumptions on the web.
As follows:
1. nearly all MemTracker raw ptr -> shared_ptr
2. Use CreateTracker() to create new MemTracker(in order to add itself to its parent)
3. RowBatch & MemPool still use raw ptrs of MemTracker, it's easy to ensure RowBatch & MemPool destructor exec 
     before MemTracker's destructor. So we don't change these code.
4. MemTracker can use RuntimeProfile's counter to calc consumption. So RuntimeProfile's counter need to be shared 
    too. We add a shared counter pool to store the shared counter, don't change other counters of RuntimeProfile.
Note that, this PR doesn't change the MemTracker tree structure. So there still have some orphan trackers, e.g. RowBlockV2's MemTracker. If you find some shared MemTrackers are little memory consumption & too time-consuming, you could make them be the orphan, then it's fine to use the raw ptr.
This commit is contained in:
HuangWei
2020-07-31 21:57:21 +08:00
committed by GitHub
parent f412f99511
commit 10f822eb43
209 changed files with 2137 additions and 1845 deletions

View File

@ -51,13 +51,13 @@ ExprContext::~ExprContext() {
// TODO(zc): memory tracker
Status ExprContext::prepare(RuntimeState* state, const RowDescriptor& row_desc,
MemTracker* tracker) {
DCHECK(tracker != NULL) << std::endl << get_stack_trace();
const std::shared_ptr<MemTracker>& tracker) {
DCHECK(tracker != nullptr) << std::endl << get_stack_trace();
DCHECK(_pool.get() == NULL);
_prepared = true;
// TODO: use param tracker to replace instance_mem_tracker
// TODO: use param tracker to replace instance_mem_tracker, be careful about tracker's life cycle
// _pool.reset(new MemPool(new MemTracker(-1)));
_pool.reset(new MemPool(state->instance_mem_tracker()));
_pool.reset(new MemPool(state->instance_mem_tracker().get()));
return _root->prepare(state, row_desc, this);
}