def fire_bursts(func, sub_test_name, lead_out=3): name_tag = "<" + sub_test_name + ">" print color.HEADER(test_name + " initiating " + sub_test_name) membase_start = func() mem_base = membase_start # Track heap behavior increases = 0 decreases = 0 constant = 0 for i in range(0, BURST_COUNT): print color.INFO(name_tag), " Run ", i + 1 memi = func() if memi > mem_base: memincrease = memi - mem_base increases += 1 elif memi == mem_base: memincrease = 0 constant += 1 else: memincrease = 0 decreases += 1 # We want to know how much each burst increases memory relative to the last burst mem_base = memi if memincrease > acceptable_increase: print color.WARNING( name_tag), "Memory increased by ", memincrease, "b, ", float( memincrease) / BURST_SIZE, "pr. packet \n" else: print color.OK(name_tag), "Memory increase ", memincrease, "b \n" # Memory can decrease, we don't care about that # if memincrease > 0: # mem_base += memincrease print color.INFO( name_tag ), "Heap behavior: ", "+", increases, ", -", decreases, ", ==", constant print color.INFO(name_tag), "Done. Checking for liveliness" if memory_increase(lead_out, membase_start) > acceptable_increase: print color.FAIL(sub_test_name + " failed ") return False print color.PASS(sub_test_name + " succeeded ") return True
def memory_increase(lead_time, expected_memuse=memuse_at_start): name_tag = "<" + test_name + "::memory_increase>" if lead_time: print color.INFO( name_tag ), "Checking for memory increase after a lead time of ", lead_time, "s." # Give the VM a chance to free up resources before asking time.sleep(lead_time) use = get_mem() increase = use - expected_memuse percent = 0.0 if (increase): percent = float(increase) / expected_memuse if increase > acceptable_increase: print color.WARNING(name_tag), "Memory increased by ", percent, "%." print "(", expected_memuse, "->", use, ",", increase, "b increase, but no increase expected.)" else: print color.OK(name_tag + "Memory constant, no leak detected") return increase