Explorar el Código

add script to create numpy array files from the statistics trace and separate the plot statistics functionality

Ioannis Koutras hace 12 años
padre
commit
b010a1b2e0
Se han modificado 3 ficheros con 93 adiciones y 1 borrados
  1. 26 0
      scripts/parse_stats_trace.py
  2. 1 1
      scripts/plot_memory_usage.py
  3. 66 0
      scripts/plot_stats.py

+ 26 - 0
scripts/parse_stats_trace.py

@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+
+import argparse
+import numpy as np
+
+def read_stats_trace(stats_text_file):
+    allocated_regexp = r"dmmlib - ms all (\d+)"
+    allocated = np.fromregex(stats_text_file.name, allocated_regexp,
+            [('num', np.int64)])
+    requested_regexp = r"dmmlib - ms req (\d+)"
+    requested = np.fromregex(stats_text_file.name, requested_regexp,
+            [('num', np.int64)])
+    if allocated.size != requested.size:
+        print "Warning: Allocated and requested arrays have different sizes"
+    return (allocated['num'], requested['num'])
+
+if __name__=='__main__':
+    parser = argparse.ArgumentParser(
+            description="parse dmmlib's memory traces")
+    parser.add_argument("memory_trace", type=argparse.FileType('r'),
+                    help="dmmlib memory trace file")
+    args = parser.parse_args()
+    (allocated, requested) = read_stats_trace(args.memory_trace)
+    np.savez_compressed(args.memory_trace.name,
+            allocated=allocated, requested=requested)
+    args.memory_trace.close()

+ 1 - 1
scripts/plot_memory_usage.py

@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 import os, sys
 import subprocess

+ 66 - 0
scripts/plot_stats.py

@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import argparse
+import numpy as np
+
+import matplotlib
+matplotlib.use('Agg')
+import matplotlib.pyplot as plt
+from matplotlib.ticker import FuncFormatter
+
+def megabytes(x, pos):
+    return '%1.f' % (x/(1024*1024))
+
+def get_memory_utilization_figure(allocated, requested):
+    memory_fig = plt.figure()
+    memory_ax = memory_fig.add_subplot(111)
+
+    memory_ax.plot(allocated, label='allocated memory', rasterized=True)
+    memory_ax.plot(requested, label='requested memory', rasterized=True)
+
+    memory_ax.set_ylim(ymin=0)
+
+    memory_ax.set_xticks([])
+    memory_ax.set_xlabel('Application timeline')
+
+    memory_ax.yaxis.set_major_formatter(FuncFormatter(megabytes))
+    memory_ax.get_yaxis().tick_left()
+
+    return memory_fig
+
+def get_memory_utilization_index(allocated, requested):
+    memory_fig = plt.figure()
+    memory_ax = memory_fig.add_subplot(111)
+
+    memory_ax.plot(np.true_divide(requested, allocated), rasterized=True)
+
+    memory_ax.set_xticks([])
+    memory_ax.set_xlabel('Application timeline')
+
+    memory_ax.get_yaxis().tick_left()
+    memory_ax.set_ylabel('Memory utilization index')
+
+    return memory_fig
+
+if __name__=='__main__':
+    parser = argparse.ArgumentParser(
+            description="parse dmmlib's memory traces")
+    parser.add_argument("stat_arrays_file", type=argparse.FileType('r'),
+                    help="compressed statistics file")
+    args = parser.parse_args()
+    npzfile = np.load(args.stat_arrays_file)
+    allocated = npzfile['allocated']
+    requested = npzfile['requested']
+    memory_fig = get_memory_utilization_figure(allocated, requested)
+    memory_fig.savefig(
+            '{}_mem_usage.pdf'
+            .format(args.stat_arrays_file.name.split('.')[0]),
+            dpi=150
+            )
+    memory_fig = get_memory_utilization_index(allocated, requested)
+    memory_fig.savefig(
+            '{}_mem_utilization_index.pdf'
+            .format(args.stat_arrays_file.name.split('.')[0]),
+            dpi=150
+            )
+    args.stat_arrays_file.close()