Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: base/allocator/allocator_extension.h

Issue 1665553002: metrics: Connect leak detector to allocator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test for allocator hook registration Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ 5 #ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
6 #define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ 6 #define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
7 7
8 #include <stddef.h> // for size_t 8 #include <stddef.h> // for size_t
9 9
10 #include <type_traits> // for std::add_pointer
11
10 #include "base/base_export.h" 12 #include "base/base_export.h"
11 #include "build/build_config.h" 13 #include "build/build_config.h"
12 14
13 namespace base { 15 namespace base {
14 namespace allocator { 16 namespace allocator {
15 17
18 // Callback types for alloc and free.
19 using AllocHookFunc = std::add_pointer<void(const void*, size_t)>::type;
Primiano Tucci (use gerrit) 2016/03/01 18:54:37 What is the benefit of std::add_pointer as opposit
20 using FreeHookFunc = std::add_pointer<void(const void*)>::type;
21
16 // Request that the allocator release any free memory it knows about to the 22 // Request that the allocator release any free memory it knows about to the
17 // system. 23 // system.
18 BASE_EXPORT void ReleaseFreeMemory(); 24 BASE_EXPORT void ReleaseFreeMemory();
19 25
20 // Get the named property's |value|. Returns true if the property is known. 26 // Get the named property's |value|. Returns true if the property is known.
21 // Returns false if the property is not a valid property name for the current 27 // Returns false if the property is not a valid property name for the current
22 // allocator implementation. 28 // allocator implementation.
23 // |name| or |value| cannot be NULL 29 // |name| or |value| cannot be NULL
24 BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value); 30 BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value);
25 31
26 BASE_EXPORT bool IsHeapProfilerRunning(); 32 BASE_EXPORT bool IsHeapProfilerRunning();
27 33
34 // Register callbacks for alloc and free. Can only store one callback at a time
35 // for each of alloc and free. Returns the previously stored hook function, or
36 // nullptr if none was stored.
37 BASE_EXPORT AllocHookFunc SetSingleAllocHook(AllocHookFunc func);
Primiano Tucci (use gerrit) 2016/03/01 18:54:37 I'd drop Single from the name. The fact that you h
38 BASE_EXPORT FreeHookFunc SetSingleFreeHook(FreeHookFunc func);
39
40 // Returns the currently stored alloc/free callbacks that were registered by
41 // calling SetSingle{Alloc,Free}Hook().
42 BASE_EXPORT AllocHookFunc GetSingleAllocHook();
43 BASE_EXPORT FreeHookFunc GetSingleFreeHook();
44
45 // Attempts to unwind the call stack from the current location where this
46 // function is being called from. Must be called from a hook function registered
47 // by calling SetSingle{Alloc,Free}Hook, directly or indirectly.
48 //
49 // Arguments:
50 // stack: pointer to a pre-allocated array of void*'s.
51 // max_stack_size: indicates the size of the array in |stack|.
52 // skip_count: Indicates how many initial call stack levels to skip before
Primiano Tucci (use gerrit) 2016/03/01 18:54:36 It looks like this is really not used in the .cc f
53 // storing the caller of alloc/free. This value might not be
54 // used, depending on the specific implementation.
55 //
56 // Returns the number of call stack frames stored in |stack|, or 0 if no call
57 // stack information is available.
58 BASE_EXPORT int GetCallStack(void** stack, int max_stack_size, int skip_count);
59
28 } // namespace allocator 60 } // namespace allocator
29 } // namespace base 61 } // namespace base
30 62
31 #endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ 63 #endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
OLDNEW
« no previous file with comments | « no previous file | base/allocator/allocator_extension.cc » ('j') | base/allocator/allocator_extension.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698