diff options
Diffstat (limited to 'scripts/matplotlib_histograms.py')
| -rwxr-xr-x | scripts/matplotlib_histograms.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/scripts/matplotlib_histograms.py b/scripts/matplotlib_histograms.py index 4d3af45..7fae59a 100755 --- a/scripts/matplotlib_histograms.py +++ b/scripts/matplotlib_histograms.py @@ -11,37 +11,44 @@ import sys import matplotlib.pyplot as plt +currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +parentdir = os.path.dirname(currentdir) +sys.path.insert(0, parentdir) + +import src.chattyparser def main(): parser = argparse.ArgumentParser(description="Plot histograms using a malt or chattymalloc output file") parser.add_argument("input_file", help="path to malt or chattymalloc output file", type=str) parser.add_argument("-e", "--export", help="export to csv", action="store_true") + parser.add_argument("-n", "--no-ascii", help="don't output a ascii histogram", action="store_true") + parser.add_argument("-i", "--interactive", help="open interactive matplotlib histogram plots", + action="store_true") args = parser.parse_args() - fname, fext = os.path.splitext(args.input_file) - fname = os.path.basename(fname) + fpath, fext = os.path.splitext(args.input_file) + fname = os.path.basename(fpath) # chattymalloc if fname.startswith("chatty") and fext == ".txt": - # import chattyparser - currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) - parentdir = os.path.dirname(currentdir) - sys.path.insert(0, parentdir) - - chattyparser = importlib.import_module("src.chattyparser") - - hist, _, _ = chattyparser.parse(args.input_file, coll_size=False) + hist, calls, _ = src.chattyparser.parse(args.input_file, coll_size=False) # malt else: with open(args.input_file, "r") as json_file: - hist = json.load(json_file)["memStats"]["sizeMap"] + malt_res = json.load(json_file) + + hist = malt_res["memStats"]["sizeMap"] + calls = {} + for thread in malt_res["threads"]: + for func, data in thread["stats"].items(): + calls[func] = calls.get(func, 0) + data["count"] if args.export: - with open(f"{fname}.csv", "w") as csv_file: + with open(f"{fpath}.csv", "w") as csv_file: print("Size", "Amount", file=csv_file) for size, amount in hist.items(): print(size, amount, file=csv_file) - else: + if args.interactive: sizes = [] sizes_smaller_4K = [] sizes_smaller_32K = [] @@ -74,5 +81,8 @@ def main(): plt.title("All sizes") plt.show() + if not args.no_ascii: + src.chattyparser.plot_hist_ascii(f"{fpath}.hist.txt", hist, calls) + if __name__ == "__main__": main() |
