mirror of https://github.com/ivanch/tcc.git
89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
|
import numpy as np
|
||
|
import matplotlib.pyplot as plt
|
||
|
|
||
|
def plot_graph(x, y, title, x_label, y_label, filename):
|
||
|
plt.plot(x, y, 'ro', markersize=1, linewidth=0.5, linestyle='solid')
|
||
|
plt.title(title)
|
||
|
plt.xlabel(x_label)
|
||
|
plt.ylabel(y_label)
|
||
|
plt.savefig(f'{filename}.png')
|
||
|
|
||
|
plt.clf()
|
||
|
plt.close('all')
|
||
|
|
||
|
def plot_resource_graph(x_data, y_data, title, x_label, y_label, filename):
|
||
|
requests = x_data
|
||
|
resource = {
|
||
|
'CPU': [p[0] for p in y_data],
|
||
|
'RAM': [p[1] for p in y_data],
|
||
|
}
|
||
|
|
||
|
x = np.arange(len(requests))
|
||
|
width = 0.25
|
||
|
multiplier = 0
|
||
|
|
||
|
fig, ax = plt.subplots(layout='constrained')
|
||
|
|
||
|
for attribute, measurement in resource.items():
|
||
|
offset = width * multiplier
|
||
|
|
||
|
rects = ax.bar(x + offset, measurement, width, label=attribute)
|
||
|
ax.bar_label(rects, padding=3)
|
||
|
multiplier += 1
|
||
|
|
||
|
# Add some text for labels, title and custom x-axis tick labels, etc.
|
||
|
ax.set_xlabel(x_label)
|
||
|
ax.set_ylabel(y_label)
|
||
|
ax.set_title(title)
|
||
|
ax.set_xticks(x + (width/2), requests)
|
||
|
ax.legend(loc='upper left', ncols=len(resource.items()))
|
||
|
ax.set_ylim(0, 100)
|
||
|
|
||
|
plt.savefig(f'{filename}.png')
|
||
|
|
||
|
plt.clf()
|
||
|
plt.close('all')
|
||
|
|
||
|
def get_data(filename):
|
||
|
lines = []
|
||
|
with open(filename, 'r') as f:
|
||
|
lines = f.readlines()
|
||
|
|
||
|
x = []
|
||
|
y = []
|
||
|
for line in lines:
|
||
|
line = line.strip().split(',')
|
||
|
if line:
|
||
|
x.append(int(line[0]))
|
||
|
y.append(float(line[1]))
|
||
|
|
||
|
return x, y
|
||
|
|
||
|
def get_resource_data(filename):
|
||
|
lines = []
|
||
|
with open(filename, 'r') as f:
|
||
|
lines = f.readlines()
|
||
|
|
||
|
x = []
|
||
|
y = []
|
||
|
for line in lines:
|
||
|
line = line.strip().split(',')
|
||
|
if line:
|
||
|
x.append(int(line[0])) # requests
|
||
|
y.append([float(v)*100 for v in line[1:]]) # cpu, ram
|
||
|
|
||
|
return x, y
|
||
|
|
||
|
def generate_req_graph(filename, framework_name, endpoint_name):
|
||
|
x, y = get_data(filename)
|
||
|
|
||
|
filename = filename.split('/')[-1]
|
||
|
new_filename = filename.replace('.csv', '')
|
||
|
plot_graph(x, y, f'{framework_name} - {endpoint_name}', 'Número de requisições', 'Requisições por segundo', new_filename)
|
||
|
|
||
|
def generate_resource_graph(filename, framework_name, endpoint_name):
|
||
|
x, y = get_resource_data(filename)
|
||
|
|
||
|
filename = filename.split('/')[-1]
|
||
|
new_filename = filename.replace('.csv', '')
|
||
|
plot_resource_graph(x, y, f'{framework_name} - {endpoint_name}', 'Uso de recursos', 'Uso (%)', new_filename)
|