def test_read_bit_by_bit(): tmpfile = tempfile.NamedTemporaryFile(delete=False) vmprof.enable(tmpfile.fileno()) function_foo() vmprof.disable() tmpfile.close() stats = read_profile(tmpfile.name) stats.get_tree()
def test_line_profiling(): tmpfile = tempfile.NamedTemporaryFile(delete=False) vmprof.enable(tmpfile.fileno(), lines=True, native=False) # enable lines profiling function_foo() vmprof.disable() tmpfile.close() def walk(tree): assert len(tree.lines) >= len(tree.children) for v in six.itervalues(tree.children): walk(v) stats = read_profile(tmpfile.name) walk(stats.get_tree())
def test_line_profiling(): filename = "/Users/palpant/test.vmprof" with open(filename, "wb+") as fd: vmprof.enable(fd.fileno(), lines=True, native=False) # enable lines profiling function_foo() vmprof.disable() def walk(tree): assert len(tree.lines) >= len(tree.children) for v in six.itervalues(tree.children): walk(v) stats = read_profile(filename) walk(stats.get_tree())
def parse_profile(profile: RequestProfile): if (profile.data and profile.data_json): return profile.data profile_dict = read_profile(io.BytesIO(profile.data)) profile_tree = profile_dict.get_tree() profile_dump = profile_tree._serialize() profile_path = [] cutoff_samples = int(0.85 * profile_dump[2]) profile_next = profile_dump while profile_next: for profile_id, profile_next in enumerate(profile_next[4]): if (profile_next[2] > cutoff_samples): profile_path.append(profile_id) break else: break profile_dict = { "data": { "VM": profile_dict.interp, "profiles": profile_dump, "argv": "%s %s" % (profile_dict.interp, profile_dict.getargv()), "version": 2, } } profile_json = gzip.compress(json.dumps(profile_dict).encode('utf-8'), compresslevel=8) profile.data = profile_json profile.data_json = True profile.data_path = ','.join(map(str, profile_path)) profile.size_json = len(profile_json) profile.save(force_update=True, update_fields=['data', 'data_json', 'data_path', 'size_json']) return profile_json