aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/chatty_histogram.py66
-rwxr-xr-xscripts/malt_histogram.py58
-rwxr-xr-xscripts/matplotlib_histograms.py78
3 files changed, 78 insertions, 124 deletions
diff --git a/scripts/chatty_histogram.py b/scripts/chatty_histogram.py
deleted file mode 100755
index 30fda24..0000000
--- a/scripts/chatty_histogram.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import inspect
-import json
-import matplotlib.pyplot as plt
-import os
-import sys
-
-currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
-parentdir = os.path.dirname(currentdir)
-sys.path.insert(0,parentdir)
-
-import src.chattyparser as cp
-
-
-parser = argparse.ArgumentParser(description="Plot histograms using a chattymalloc output file")
-parser.add_argument("chattymalloc_file", help="path to chattymalloc.txt output file", type=str)
-parser.add_argument("-e", "--export", help="export to csv", action="store_true")
-
-def main():
- args = parser.parse_args()
-
- hist, calls, total_sizes = cp.parse(args.chattymalloc_file)
-
- if args.export:
- with open(args.chattymalloc_file.replace("json", "csv"), "w") as f:
- print("Size", "Amount", file=f)
- for size, amount in hist.items():
- print(size, amount, file=f)
-
- else:
- sizes = []
- sizes_smaller_4K = []
- sizes_smaller_32K = []
- sizes_bigger_32K = []
- for size, amount in hist.items():
- size = int(size)
- sizes += [int(size)] * amount
- if size < 4096:
- sizes_smaller_4K += [int(size)] * amount
- if size < 32000:
- sizes_smaller_32K += [int(size)] * amount
- else:
- sizes_bigger_32K += [int(size)] * amount
-
-
- plt.figure(0)
- plt.hist(sizes_smaller_4K, 200)
- plt.title("Sizes smaller than 4K")
-
- plt.figure(1)
- plt.hist(sizes_smaller_32K, 200)
- plt.title("Sizes smaller than 32K")
-
- plt.figure(2)
- plt.hist(sizes_bigger_32K, 200)
- plt.title("Sizes bigger than 32K")
-
- plt.figure(3)
- plt.hist(sizes, 200)
- plt.title("All sizes")
- plt.show()
-
-if __name__ == "__main__":
- main()
diff --git a/scripts/malt_histogram.py b/scripts/malt_histogram.py
deleted file mode 100755
index 122035e..0000000
--- a/scripts/malt_histogram.py
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/usr/bin/env python3
-
-import argparse
-import json
-import matplotlib.pyplot as plt
-
-
-parser = argparse.ArgumentParser(description="Plot interactive histogram using a malt json output file")
-parser.add_argument("malt_output_file", help="path to malt output file", type=str)
-parser.add_argument("-e", "--export", help="export to csv", action="store_true")
-
-def main():
- args = parser.parse_args()
-
- with open(args.malt_output_file, "r") as f:
- res = json.load(f)
-
- if args.export:
- with open(args.malt_output_file.replace("json", "csv"), "w") as f:
- print("Size", "Amount", file=f)
- for size, amount in res["memStats"]["sizeMap"].items():
- print(size, amount, file=f)
-
- else:
- sizes = []
- sizes_smaller_4K = []
- sizes_smaller_32K = []
- sizes_bigger_32K = []
- for size, amount in res["memStats"]["sizeMap"].items():
- size = int(size)
- sizes += [int(size)] * amount
- if size < 4096:
- sizes_smaller_4K += [int(size)] * amount
- if size < 32000:
- sizes_smaller_32K += [int(size)] * amount
- else:
- sizes_bigger_32K += [int(size)] * amount
-
-
- plt.figure(0)
- plt.hist(sizes_smaller_4K, 200)
- plt.title("Sizes smaller than 4K")
-
- plt.figure(1)
- plt.hist(sizes_smaller_32K, 200)
- plt.title("Sizes smaller than 32K")
-
- plt.figure(2)
- plt.hist(sizes_bigger_32K, 200)
- plt.title("Sizes bigger than 32K")
-
- plt.figure(3)
- plt.hist(sizes, 200)
- plt.title("All sizes")
- plt.show()
-
-if __name__ == "__main__":
- main()
diff --git a/scripts/matplotlib_histograms.py b/scripts/matplotlib_histograms.py
new file mode 100755
index 0000000..4d3af45
--- /dev/null
+++ b/scripts/matplotlib_histograms.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python3
+
+"""Plot an interactive histogram from malt or chattymalloc output file"""
+
+import argparse
+import importlib
+import inspect
+import json
+import os
+import sys
+
+import matplotlib.pyplot as plt
+
+
+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")
+ args = parser.parse_args()
+
+ fname, fext = os.path.splitext(args.input_file)
+ fname = os.path.basename(fname)
+ # 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)
+ # malt
+ else:
+ with open(args.input_file, "r") as json_file:
+ hist = json.load(json_file)["memStats"]["sizeMap"]
+
+ if args.export:
+ with open(f"{fname}.csv", "w") as csv_file:
+ print("Size", "Amount", file=csv_file)
+ for size, amount in hist.items():
+ print(size, amount, file=csv_file)
+
+ else:
+ sizes = []
+ sizes_smaller_4K = []
+ sizes_smaller_32K = []
+ sizes_bigger_32K = []
+ for size, amount in hist.items():
+ size = int(size)
+ sizes.append(size * amount)
+ if size < 4096:
+ sizes_smaller_4K.append(size * amount)
+ if size < 32000:
+ sizes_smaller_32K.append(size * amount)
+ else:
+ sizes_bigger_32K.append(size * amount)
+
+
+ plt.figure(0)
+ plt.hist(sizes_smaller_4K, 200)
+ plt.title("Sizes smaller than 4K")
+
+ plt.figure(1)
+ plt.hist(sizes_smaller_32K, 200)
+ plt.title("Sizes smaller than 32K")
+
+ plt.figure(2)
+ plt.hist(sizes_bigger_32K, 200)
+ plt.title("Sizes bigger than 32K")
+
+ plt.figure(3)
+ plt.hist(sizes, 200)
+ plt.title("All sizes")
+ plt.show()
+
+if __name__ == "__main__":
+ main()