| Index: third_party/tcmalloc/chromium/src/call_stack_table.h
|
| diff --git a/third_party/tcmalloc/chromium/src/call_stack_table.h b/third_party/tcmalloc/chromium/src/call_stack_table.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5bc77bb78f60a9ff7d10caa7c3ec8e255b9b3a93
|
| --- /dev/null
|
| +++ b/third_party/tcmalloc/chromium/src/call_stack_table.h
|
| @@ -0,0 +1,89 @@
|
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// ---
|
| +// Author: Simon Que
|
| +
|
| +#ifndef _CALL_STACK_TABLE_H_
|
| +#define _CALL_STACK_TABLE_H_
|
| +
|
| +#include <unordered_map>
|
| +#include <functional>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/custom_allocator.h"
|
| +#include "base/stl_allocator.h"
|
| +#include "heap-profile-stats.h"
|
| +#include "leak_analyzer.h"
|
| +
|
| +namespace leak_detector {
|
| +
|
| +// Contains a hash table where the key is the call stack and the value is the
|
| +// number of allocations from that call stack.
|
| +class CallStackTable {
|
| + public:
|
| + // Represents a unique call stack.
|
| + using CallStack = HeapProfileBucket;
|
| +
|
| + struct Hash {
|
| + long operator() (const CallStack* call_stack) const {
|
| + // The call stack object should already have a hash computed when it was
|
| + // created.
|
| + return call_stack->hash;
|
| + }
|
| + };
|
| +
|
| + CallStackTable();
|
| + ~CallStackTable();
|
| +
|
| + // Add/Remove an allocation for the given call stack.
|
| + void Add(const CallStack* call_stack);
|
| + void Remove(const CallStack* call_stack);
|
| +
|
| + // Dump contents to log buffer |buffer| of size |size|.
|
| + int Dump(char* buffer, int size) const;
|
| +
|
| + // Check for leak patterns in the allocation data.
|
| + void TestForLeaks();
|
| +
|
| + const LeakAnalyzer<const CallStack*>& leak_analyzer() const {
|
| + return leak_analyzer_;
|
| + }
|
| +
|
| + private:
|
| + // Hash table entry used to track number of allocs and frees for a call stack.
|
| + // Do not use the fields of struct HeapProfileBucket for this purpose; one
|
| + // call stack object can have different entries in multiple CallStackTables.
|
| + struct Entry {
|
| + // Number of allocs/frees for the call stack.
|
| + uint32 num_allocs;
|
| + uint32 num_frees;
|
| + };
|
| +
|
| + // The total number of recorded allocations when this object was created. This
|
| + // acts as a timestamp of sorts.
|
| + uint64_t total_num_allocs_at_creation_;
|
| +
|
| + // Total number of allocs and frees in this table.
|
| + uint32 num_allocs_;
|
| + uint32 num_frees_;
|
| +
|
| + // Hash table containing entries.
|
| + using TableEntryAllocator =
|
| + STL_Allocator<std::pair<const CallStack*, Entry>, CustomAllocator>;
|
| + std::unordered_map<const CallStack*,
|
| + Entry,
|
| + Hash,
|
| + std::equal_to<const CallStack*>,
|
| + TableEntryAllocator> entry_map_;
|
| +
|
| + // For detecting leak patterns in incoming allocations.
|
| + LeakAnalyzer<const CallStack*> leak_analyzer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CallStackTable);
|
| +};
|
| +
|
| +} // namespace leak_detector
|
| +
|
| +#endif // _CALL_STACK_TABLE_H_
|
|
|