[MemSheriff] More sendto parameter issues.
[chromium-blink-merge.git] / tools / deep_memory_profiler / lib / dump.py
blob798763a1f529691bf86a91a6a9cd3aac4ffbd1b2
1 # Copyright 2013 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.
5 import logging
6 import os
9 LOGGER = logging.getLogger('dmprof')
12 class Dump(object):
13 """Represents a heap profile dump."""
14 def __init__(self):
15 pass
17 @property
18 def path(self):
19 raise NotImplementedError
21 @property
22 def count(self):
23 raise NotImplementedError
25 @property
26 def time(self):
27 raise NotImplementedError
29 @property
30 def iter_map(self):
31 raise NotImplementedError
33 @property
34 def iter_stacktrace(self):
35 raise NotImplementedError
37 def global_stat(self, name):
38 raise NotImplementedError
40 @property
41 def run_id(self):
42 raise NotImplementedError
44 @property
45 def pagesize(self):
46 raise NotImplementedError
48 @property
49 def pageframe_length(self):
50 raise NotImplementedError
52 @property
53 def pageframe_encoding(self):
54 raise NotImplementedError
56 @property
57 def has_pagecount(self):
58 raise NotImplementedError
60 @staticmethod
61 def load(path, log_header='Loading a heap profile dump: '):
62 """Loads a heap profile dump.
64 Args:
65 path: A file path string to load.
66 log_header: A preceding string for log messages.
68 Returns:
69 A loaded Dump object.
71 Raises:
72 ParsingException for invalid heap profile dumps.
73 """
74 from lib.deep_dump import DeepDump
75 dump = DeepDump(path, os.stat(path).st_mtime)
76 with open(path, 'r') as f:
77 dump.load_file(f, log_header)
78 return dump
81 class DumpList(object):
82 """Represents a sequence of heap profile dumps.
84 Individual dumps are loaded into memory lazily as the sequence is accessed,
85 either while being iterated through or randomly accessed. Loaded dumps are
86 not cached, meaning a newly loaded Dump object is returned every time an
87 element in the list is accessed.
88 """
90 def __init__(self, dump_path_list):
91 self._dump_path_list = dump_path_list
93 @staticmethod
94 def load(path_list):
95 return DumpList(path_list)
97 def __len__(self):
98 return len(self._dump_path_list)
100 def __iter__(self):
101 for dump in self._dump_path_list:
102 yield Dump.load(dump)
104 def __getitem__(self, index):
105 return Dump.load(self._dump_path_list[index])