native_heap.py revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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 5from memory_inspector.core import stacktrace 6 7 8class NativeHeap(object): 9 """A snapshot of outstanding (i.e. not freed) native allocations. 10 11 This is typically obtained by calling |backends.Process|.DumpNativeHeap() 12 """ 13 14 def __init__(self): 15 self.allocations = [] 16 17 def Add(self, allocation): 18 assert(isinstance(allocation, Allocation)) 19 self.allocations += [allocation] 20 21 22class Allocation(object): 23 """A Native allocation, modeled in a size*count fashion. 24 25 |count| is the number of identical stack_traces which performed the allocation 26 of |size| bytes. 27 """ 28 29 def __init__(self, size, count, stack_trace): 30 assert(isinstance(stack_trace, stacktrace.Stacktrace)) 31 self.size = size # in bytes. 32 self.count = count 33 self.stack_trace = stack_trace 34 35 @property 36 def total_size(self): 37 return self.size * self.count 38 39 def __str__(self): 40 return '%d x %d : %s' % (self.count, self.size, self.stack_trace) 41