Commit 3beca36f authored by Mario Hock's avatar Mario Hock
Browse files

put code in functions..

parent e4427ec8
......@@ -19,14 +19,9 @@ def append_twice(base_list, extend_list):
## MAIN ##
if __name__ == "__main__":
### DEMO:
filename = sys.argv[1]
print( filename )
def parse_cnl_file(filename):
## * Parse input file. *
cnl_file = CNLParser(filename)
......@@ -39,11 +34,10 @@ if __name__ == "__main__":
print( "NICs: " + str(cnl_file.get_nics()) )
## Prepare data for matplotlib
#nics = cnl_file.get_nics()
nics = ("eth1", "eth2")
nics = ("eth1", "eth2") ## XXX
net_cols = list()
nic_fields = [".send", ".receive"]
for nic_name in nics:
......@@ -57,42 +51,71 @@ if __name__ == "__main__":
#print( cols ) ## XXX
## Plot with matplotlib.
## Augment cnl_file with processed data.
cnl_file.cols = cols
cnl_file.net_col_names = net_cols
cnl_file.cpu_col_names = cpu_cols
cnl_file.x_values = x_values
## Create figure (window/file)
fig = plt.figure()
return cnl_file
## Draw comment on the figure.
t = matplotlib.text.Text(10,10, "Comment: " + cnl_file.get_comment(), figure=fig)
fig.texts.append(t)
#plt.title( cnl_file.get_comment() )
#plt.figtext(0.01, 0.02, "Comment: " + cnl_file.get_comment())
ax_net = fig.add_subplot(211)
#ax_net = fig.add_subplot(111) ## twin
def plot_net(ax, x_values, cols, active_cols):
ax.set_ylim(0,10**10)
ax.set_ylabel('Throughput (Bit/s)')
for col_name in active_cols:
ax.plot(x_values , cols[col_name], label=col_name)
ax.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
ax_net.set_ylim(0,10**10)
ax_net.set_ylabel('Throughput (Bit/s)')
ax.legend()
for col_name in net_cols:
ax_net.plot(x_values , cols[col_name], label=col_name)
ax_net.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
ax_net.legend()
def plot_cpu(ax, x_values, cols, active_cols):
ax.set_ylim(0,100)
ax.set_ylabel('CPU util (%)')
for col_name in active_cols:
ax.plot(x_values , cols[col_name], label=col_name)
#ax2.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
#ax_cpu = ax_net.twinx() ## twin
ax.legend()
## MAIN ##
if __name__ == "__main__":
### DEMO:
filename = sys.argv[1]
print( filename )
cnl_file = parse_cnl_file(filename)
## Plot with matplotlib.
## Create figure (window/file)
fig = plt.figure()
fig.canvas.set_window_title('CPUnetPlot')
## Draw comment on the figure (use absolute positioning).
t = matplotlib.text.Text(10,10, "Comment: " + cnl_file.get_comment(), figure=fig)
fig.texts.append(t)
## Prepare subplots
ax_net = fig.add_subplot(211)
ax_cpu = fig.add_subplot(212, sharex=ax_net)
ax_cpu.set_ylim(0,100)
ax_cpu.set_ylabel('CPU util (%)')
#ax_net = fig.add_subplot(111) ## twin
#ax_cpu = ax_net.twinx() ## twin
for col_name in cpu_cols:
ax_cpu.plot(x_values , cols[col_name], label=col_name)
#ax2.plot(x_values , calc_ema(cols[col_name], 0.2), label=col_name+" (ema)")
ax_cpu.legend()
## Plot
plot_net(ax_net, cnl_file.x_values, cnl_file.cols, cnl_file.net_col_names)
plot_cpu(ax_cpu, cnl_file.x_values, cnl_file.cols, cnl_file.cpu_col_names )
plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment