/Users/deen/code/yugabyte-db/src/yb/util/allocation_tracker.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | |
16 | | #include "yb/util/allocation_tracker.h" |
17 | | |
18 | | #include <glog/logging.h> |
19 | | |
20 | | #include "yb/util/debug-util.h" |
21 | | |
22 | | namespace yb { |
23 | | |
24 | 0 | AllocationTrackerBase::~AllocationTrackerBase() { |
25 | 0 | #ifndef NDEBUG |
26 | 0 | std::lock_guard<std::mutex> lock(mutex_); |
27 | 0 | for (auto& pair : objects_) { |
28 | 0 | LOG(ERROR) << "Error of type " << name_ << " not destroyed, id: " << pair.second.second |
29 | 0 | << ", created at: " << pair.second.first; |
30 | 0 | } |
31 | | #else |
32 | | if (count_) { |
33 | | LOG(ERROR) << "Not all objects of type " << name_ << " were destroyed, " |
34 | | << count_ << " objects left"; |
35 | | } |
36 | | #endif |
37 | 0 | } |
38 | | |
39 | 0 | void AllocationTrackerBase::DoCreated(void* object) { |
40 | 0 | LOG(INFO) << "Created " << name_ << ": " << object; |
41 | 0 | #ifndef NDEBUG |
42 | 0 | std::lock_guard<std::mutex> lock(mutex_); |
43 | 0 | objects_.emplace(object, |
44 | 0 | std::make_pair(GetStackTrace(StackTraceLineFormat::CLION_CLICKABLE), |
45 | 0 | ++id_)); |
46 | | #else |
47 | | ++count_; |
48 | | #endif |
49 | 0 | } |
50 | | |
51 | 0 | void AllocationTrackerBase::DoDestroyed(void* object) { |
52 | 0 | LOG(INFO) << "Destroyed " << name_ << ": " << object; |
53 | 0 | #ifndef NDEBUG |
54 | 0 | std::lock_guard<std::mutex> lock(mutex_); |
55 | 0 | objects_.erase(object); |
56 | | #else |
57 | | --count_; |
58 | | #endif |
59 | 0 | } |
60 | | |
61 | | } // namespace yb |