Example #1
0
def _init_leak_detection() -> None:
    # Initialize trace malloc to track up to 25 stack frames.
    tracemalloc.start(25)
    if sys.version_info >= (3, 9):
        # Nice to reset peak to 0. Available for versions >= 3.9.
        tracemalloc.reset_peak()
    # Enable leak debugging in the garbage collector.
    gc.set_debug(gc.DEBUG_LEAK)
Example #2
0
def process(directory, output, compression):
    # Read Files
    files = [
        f"{directory}/{file}" for file in os.listdir(directory)
        if file.endswith(("csv", ))
    ]

    # Process
    for path in files:
        now = time.time()
        tracemalloc.start()

        f = File(path, compression=compression, destination=output)
        del f

        current, peak = tracemalloc.get_traced_memory()
        print(path, ",", peak / (10**6), ",", (time.time() - now) / 1000, ',',
              os.path.getsize(path))
        # print(f"Current memory usage is {current / (10**6)}MB; Peak was {peak / (10**6)}MB")
        tracemalloc.stop()
        # print("TOTAL TIME:", )
        tracemalloc.reset_peak()
Example #3
0
    def test_reset_peak(self):
        # Python allocates some internals objects, so the test must tolerate
        # a small difference between the expected size and the real usage
        tracemalloc.clear_traces()

        # Example: allocate a large piece of memory, temporarily
        large_sum = sum(list(range(100000)))
        size1, peak1 = tracemalloc.get_traced_memory()

        # reset_peak() resets peak to traced memory: peak2 < peak1
        tracemalloc.reset_peak()
        size2, peak2 = tracemalloc.get_traced_memory()
        self.assertGreaterEqual(peak2, size2)
        self.assertLess(peak2, peak1)

        # check that peak continue to be updated if new memory is allocated:
        # peak3 > peak2
        obj_size = 1024 * 1024
        obj, obj_traceback = allocate_bytes(obj_size)
        size3, peak3 = tracemalloc.get_traced_memory()
        self.assertGreaterEqual(peak3, size3)
        self.assertGreater(peak3, peak2)
        self.assertGreaterEqual(peak3 - peak2, obj_size)
Example #4
0
 def update_event(self, inp=-1):
     self.set_output_val(0, tracemalloc.reset_peak())
Example #5
0
n = "\n"
print(
#    unvivtool.__doc__, n,
    unvivtool, n,
    dir(unvivtool), n,

    flush=True
)


# tracemalloc -- BEGIN ---------------------------------------------------------
# tracemalloc.stop()
first_size, first_peak = tracemalloc.get_traced_memory()

if sys.version_info[0:2] >= (3, 9):
    tracemalloc.reset_peak()

tracemalloc.start()
# tracemalloc -- END -----------------------------------------------------------


count_successful_tests = 0
print("")

# Decode
if args.cmd[0] == "d":
    vivfile = "tests/car.viv"
    outdir = "tests"
    request_fileid = 2            # optional
    request_filename = "LICENSE"  # optional, overrides request_fileid