| 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..e5ce921d277691caf3e3906056a427acad7d66a3
|
| --- /dev/null
|
| +++ b/third_party/tcmalloc/chromium/src/call_stack_table.h
|
| @@ -0,0 +1,104 @@
|
| +// 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/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 bucket and the value is
|
| +// the number of allocations from that call stack.
|
| +class CallStackTable {
|
| + public:
|
| + // Local allocation function pointer types.
|
| + typedef void* (*Allocator)(size_t size);
|
| + typedef void (*DeAllocator)(void* ptr);
|
| +
|
| + // Bucket that represents a unique call stack.
|
| + using Bucket = HeapProfileBucket;
|
| +
|
| + class Alloc {
|
| + public:
|
| + static void Init(Allocator alloc, DeAllocator dealloc);
|
| + static void* Allocate(size_t size);
|
| + static void Free(void* ptr, size_t size);
|
| +
|
| + private:
|
| + static Allocator alloc_;
|
| + static DeAllocator dealloc_;
|
| + };
|
| +
|
| + struct Hash {
|
| + long operator() (const Bucket* bucket) const {
|
| + return bucket->hash;
|
| + }
|
| + };
|
| +
|
| + CallStackTable(Allocator alloc, DeAllocator dealloc);
|
| + ~CallStackTable();
|
| +
|
| + // Add/Remove an allocation for the given call stack bucket.
|
| + void Add(const Bucket* ptr);
|
| + void Remove(const Bucket* ptr);
|
| +
|
| + // 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 Bucket*>& leak_analyzer() const {
|
| + return leak_analyzer_;
|
| + }
|
| +
|
| + private:
|
| + // Hash table entry used to track number of allocs and frees for a call stack.
|
| + // We don't want to reuse the HeapProfileBucket struct for this because it
|
| + // requires too much space by storing a full call stack. Instead, this custom
|
| + // struct contains a pointer to an existing HeapProfileBucket (alias Bucket).
|
| + 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_;
|
| +
|
| + // For local allocation.
|
| + Allocator alloc_;
|
| + DeAllocator dealloc_;
|
| + using TableEntryAllocator =
|
| + STL_Allocator<std::pair<const Bucket*, Entry>, Alloc>;
|
| + std::unordered_map<const Bucket*,
|
| + Entry,
|
| + Hash,
|
| + std::equal_to<const Bucket*>,
|
| + TableEntryAllocator> entry_map_;
|
| +
|
| + // For detecting leak patterns in incoming allocations.
|
| + LeakAnalyzer<const Bucket*> leak_analyzer_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CallStackTable);
|
| +};
|
| +
|
| +} // namespace leak_detector
|
| +
|
| +#endif // _CALL_STACK_TABLE_H_
|
|
|