def snapshot(self) -> object: """Produce a comparable snapshot of this Option""" # Under mypyc, we don't have a __dict__, so we need to do worse things. d = dict(getattr(self, '__dict__', ())) for k in get_class_descriptors(Options): if hasattr(self, k): d[k] = getattr(self, k) del d['per_module_cache'] return d
def snapshot(self) -> object: """Produce a comparable snapshot of this Option""" # Under mypyc, we don't have a __dict__, so we need to do worse things. d = dict(getattr(self, '__dict__', ())) for k in get_class_descriptors(Options): if hasattr(self, k): d[k] = getattr(self, k) del d['per_module_cache'] return d
def snapshot(self) -> object: """Produce a comparable snapshot of this Option""" # Under mypyc, we don't have a __dict__, so we need to do worse things. d = dict(getattr(self, '__dict__', ())) for k in get_class_descriptors(Options): if hasattr(self, k) and k != "new_semantic_analyzer": d[k] = getattr(self, k) # Remove private attributes from snapshot d = {k: v for k, v in d.items() if not k.startswith('_')} return d
def collect_memory_stats() -> Tuple[Dict[str, int], Dict[str, int]]: """Return stats about memory use. Return a tuple with these items: - Dict from object kind to number of instances of that kind - Dict from object kind to total bytes used by all instances of that kind """ objs = gc.get_objects() find_recursive_objects(objs) inferred = {} for obj in objs: if type(obj) is FakeInfo: # Processing these would cause a crash. continue n = type(obj).__name__ if hasattr(obj, '__dict__'): # Keep track of which class a particular __dict__ is associated with. inferred[id(obj.__dict__)] = '%s (__dict__)' % n if isinstance(obj, (Node, Type)): # type: ignore if hasattr(obj, '__dict__'): for x in obj.__dict__.values(): if isinstance(x, list): # Keep track of which node a list is associated with. inferred[id(x)] = '%s (list)' % n if isinstance(x, tuple): # Keep track of which node a list is associated with. inferred[id(x)] = '%s (tuple)' % n for k in get_class_descriptors(type(obj)): x = getattr(obj, k, None) if isinstance(x, list): inferred[id(x)] = '%s (list)' % n if isinstance(x, tuple): inferred[id(x)] = '%s (tuple)' % n freqs = {} # type: Dict[str, int] memuse = {} # type: Dict[str, int] for obj in objs: if id(obj) in inferred: name = inferred[id(obj)] else: name = type(obj).__name__ freqs[name] = freqs.get(name, 0) + 1 memuse[name] = memuse.get(name, 0) + sys.getsizeof(obj) return freqs, memuse
def collect_memory_stats() -> Tuple[Dict[str, int], Dict[str, int]]: """Return stats about memory use. Return a tuple with these items: - Dict from object kind to number of instances of that kind - Dict from object kind to total bytes used by all instances of that kind """ objs = gc.get_objects() find_recursive_objects(objs) inferred = {} for obj in objs: if type(obj) is FakeInfo: # Processing these would cause a crash. continue n = type(obj).__name__ if hasattr(obj, '__dict__'): # Keep track of which class a particular __dict__ is associated with. inferred[id(obj.__dict__)] = '%s (__dict__)' % n if isinstance(obj, (Node, Type)): if hasattr(obj, '__dict__'): for x in obj.__dict__.values(): if isinstance(x, list): # Keep track of which node a list is associated with. inferred[id(x)] = '%s (list)' % n for k in get_class_descriptors(type(obj)): x = getattr(obj, k, None) if isinstance(x, list): inferred[id(x)] = '%s (list)' % n freqs = {} # type: Dict[str, int] memuse = {} # type: Dict[str, int] for obj in objs: if id(obj) in inferred: name = inferred[id(obj)] else: name = type(obj).__name__ freqs[name] = freqs.get(name, 0) + 1 memuse[name] = memuse.get(name, 0) + sys.getsizeof(obj) return freqs, memuse