示例#1
0
    def test_new_reference(self):
        tracemalloc.clear_traces()
        # gc.collect() indirectly calls PyList_ClearFreeList()
        support.gc_collect()

        # Create a list and "destroy it": put it in the PyListObject free list
        obj = []
        obj = None

        # Create a list which should reuse the previously created empty list
        obj = []

        nframe = tracemalloc.get_traceback_limit()
        frames = get_frames(nframe, -3)
        obj_traceback = tracemalloc.Traceback(frames, min(len(frames), nframe))

        traceback = tracemalloc.get_object_traceback(obj)
        self.assertIsNotNone(traceback)
        self.assertEqual(traceback, obj_traceback)
    def display(self, count=10, group_by="line", cumulative=False, file=None,
                callback=None):
        if group_by == 'address':
            traces = True
        elif cumulative:
            traces = (tracemalloc.get_traceback_limit() > 1)
        else:
            traces = False
        snapshot = tracemalloc.Snapshot.create(traces=traces)
        if self.metrics:
            add_metrics(snapshot)
        if callback is not None:
            callback(snapshot)

        self.display_snapshot(snapshot,
                              count=count,
                              group_by=group_by,
                              cumulative=cumulative,
                              file=file)
        return snapshot
示例#3
0
def allocate_bytes(size):
    nframe = tracemalloc.get_traceback_limit()
    bytes_len = (size - EMPTY_STRING_SIZE)
    frames = get_frames(nframe, 1)
    data = b'x' * bytes_len
    return data, tracemalloc.Traceback(frames)
示例#4
0
文件: nodes.py 项目: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(0, tracemalloc.get_traceback_limit())
示例#5
0
def allocate_bytes(size):
    nframe = tracemalloc.get_traceback_limit()
    bytes_len = (size - EMPTY_STRING_SIZE)
    frames = get_frames(nframe, 1)
    data = b'x' * bytes_len
    return data, tracemalloc.Traceback(frames)
示例#6
0
            )
        elif incomplete:
            print('\n'.join(tracemalloc.Traceback(incomplete[0]).format()))
            print('  ...')
        else:
            print('no traceback found')

    # abbreviations
    do_q = do_quit
    do_l = do_list
    do_n = do_next
    do_p = do_print
    do_tb = do_traceback


if __name__ == '__main__':
    if not tracemalloc.is_tracing():
        sys.exit('specify tracing depth using -X tracemalloc=N')
    del sys.argv[0]
    path = sys.argv[0]
    with open(path, 'r') as f:
        src = f.read()
    code = compile(src, path, 'exec')
    gc.set_debug(gc.DEBUG_SAVEALL)
    print('executing {} tracing at depth {}'.format(
        path, tracemalloc.get_traceback_limit()))
    try:
        exec(code)
    finally:
        explore_cycles()
示例#7
0
fname = 'E:/var/log/ulex/interface_18010.log'
with open(fname) as words:
    words = list(words)
    for Word in words:
        prefix = Word[:30]
        counts[prefix] += 1
#print('Top prefixes:', counts.most_common(30))

#snapshot = tracemalloc.take_snapshot()
#display_top(snapshot)

time2 = tracemalloc.take_snapshot().filter_traces((
    tracemalloc.Filter(False, "<frozen importlib._bootstrap>"),
    tracemalloc.Filter(False, "<frozen importlib._bootstrap_external>"),
    tracemalloc.Filter(False, "<unknown>"),
))

stats = time2.compare_to(time1, 'filename')

print(tracemalloc.get_traced_memory())
print(tracemalloc.get_traceback_limit())

for stat in stats:
    print(stat)
    #print(stat.traceback.format())

'''top_stat = time2.statistics('traceback')
stats = iter(top_stat)
for stat in stats:
    print(stat.traceback.format())'''