Python tracemalloc.get_tracemalloc_memory() Examples
The following are 7
code examples of tracemalloc.get_tracemalloc_memory().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tracemalloc
, or try the search function
.
Example #1
Source File: debug.py From zulip with Apache License 2.0 | 6 votes |
def tracemalloc_dump() -> None: if not tracemalloc.is_tracing(): logger.warning("pid %s: tracemalloc off, nothing to dump", os.getpid()) return # Despite our name for it, `timezone_now` always deals in UTC. basename = "snap.{}.{}".format(os.getpid(), timezone_now().strftime("%F-%T")) path = os.path.join(settings.TRACEMALLOC_DUMP_DIR, basename) os.makedirs(settings.TRACEMALLOC_DUMP_DIR, exist_ok=True) gc.collect() tracemalloc.take_snapshot().dump(path) with open(f'/proc/{os.getpid()}/stat', 'rb') as f: procstat = f.read().split() rss_pages = int(procstat[23]) logger.info("tracemalloc dump: tracing %s MiB (%s MiB peak), using %s MiB; rss %s MiB; dumped %s", tracemalloc.get_traced_memory()[0] // 1048576, tracemalloc.get_traced_memory()[1] // 1048576, tracemalloc.get_tracemalloc_memory() // 1048576, rss_pages // 256, basename)
Example #2
Source File: test_tracemalloc.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_get_tracemalloc_memory(self): data = [allocate_bytes(123) for count in range(1000)] size = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size, 0) tracemalloc.clear_traces() size2 = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size2, 0) self.assertLessEqual(size2, size)
Example #3
Source File: test_tracemalloc.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_get_tracemalloc_memory(self): data = [allocate_bytes(123) for count in range(1000)] size = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size, 0) tracemalloc.clear_traces() size2 = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size2, 0) self.assertLessEqual(size2, size)
Example #4
Source File: allocation_profiler.py From stackimpact-python with BSD 3-Clause "New" or "Revised" License | 5 votes |
def start_profiler(self): self.agent.log('Activating memory allocation profiler.') def start(): tracemalloc.start(self.MAX_TRACEBACK_SIZE) self.agent.run_in_main_thread(start) self.start_ts = time.time() def monitor_overhead(): if tracemalloc.is_tracing() and tracemalloc.get_tracemalloc_memory() > self.MAX_MEMORY_OVERHEAD: self.agent.log('Allocation profiler memory overhead limit exceeded: {0} bytes'.format(tracemalloc.get_tracemalloc_memory())) self.stop_profiler() self.overhead_monitor = self.agent.schedule(0.5, 0.5, monitor_overhead)
Example #5
Source File: allocation_profiler.py From stackimpact-python with BSD 3-Clause "New" or "Revised" License | 5 votes |
def stop_profiler(self): self.agent.log('Deactivating memory allocation profiler.') with self.profile_lock: if self.overhead_monitor: self.overhead_monitor.cancel() self.overhead_monitor = None if tracemalloc.is_tracing(): snapshot = tracemalloc.take_snapshot() self.agent.log('Allocation profiler memory overhead {0} bytes'.format(tracemalloc.get_tracemalloc_memory())) tracemalloc.stop() self.process_snapshot(snapshot, time.time() - self.start_ts)
Example #6
Source File: test_tracemalloc.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_get_tracemalloc_memory(self): data = [allocate_bytes(123) for count in range(1000)] size = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size, 0) tracemalloc.clear_traces() size2 = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size2, 0) self.assertLessEqual(size2, size)
Example #7
Source File: test_tracemalloc.py From android_universal with MIT License | 5 votes |
def test_get_tracemalloc_memory(self): data = [allocate_bytes(123) for count in range(1000)] size = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size, 0) tracemalloc.clear_traces() size2 = tracemalloc.get_tracemalloc_memory() self.assertGreaterEqual(size2, 0) self.assertLessEqual(size2, size)