本文整理汇总了Python中tracemalloc.start方法的典型用法代码示例。如果您正苦于以下问题:Python tracemalloc.start方法的具体用法?Python tracemalloc.start怎么用?Python tracemalloc.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracemalloc
的用法示例。
在下文中一共展示了tracemalloc.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_main
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def profile_main():
"""
:return:
"""
log.info("Profiling: ENABLED")
# Enable memory usage profiling at the line level
tracemalloc.start()
# Enable CPU usage/function call timing/rate at the function level
# Automatigically dumps profile to `filename` for further analysis
cProfile.run("main()", filename=(CWD + "/chimay-red.cprof"))
# Take snapshot of traced malloc profile
snapshot = tracemalloc.take_snapshot()
# Print snapshot statistics filtering for only `tracefiles`
display_top(snapshot, limit=20, modpaths=TRACEFILES)
return 0
示例2: test_trace
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_trace():
import tracemalloc
tracemalloc.start(10)
time1 = tracemalloc.take_snapshot()
import pycorrector
c = pycorrector.correct('少先队员因该为老人让坐')
print(c)
time2 = tracemalloc.take_snapshot()
stats = time2.compare_to(time1, 'lineno')
print('*' * 32)
for stat in stats[:3]:
print(stat)
stats = time2.compare_to(time1, 'traceback')
print('*' * 32)
for stat in stats[:3]:
print(stat.traceback.format())
示例3: tracemalloc_state
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def tracemalloc_state(enabled=True):
orig_enabled = tracemalloc.is_tracing()
def set_enabled(new_enabled):
cur_enabled = tracemalloc.is_tracing()
if cur_enabled == new_enabled:
return
if new_enabled:
tracemalloc.start()
else:
tracemalloc.stop()
set_enabled(enabled)
try:
yield
finally:
set_enabled(orig_enabled)
示例4: test_set_traceback_limit
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_set_traceback_limit(self):
obj_size = 10
tracemalloc.stop()
self.assertRaises(ValueError, tracemalloc.start, -1)
tracemalloc.stop()
tracemalloc.start(10)
obj2, obj2_traceback = allocate_bytes(obj_size)
traceback = tracemalloc.get_object_traceback(obj2)
self.assertEqual(len(traceback), 10)
self.assertEqual(traceback, obj2_traceback)
tracemalloc.stop()
tracemalloc.start(1)
obj, obj_traceback = allocate_bytes(obj_size)
traceback = tracemalloc.get_object_traceback(obj)
self.assertEqual(len(traceback), 1)
self.assertEqual(traceback, obj_traceback)
示例5: test_get_traces_intern_traceback
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_get_traces_intern_traceback(self):
# dummy wrappers to get more useful and identical frames in the traceback
def allocate_bytes2(size):
return allocate_bytes(size)
def allocate_bytes3(size):
return allocate_bytes2(size)
def allocate_bytes4(size):
return allocate_bytes3(size)
# Ensure that two identical tracebacks are not duplicated
tracemalloc.stop()
tracemalloc.start(4)
obj_size = 123
obj1, obj1_traceback = allocate_bytes4(obj_size)
obj2, obj2_traceback = allocate_bytes4(obj_size)
traces = tracemalloc._get_traces()
trace1 = self.find_trace(traces, obj1_traceback)
trace2 = self.find_trace(traces, obj2_traceback)
size1, traceback1 = trace1
size2, traceback2 = trace2
self.assertEqual(traceback2, traceback1)
self.assertIs(traceback2, traceback1)
示例6: main
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
print("Warming up (to discount regex cache etc.)")
run()
tracemalloc.start(25)
gc.collect()
snapshot1 = tracemalloc.take_snapshot()
run()
gc.collect()
snapshot2 = tracemalloc.take_snapshot()
top_stats = snapshot2.compare_to(snapshot1, 'traceback')
print("Objects not released")
print("====================")
for stat in top_stats:
if "tracemalloc.py" in str(stat) or stat.size_diff == 0:
continue
print(stat)
for line in stat.traceback.format():
print(" ", line)
print("\nquickjs should not show up above.")
示例7: rev_comp_gene_calls_dict
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def rev_comp_gene_calls_dict(gene_calls_dict, contig_sequence):
contig_length = len(contig_sequence)
gene_caller_ids = list(gene_calls_dict.keys())
gene_caller_id_conversion_dict = dict([(gene_caller_ids[-i - 1], i) for i in range(0, len(gene_caller_ids))])
G = lambda g: gene_caller_id_conversion_dict[g]
reverse_complemented_gene_calls = {}
for gene_callers_id in gene_calls_dict:
g = copy.deepcopy(gene_calls_dict[gene_callers_id])
g['start'], g['stop'] = contig_length - g['stop'], contig_length - g['start']
g['direction'] = 'f' if g['direction'] == 'r' else 'r'
reverse_complemented_gene_calls[G(gene_callers_id)] = g
return reverse_complemented_gene_calls, gene_caller_id_conversion_dict
示例8: get_split_start_stops_without_gene_calls
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def get_split_start_stops_without_gene_calls(contig_length, split_length):
"""Returns split start stop locations for a given contig length."""
num_chunks = int(contig_length / split_length)
if num_chunks < 2:
return [(0, contig_length)]
chunks = []
for i in range(0, num_chunks):
chunks.append((i * split_length, (i + 1) * split_length),)
chunks.append(((i + 1) * split_length, contig_length),)
if (chunks[-1][1] - chunks[-1][0]) < (split_length / 2):
# last chunk is too small :/ merge it to the previous one.
last_tuple = (chunks[-2][0], contig_length)
chunks.pop()
chunks.pop()
chunks.append(last_tuple)
return chunks
示例9: is_this_name_OK_for_database
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def is_this_name_OK_for_database(variable_name, content, stringent=True, additional_chars_allowed=''):
if not content:
raise ConfigError("But the %s is empty? Come on :(" % variable_name)
if content[0] in constants.digits:
raise ConfigError("Sorry, %s can't start with a digit. Long story. Please specify a name "
"that starts with an ASCII letter." % variable_name)
if stringent:
allowed_chars = constants.allowed_chars.replace('.', '').replace('-', '')
else:
allowed_chars = constants.allowed_chars.replace('.', '')
if len(additional_chars_allowed):
allowed_chars += additional_chars_allowed
if len([c for c in content if c not in allowed_chars]):
raise ConfigError("Well, the %s contains characters that anvi'o does not like :/ Please limit the characters "
"to ASCII letters, digits, and the underscore ('_') character." % variable_name)
示例10: test
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test(self):
timings = []
memory_usage = []
tracemalloc.start()
for i in range(self.repeat):
before_memory = tracemalloc.take_snapshot()
start_time = time.time()
self.bench()
end_time = time.time()
after_memory = tracemalloc.take_snapshot()
timings.append(end_time - start_time)
memory_usage.append(sum([t.size for t in after_memory.compare_to(before_memory, 'filename')]))
print("time min:", min(timings), "max:", max(timings), "avg:", sum(timings) / len(timings)) # NOQA
print("memory min:", min(memory_usage), "max:", max(memory_usage), "avg:", sum(memory_usage) / len(memory_usage)) # NOQA
示例11: test_basic
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_basic(zipkin_url, client, loop):
endpoint = az.create_endpoint('simple_service', ipv4='127.0.0.1', port=80)
interval = 50
tracer = await az.create(zipkin_url, endpoint, sample_rate=1.0,
send_interval=interval, loop=loop)
with tracer.new_trace(sampled=True) as span:
span.name('root_span')
span.tag('span_type', 'root')
span.kind(az.CLIENT)
span.annotate('SELECT * FROM')
await asyncio.sleep(0.1)
span.annotate('start end sql')
# close forced sending data to server regardless of send interval
await tracer.close()
trace_id = span.context.trace_id
url = URL(zipkin_url).with_path('/zipkin/api/v2/traces')
data = await _retry_zipkin_client(url, client)
assert any(s['traceId'] == trace_id for trace in data for s in trace), data
示例12: test_leak_in_transport
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def test_leak_in_transport(zipkin_url, client, loop):
tracemalloc.start()
endpoint = az.create_endpoint('simple_service')
tracer = await az.create(zipkin_url, endpoint, sample_rate=1,
send_interval=0.0001, loop=loop)
await asyncio.sleep(5)
gc.collect()
snapshot1 = tracemalloc.take_snapshot()
await asyncio.sleep(10)
gc.collect()
snapshot2 = tracemalloc.take_snapshot()
top_stats = snapshot2.compare_to(snapshot1, 'lineno')
count = sum(s.count for s in top_stats)
await tracer.close()
assert count < 400 # in case of leak this number is around 901452
示例13: main
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
# change path to launcher
global __file__
__file__ = os.path.abspath(__file__)
if os.path.islink(__file__):
__file__ = getattr(os, 'readlink', lambda x: x)(__file__)
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# xlog.info("start XX-Net %s", current_version)
allow_remote = 0
restart_from_except = False
module_init.start_all_auto()
while True:
time.sleep(1)
示例14: memory_monitor
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def memory_monitor(command_queue: Queue, poll_interval=1):
tracemalloc.start()
old_max = 0
snapshot = None
while True:
try:
command_queue.get(timeout=poll_interval)
if snapshot is not None:
print(datetime.now())
display_top(snapshot)
return
except Empty:
max_rss = getrusage(RUSAGE_SELF).ru_maxrss
if max_rss > old_max:
old_max = max_rss
snapshot = tracemalloc.take_snapshot()
display_top(snapshot, limit=1)
print(datetime.now(), 'max RSS', old_max)
示例15: main
# 需要导入模块: import tracemalloc [as 别名]
# 或者: from tracemalloc import start [as 别名]
def main():
await bot.start()
await bot.run_until_disconnected()