Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
Signed-off-by: Mariia Azbeleva <[email protected]>
  • Loading branch information
azbeleva committed Sep 22, 2023
1 parent d8d60ad commit 1030830
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions Robot-Framework/lib/PerformanceDataProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

import csv
import os
import matplotlib.pyplot as plt
import logging
from robot.api.deco import keyword
Expand All @@ -11,37 +12,40 @@ class PerformanceDataProcessing:

def __init__(self, device):
# Initialize the instance variable with the global variable value
self.dir_path = "../../../Performance_test_results/"
self.data_dir = "../../../Performance_test_results/"
self.device = device

def _write_to_csv(self, test_name, data):
file_path = os.path.join(self.data_dir, f"{self.device}_{test_name}.csv")
logging.info(f"Writing data to {file_path}")
with open(file_path, 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(data)

@keyword
def write_cpu_to_csv(self, test_name, build_number, cpu_data):
logging.info("Write new data to the csv file...")
with open(f"{self.dir_path}{self.device}_{test_name}.csv", 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow([build_number,
cpu_data['cpu_events_per_second'],
cpu_data['min_latency'],
cpu_data['avg_latency'],
cpu_data['max_latency'],
cpu_data['cpu_events_per_thread'],
cpu_data['cpu_events_per_thread_stddev'],
self.device])
data = [build_number,
cpu_data['cpu_events_per_second'],
cpu_data['min_latency'],
cpu_data['avg_latency'],
cpu_data['max_latency'],
cpu_data['cpu_events_per_thread'],
cpu_data['cpu_events_per_thread_stddev'],
self.device]
self._write_to_csv(test_name, data)

@keyword
def write_mem_to_csv(self, test_name, build_number, mem_data):
logging.info("Write new data to the csv file...")
with open(f"{self.dir_path}{self.device}_{test_name}.csv", 'a', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow([build_number,
mem_data['operations_per_second'],
mem_data['data_transfer_speed'],
mem_data['min_latency'],
mem_data['avg_latency'],
mem_data['max_latency'],
mem_data['avg_events_per_thread'],
mem_data['events_per_thread_stddev'],
self.device])
data = [build_number,
mem_data['operations_per_second'],
mem_data['data_transfer_speed'],
mem_data['min_latency'],
mem_data['avg_latency'],
mem_data['max_latency'],
mem_data['avg_events_per_thread'],
mem_data['events_per_thread_stddev'],
self.device]
self._write_to_csv(test_name, data)

@keyword
def read_cpu_csv_and_plot(self, test_name):
Expand All @@ -53,7 +57,7 @@ def read_cpu_csv_and_plot(self, test_name):
cpu_events_per_thread = []
cpu_events_per_thread_stddev = []

with open(f"{self.dir_path}{self.device}_{test_name}.csv", 'r') as csvfile:
with open(f"{self.data_dir}{self.device}_{test_name}.csv", 'r') as csvfile:
csvreader = csv.reader(csvfile)
logging.info("Reading data from csv file...")
for row in csvreader:
Expand Down Expand Up @@ -123,7 +127,7 @@ def read_mem_csv_and_plot(self, test_name):
avg_events_per_thread = []
events_per_thread_stddev = []

with open(f"{self.dir_path}{self.device}_{test_name}.csv", 'r') as csvfile:
with open(f"{self.data_dir}{self.device}_{test_name}.csv", 'r') as csvfile:
csvreader = csv.reader(csvfile)
logging.info("Reading data from csv file...")
for row in csvreader:
Expand Down

0 comments on commit 1030830

Please sign in to comment.