Kaynağa Gözat

tablas informe

David 10 yıl önce
ebeveyn
işleme
4fdf8fe0b1
1 değiştirilmiş dosya ile 175 ekleme ve 0 silme
  1. 175 0
      scripts/batch_tables.py

+ 175 - 0
scripts/batch_tables.py

@@ -0,0 +1,175 @@
+#!/usr/bin/env python3
+# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
+import json
+import matplotlib.pyplot as plt
+import os
+import sys
+from subprocess import Popen, PIPE
+from stats import parseData
+
+bar_width = 0.25
+index = []
+def tprint(ls):
+    tmp = []
+    for f in ls:
+        if type(f) is str:
+            tmp.append(f)
+        else:
+            tmp.append(str(round(f)))
+
+    print("\t|".join(tmp))
+
+def plot(process_data, title, filename):
+    fig, ax = plt.subplots(figsize=(10,5))
+    
+    task_output = []
+    for p in process_data:
+        cmd = ["./simusched",p["tasks"]]
+        cmd.extend(p["args"].split(" "))
+        process = Popen(cmd, stdout=PIPE)
+        (out, _) = process.communicate()
+        process.wait()
+        out = out.decode("utf-8")
+        (parsed,idle) = parseData(out.split("\n"))
+        ap  = {}
+        ap["idle"] = idle
+        ap["processes"] = parsed
+        ap["tasks"] = p["tasks"]
+        ap["args"] = p["args"]
+        task_output.append(ap)
+
+
+    m_latencies = []
+    m_ready = []
+    m_turnaround = []
+    m_cpu = []
+    m_cpuio = []
+    idletime = []
+    for t in task_output:
+        m_latencies.append(meanLatency(t))
+        m_ready.append(meanReady(t))
+        m_turnaround.append(meanTA(t))
+        m_cpu.append(meanCPU(t))
+        m_cpuio.append(meanCPUIO(t))
+        idletime.append(t["idle"])
+
+
+
+    xtlbls = []
+    for i in range(len(process_data)):
+        lbl = task_output[i]["args"]
+        if len(lbl) > 15:
+            lbl=lbl[:15]
+
+        xtlbls.append(lbl.replace("1 2 0 ", "").replace("2 2 8 ", ""))
+
+    tprint(xtlbls)
+    tprint(['M. Latency'] + m_latencies)
+    tprint(['M. Ready'] + m_ready)
+    tprint(['M. Turnaround'] + m_turnaround)
+    tprint(['Idle'] + idletime)
+
+
+    #plot_data(0, m_latencies, 'r', 'M. Latency')
+    #plot_data(1, m_ready, 'g', 'M. Ready')
+    #plot_data(2, m_turnaround, '#3333bb', 'M. Turnaround')
+    #plot_data(3, m_cpu, '#deadbe', 'M. CPU')
+    #plot_data(4, m_cpuio, '#aa00aa', 'M. CPU+IO')
+    #plot_data(5, idletime, '#c1c1c1', 'Idle')
+
+    sys.exit(0)
+    ax.set_ylabel('Ticks')
+
+    tmp_tasks = set([ t["tasks"] for t in task_output ])
+    if len(tmp_tasks)>1:
+        ax.set_title(title + " - Multiples casos")
+    else:
+        ax.set_title(title + " - %s" % task_output[0]["tasks"])
+    ax.set_xticks([ i + 3.5* bar_width for i in index])
+
+    xtlbls = []
+    for i in range(len(process_data)):
+        lbl = task_output[i]["args"]
+        if len(lbl) > 30:
+            lbl=lbl[:30]+ "..."
+
+        xtlbls.append(lbl)
+
+    ax.set_xticklabels(xtlbls)
+    
+    for tick in ax.xaxis.get_major_ticks():
+        tick.label.set_fontsize(8)
+
+    plt.legend(loc="best")
+    
+    plt.tight_layout()
+    plt.grid()
+    plt.savefig(filename)
+
+
+def meanLatency(pl):
+    totLatency = sum([ latency(p) for p in pl["processes"]])
+    mean = totLatency / len(pl["processes"])
+    return mean
+
+def meanTA(pl):
+    totTA = sum([ turnaround(p) for p in pl["processes"]])
+    mean = totTA / len(pl["processes"])
+    return mean
+
+def meanReady(pl):
+    totReady = sum([ ready(p) for p in pl["processes"]])
+    mean = totReady / len(pl["processes"])
+    return mean
+
+def meanCPU(pl):
+    totCPU = sum([ cpu(p) for p in pl["processes"]])
+    mean = totCPU / len(pl["processes"])
+    return mean
+
+def meanCPUIO(pl):
+    totCPUIO = sum([ cpu_io(p) for p in pl["processes"]])
+    mean = totCPUIO / len(pl["processes"])
+    return mean
+
+def latency(p):
+    return p["primerTick"]-p["cargaTick"]
+
+def turnaround(p):
+    return p["ultimoTick"]-p["primerTick"]
+
+def ready(p):
+    return (p["ultimoTick"]-p["primerTick"])-(p["ticksBlock"]+p["ticksCpu"])+(p["primerTick"]-p["cargaTick"])
+
+def cpu(p):
+    return p["ticksCpu"]
+
+def cpu_io(p):
+    return p["ticksBlock"]+p["ticksCpu"]
+
+def plot_data(ind, data, color, label):
+    opacity = 1
+    plt.bar([i + bar_width*ind for i in index],
+        data,
+        bar_width,
+        alpha=opacity,
+        color=color,
+        label=(label))
+
+if len(sys.argv) != 2:
+    print("1 arg, json file")
+    sys.exit(1)
+
+if not os.path.isfile(sys.argv[1]):
+    print("'%s' no es un archivo / no existe" % sys.argv[1])
+    sys.exit(2)
+    
+try:
+    data = open(sys.argv[1]).read()
+    j = json.loads(data)
+    index = [ 1.8*i for i in list(range(len(j["list"]))) ]
+    plot(j["list"],j["title"], j["filename"])
+except Exception as e:
+    print("Exception")
+    print(data)
+    print(e)