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

Side by Side Diff: tools/android/heap_profiler/heap_profiler.h

Issue 323893002: [Android] Introduce libheap_profiler for memory profiling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/hdump/heap_dump/, simplify JSON, refactor heap_dump main Created 6 years, 6 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef TOOLS_ANDROID_HEAP_PROFILER_HEAP_PROFILER_H_
6 #define TOOLS_ANDROID_HEAP_PROFILER_HEAP_PROFILER_H_
7
8 #include <stdint.h>
9 #include "tools/android/heap_profiler/third_party/bsd-trees/tree.h"
10
11 #define HEAP_PROFILER_MAGIC_MARKER 0x42beef42L
12 #define HEAP_PROFILER_MAX_DEPTH 12
13 #define HEAP_PROFILER_EXPORT __attribute__((visibility("default")))
14
15 // The allocated vma is a result of a system malloc() invocation.
16 #define HEAP_PROFILER_FLAGS_MALLOC 1
17
18 // The allocation vma is a result of a mmap() invocation.
19 #define HEAP_PROFILER_FLAGS_MMAP 2 // Allocation performed through mmap.
20
21 // Only in the case of FLAGS_MMAP: The mmap is not anonymous (i.e. file backed).
22 #define HEAP_PROFILER_FLAGS_MMAP_FILE 4
23
24 // Android only: allocation made by the Zygote (before forking).
25 #define HEAP_PROFILER_FLAGS_IN_ZYGOTE 8
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 typedef struct StacktraceEntry {
33 uintptr_t frames[HEAP_PROFILER_MAX_DEPTH]; // Absolute addrs of stack frames.
34 uint32_t hash; // H(frames), used to keep these entries in a hashtable.
35
36 // Total number of bytes allocated through this code path. It is equal to the
37 // sum of VMA instances' length which .bt == this.
pasko 2014/06/10 16:59:52 nit: second sentence in this comment just repeats
38 size_t alloc_bytes;
39
40 // |next| has a dual purpose. When the entry is used (hence in the hashtable),
41 // this is a ptr to the next item in the same bucket. When the entry is free,
42 // this is a ptr to the next entry in the freelist.
43 struct StacktraceEntry* next;
44 } StacktraceEntry;
45
46 // Represents a contiguous range of virtual memory which has been allocated by
47 // a give code path (identified by the corresponding StacktraceEntry).
48 typedef struct VMA {
49 RB_ENTRY(VMA) rb_node; // Anchor for the RB-tree;
50 uintptr_t start;
51 uintptr_t end;
52 uint32_t flags; // See HEAP_PROFILER_FLAGS_*.
53 StacktraceEntry* st; // NULL == free entry.
54 struct VMA* next_free;
55 } VMA;
56
57 typedef struct {
58 uint32_t magic_start; // The magic marker used by hdump to discover the area.
59 uint32_t num_allocs; // The total number of allocation entries present.
60 uint32_t max_allocs; // The max number of items in |allocs|.
61 uint32_t num_stack_traces; // The total number of stack traces present.
62 uint32_t max_stack_traces; // The max number of items in |stack_traces|.
63 size_t total_alloc_bytes; // Total allocation bytes tracked.
64 VMA* allocs; // Start of the the VMA pool.
65 StacktraceEntry* stack_traces; // Start of the StacktraceEntry pool.
66 } HeapStats;
67
68 // The API is exported in order to be accessed from custom allocators.
69
70 // Initialize the heap_profiler. The caller has to allocate the HeapStats
71 // "superblock", since the way it is mapped is platform-specific.
72 HEAP_PROFILER_EXPORT void heap_profiler_init(HeapStats* heap_stats);
73
74 // Records and allocation. The caller must unwind the stack and pass the
75 // frames array. Flags are optionals and don't affect the behavior of the
76 // library (they're just kept along and dumped).
77 HEAP_PROFILER_EXPORT void heap_profiler_alloc(
78 void* addr, size_t size, uintptr_t* frames, uint32_t depth, uint32_t flags);
79
80 // Frees any allocation (even partial) overlapping with the given range.
81 // If old_flags != NULL, it will be filled with the flags of the deleted VMAs.
82 HEAP_PROFILER_EXPORT void heap_profiler_free(
83 void* addr, size_t size, uint32_t* old_flags);
84
85 // Cleans up the HeapStats and all the internal data structures.
86 HEAP_PROFILER_EXPORT void heap_profiler_cleanup(void);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif // TOOLS_ANDROID_HEAP_PROFILER_HEAP_PROFILER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698