[v1,3/3] new script/analyse-tlb-flushes-simpletrace.py

Message ID 20170411105031.28904-4-alex.bennee@linaro.org
State New
Headers show
Series
  • Fix cputlb flush stats and exporting data
Related show

Commit Message

Alex Bennée April 11, 2017, 10:50 a.m.
This is a simple helper script to extract TLB flush stats from the a
simpletrace file and plot the results.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 scripts/analyse-tlb-flushes-simpletrace.py | 62 ++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100755 scripts/analyse-tlb-flushes-simpletrace.py

-- 
2.11.0

Patch hide | download patch | download mbox

diff --git a/scripts/analyse-tlb-flushes-simpletrace.py b/scripts/analyse-tlb-flushes-simpletrace.py
new file mode 100755
index 0000000000..9a1191c154
--- /dev/null
+++ b/scripts/analyse-tlb-flushes-simpletrace.py
@@ -0,0 +1,62 @@ 
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Generate a simple graph of flushes over time
+#
+# Author: Alex Bennée <alex.bennee@linaro.org>
+#
+
+import os
+import simpletrace
+import argparse
+import numpy as np
+import matplotlib.pyplot as plt
+
+class CpuTLBFlushAnalyser(simpletrace.Analyzer):
+    "A simpletrace Analyser for extracting flush stats."
+
+    def __init__(self):
+        self.stats = 0
+        self.timestamps = []
+        self.flush_self = []
+        self.flush_async = []
+        self.flush_synced = []
+
+
+    def tlb_flush_stats(self, timestamp, flush_self, flush_async, flush_synced):
+        "Match for tlb_flush_stats event. Appends counts to the relevant array."
+        self.timestamps.append(timestamp)
+        self.flush_self.append(flush_self)
+        self.flush_async.append(flush_async)
+        self.flush_synced.append(flush_synced)
+        self.stats += 1
+
+
+def get_args():
+    "Grab options"
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--output", "-o", type=str, help="Render plot to file")
+    parser.add_argument("events", type=str, help='trace file read from')
+    parser.add_argument("tracefile", type=str, help='trace file read from')
+    return parser.parse_args()
+
+if __name__ == '__main__':
+    args = get_args()
+
+    # Gather data from the trace
+    analyzer = CpuTLBFlushAnalyser()
+    simpletrace.process(args.events, args.tracefile, analyzer)
+
+#    x = np.arange(analyzer.stats)
+    fself, = plt.plot(analyzer.timestamps, analyzer.flush_self, label="Self")
+    fasync, = plt.plot(analyzer.timestamps, analyzer.flush_async, label="Async")
+    fsynced, = plt.plot(analyzer.timestamps, analyzer.flush_synced, label="Synced")
+
+    plt.legend(handles=[fself, fasync, fsynced])
+    plt.xlabel("Execution Time")
+    plt.ylabel("Culmlative count")
+
+    if args.output:
+        plt.savefig(args.output)
+    else:
+        plt.show()