mirror of https://github.com/ivanch/tcc.git
85 lines
2.3 KiB
Python
85 lines
2.3 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()
|
|
|
|
def plot_resource_graph(x, y, title, x_label, y_label, filename):
|
|
requests = x
|
|
resource = {
|
|
'CPU': (p[0] for p in y),
|
|
'RAM': (p[1] for p in y),
|
|
}
|
|
|
|
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, requests)
|
|
ax.legend(loc='upper left', ncols=len(resource.items()))
|
|
ax.set_ylim(0, 250)
|
|
|
|
plt.savefig(f'resources_{filename}.png')
|
|
|
|
plt.clf()
|
|
|
|
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) for v in line[1:]]) # cpu, ram
|
|
|
|
return x, y
|
|
|
|
def generate_req_graph(filename, framework_name, endpoint_name):
|
|
x, y = get_data(filename)
|
|
|
|
new_filename = filename.replace('.txt', '').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)
|
|
|
|
new_filename = filename.replace('.txt', '').replace('.csv', '')
|
|
plot_resource_graph(x, y, f'{framework_name} - {endpoint_name}', 'Uso de recursos', 'Uso (%)', new_filename) |