def plot_ram(self, show_legend=False) -> str: """ Creates a str with a histogram that can be printed to the command line. :param show_legend: Shows a legend :return: str """ ram = [ ram.size_update / 1000 # convert to MB for ram in self.image_size_events ] dates = [ram.time_stamp for ram in self.image_size_events] if len(ram) == 0: return "" # No memory usage detected if len(ram) == 1: return str(f"Single memory update found:\n" f"Memory usage on the {dates[0]} " f"was updated to {ram[0]} MB\n") # else fig = Figure() fig.y_ticks_fkt = lambda x, y: self.mean_y_value(ram, x, y) fig.width = 55 fig.height = 15 fig.set_x_limits(min_=min(dates)) min_ram = int(min(ram)) # raises error if not casted fig.set_y_limits(min_=min_ram) fig.y_label = "Usage [MB]" fig.x_label = "Time" # this will use the self written function _ # num_formatter, to convert the y-label to int values fig.register_label_formatter(float, _int_formatter) fig.plot(dates, ram, lc='green', label="Continuous Graph") fig.scatter(dates, ram, lc='red', label="Single Values") return fig.show(legend=show_legend)
def analyze(self, log_files: list_of_logs) -> log_inf_list: """ Analyze the given log files one by one. :param log_files: list of valid HTCondor log files :return: list with information of each log file """ logging.info('Starting the analyze mode') if not log_files: raise_value_error("No files to analyze") result_list = list() # create progressbar, do not redirect output with Progress(transient=True, redirect_stdout=False, redirect_stderr=False) as progress: task = progress.add_task("Analysing...", total=len(log_files)) for file in log_files: progress.update(task, advance=1) result_dict = dict() logging.debug(f"Analysing the HTCondor log file: {file}") msg = f"[green]Job analysis of: {file}[/green]" result_dict["description"] = msg job_dict, res_dict, time_dict, \ ram_history, occurred_errors = self.log_to_dict(file) if job_dict: result_dict["execution-details"] = job_dict if time_dict: result_dict["times"] = time_dict if res_dict: result_dict["all-resources"] = \ self.manage_thresholds(res_dict) # show HTCondor errors if occurred_errors: result_dict["errors"] = occurred_errors # managing the ram history if ram_history: ram = np.array(ram_history.get('Image size updates')) dates = np.array(ram_history.get('Dates')) if ram_history and len(ram) > 1: fig = Figure() fig.width = 55 fig.height = 15 fig.set_x_limits(min_=min(dates)) min_ram = int(min(ram)) # raises error if not casted fig.set_y_limits(min_=min_ram) fig.y_label = "Usage" fig.x_label = "Time" # this will use the self written function _ # num_formatter, to convert the y-label to int values fig.register_label_formatter(float, _int_formatter) fig.plot(dates, ram, lc='green', label="Continuous Graph") fig.scatter(dates, ram, lc='red', label="Single Values") result_dict["ram-history"] = fig.show( legend=self.show_legend) elif ram_history: msg = f"Single memory update found:\n" \ f"Memory usage on the {dates[0]} " \ f"was updatet to {ram[0]} MB" result_dict["ram-history"] = msg if self.show_list: job_spec_id = self.get_job_spec_id(file) if 'htc-err' in self.show_list: result_dict['htc-err'] = self.htcondor_stderr( job_spec_id + self.ext_err) if 'htc-out' in self.show_list: result_dict['htc-out'] = self.htcondor_stdout( job_spec_id + self.ext_out) result_list.append(result_dict) return result_list