From ab45de77e00f80d8f8f10543949c09ad770ddc22 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 18:26:15 -0400 Subject: [PATCH 001/105] Added measuring energy of a whole py file --- src/measurement/energy_meter.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/measurement/energy_meter.py b/src/measurement/energy_meter.py index 8d589d9d..ee26608d 100644 --- a/src/measurement/energy_meter.py +++ b/src/measurement/energy_meter.py @@ -2,6 +2,7 @@ from typing import Callable import pyJoules.energy as joules + class EnergyMeter: """ A class to measure the energy consumption of specific code blocks using PyJoules. @@ -40,12 +41,15 @@ def measure_energy(self, func: Callable, *args, **kwargs): print(f"Execution Time: {end_time - start_time:.6f} seconds") print(f"Energy Consumed: {energy_consumed:.6f} Joules") - return result, energy_consumed # Return the result of the function and the energy consumed + return ( + result, + energy_consumed, + ) # Return the result of the function and the energy consumed def measure_block(self, code_block: str): """ Measures energy consumption for a block of code represented as a string. - + Parameters: - code_block (str): A string containing the code to execute. @@ -57,3 +61,24 @@ def measure_block(self, code_block: str): energy_consumed = joules.getEnergy() # Measure energy after execution print(f"Energy Consumed for the block: {energy_consumed:.6f} Joules") return energy_consumed + + def measure_file_energy(self, file_path: str): + """ + Measures the energy consumption of the code in the specified Python file. + + Parameters: + - file_path (str): The path to the Python file. + + Returns: + - float: The energy consumed (in Joules). + """ + try: + with open(file_path, "r") as file: + code = file.read() # Read the content of the file + + # Execute the code block and measure energy consumption + return self.measure_block(code) + + except Exception as e: + print(f"An error occurred while measuring energy for the file: {e}") + return None # Return None in case of an error From 2a48d816a7814f6f41e600037119c45ae2d7e377 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 18:52:57 -0400 Subject: [PATCH 002/105] code [POC] Added new energy_meter.py class, added sample inefficent python file in test folder --- src/measurement/energy_meter.py | 55 +++++++++++++++----- test/inefficent_code_example.py | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 13 deletions(-) create mode 100644 test/inefficent_code_example.py diff --git a/src/measurement/energy_meter.py b/src/measurement/energy_meter.py index ee26608d..de059bc4 100644 --- a/src/measurement/energy_meter.py +++ b/src/measurement/energy_meter.py @@ -1,19 +1,28 @@ import time from typing import Callable -import pyJoules.energy as joules +from pyJoules.device import DeviceFactory +from pyJoules.device.rapl_device import RaplPackageDomain, RaplDramDomain +from pyJoules.device.nvidia_device import NvidiaGPUDomain +from pyJoules.energy_meter import EnergyMeter +## Required for installation +# pip install pyJoules +# pip install nvidia-ml-py3 -class EnergyMeter: + +class EnergyMeterWrapper: """ A class to measure the energy consumption of specific code blocks using PyJoules. """ def __init__(self): """ - Initializes the EnergyMeter class. + Initializes the EnergyMeterWrapper class. """ - # Optional: Any initialization for the energy measurement can go here - pass + # Create and configure the monitored devices + domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)] + devices = DeviceFactory.create_devices(domains) + self.meter = EnergyMeter(devices) def measure_energy(self, func: Callable, *args, **kwargs): """ @@ -27,23 +36,28 @@ def measure_energy(self, func: Callable, *args, **kwargs): Returns: - tuple: A tuple containing the return value of the function and the energy consumed (in Joules). """ - start_energy = joules.getEnergy() # Start measuring energy + self.meter.start(tag="function_execution") # Start measuring energy + start_time = time.time() # Record start time result = func(*args, **kwargs) # Call the specified function end_time = time.time() # Record end time - end_energy = joules.getEnergy() # Stop measuring energy + self.meter.stop() # Stop measuring energy - energy_consumed = end_energy - start_energy # Calculate energy consumed + # Retrieve the energy trace + trace = self.meter.get_trace() + total_energy = sum( + sample.energy for sample in trace + ) # Calculate total energy consumed # Log the timing (optional) print(f"Execution Time: {end_time - start_time:.6f} seconds") - print(f"Energy Consumed: {energy_consumed:.6f} Joules") + print(f"Energy Consumed: {total_energy:.6f} Joules") return ( result, - energy_consumed, + total_energy, ) # Return the result of the function and the energy consumed def measure_block(self, code_block: str): @@ -57,10 +71,17 @@ def measure_block(self, code_block: str): - float: The energy consumed (in Joules). """ local_vars = {} + self.meter.start(tag="block_execution") # Start measuring energy exec(code_block, {}, local_vars) # Execute the code block - energy_consumed = joules.getEnergy() # Measure energy after execution - print(f"Energy Consumed for the block: {energy_consumed:.6f} Joules") - return energy_consumed + self.meter.stop() # Stop measuring energy + + # Retrieve the energy trace + trace = self.meter.get_trace() + total_energy = sum( + sample.energy for sample in trace + ) # Calculate total energy consumed + print(f"Energy Consumed for the block: {total_energy:.6f} Joules") + return total_energy def measure_file_energy(self, file_path: str): """ @@ -82,3 +103,11 @@ def measure_file_energy(self, file_path: str): except Exception as e: print(f"An error occurred while measuring energy for the file: {e}") return None # Return None in case of an error + + +# Example usage +if __name__ == "__main__": + meter = EnergyMeterWrapper() + energy_used = meter.measure_file_energy("../test/inefficent_code_example.py") + if energy_used is not None: + print(f"Total Energy Consumed: {energy_used:.6f} Joules") diff --git a/test/inefficent_code_example.py b/test/inefficent_code_example.py new file mode 100644 index 00000000..f8f32921 --- /dev/null +++ b/test/inefficent_code_example.py @@ -0,0 +1,90 @@ +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] + + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except ( + Exception + ) as e: # UEH: Unqualified Exception Handling, catching generic exceptions + print("An error occurred:", e) + + # LMC: Long Message Chain + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x != None and x != 0 and len(str(x)) > 1, results) + ) + + return self.processed_data + + # LBCL: Long Base Class List + + +class AdvancedProcessor(DataProcessor, object, dict, list, set, tuple): + pass + + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return ( + True if item > 10 else False if item < -10 else None if item == 0 else item + ) + + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + # LEC: Long Element Chain accessing deeply nested elements + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except KeyError: + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + # LPL: Long Parameter List + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) From 4ca968b7910354babc2341f56a75652c14a4f869 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 22:49:24 -0400 Subject: [PATCH 003/105] code [POC] fixed detecting the code smells --- .../__pycache__/base_analyzer.cpython-310.pyc | Bin 0 -> 732 bytes src/analyzers/base_analyzer.py | 4 +- src/analyzers/pylint_analyzer.py | 88 +++++++++--------- 3 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 src/analyzers/__pycache__/base_analyzer.cpython-310.pyc diff --git a/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc b/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f8229c8a019579445fe63c363da49d150fd7c0b4 GIT binary patch literal 732 zcmY*Wy>8nu5ayATt)#Y51nCQO2q2)2UZ5zFcBF3&_2hjU;l7@A<#96;08T>!C;w%l2uSZ#S0FE zc_|9}Q&Ckko#J4pJ3JsIWXtxEbf(&ed0OE?2hKi%esFhGbx4@}Mww9O>nT>jVW zcwvguMrsRPIi=#cQdMnNCFKL9{;YI)JQ4WKen_2YFjg-h`c_ Date: Sat, 2 Nov 2024 22:58:52 -0400 Subject: [PATCH 004/105] code [POC] fixed pylint analyzer --- src/analyzers/pylint_analyzer.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index d25d274f..d242d33d 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -16,10 +16,13 @@ def __init__(self, code_path: str): "R0915": "Long Method", # Too many statements "C0200": "Complex List Comprehension", # Loop can be simplified "C0103": "Invalid Naming Convention", # Non-standard names - + "R0912": "Long Lambda Function (LLF)", + "R0914": "Long Message Chain (LMC)" # Add other pylint codes as needed } + self.codes = set(self.code_smells.keys()) + def analyze(self): """ Runs pylint on the specified Python file and returns the output as a list of dictionaries. @@ -44,6 +47,24 @@ def analyze(self): return pylint_results + def filter_for_all_wanted_code_smells(self, pylint_results): + filtered_results =[] + for error in pylint_results: + if(error["message-id"] in self.codes ): + filtered_results.append(error) + + return filtered_results + + @classmethod + def filter_for_one_code_smell(pylint_results, code): + filtered_results =[] + for error in pylint_results: + if(error["message-id"] == code ): + filtered_results.append(error) + + return filtered_results + + from pylint.lint import Run @@ -62,5 +83,7 @@ def analyze(self): ) report = analyzer.analyze() - print("THIS IS REPORT:") - print(report) + print("THIS IS REPORT for our smells:") + print(analyzer.filter_for_all_wanted_code_smells(report)) + + \ No newline at end of file From 9901efc014d318a2e9246b12558629cff90b7675 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 22:59:42 -0400 Subject: [PATCH 005/105] code [POC] fixed pylint analyzer --- src/analyzers/pylint_analyzer.py | 1 + src/measurement/energy_meter.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index d242d33d..d5e9b7cb 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -5,6 +5,7 @@ from pylint import run_pylint from base_analyzer import BaseAnalyzer +# THIS WORKS ITS JUST THE PATH class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): diff --git a/src/measurement/energy_meter.py b/src/measurement/energy_meter.py index de059bc4..38426bf1 100644 --- a/src/measurement/energy_meter.py +++ b/src/measurement/energy_meter.py @@ -9,6 +9,8 @@ # pip install pyJoules # pip install nvidia-ml-py3 +# TEST TO SEE IF PYJOULE WORKS FOR YOU + class EnergyMeterWrapper: """ From 116374c1374fc8613d25a7c06eabbe970043a550 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 23:12:36 -0400 Subject: [PATCH 006/105] code [POC] added an entrypoint to main --- src/analyzers/pylint_analyzer.py | 30 +++++++++---------- src/main.py | 20 ++++++++++--- .../long_lambda_function_refactorer.py | 14 +++++++++ .../long_message_chain_refactorer.py | 14 +++++++++ 4 files changed, 59 insertions(+), 19 deletions(-) create mode 100644 src/refactorer/long_lambda_function_refactorer.py create mode 100644 src/refactorer/long_message_chain_refactorer.py diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index d5e9b7cb..fa2a4b1d 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -4,21 +4,25 @@ import os from pylint import run_pylint from base_analyzer import BaseAnalyzer +from refactorer.large_class_refactorer import LargeClassRefactorer +from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer +from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer # THIS WORKS ITS JUST THE PATH + class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): super().__init__(code_path) # We are going to use the codes to identify the smells this is a dict of all of them self.code_smells = { - "R0902": "Large Class", # Too many instance attributes - "R0913": "Long Parameter List", # Too many arguments - "R0915": "Long Method", # Too many statements - "C0200": "Complex List Comprehension", # Loop can be simplified - "C0103": "Invalid Naming Convention", # Non-standard names - "R0912": "Long Lambda Function (LLF)", - "R0914": "Long Message Chain (LMC)" + # "R0902": LargeClassRefactorer, # Too many instance attributes + # "R0913": "Long Parameter List", # Too many arguments + # "R0915": "Long Method", # Too many statements + # "C0200": "Complex List Comprehension", # Loop can be simplified + # "C0103": "Invalid Naming Convention", # Non-standard names + "R0912": LongLambdaFunctionRefactorer, + "R0914": LongMessageChainRefactorer, # Add other pylint codes as needed } @@ -49,25 +53,23 @@ def analyze(self): return pylint_results def filter_for_all_wanted_code_smells(self, pylint_results): - filtered_results =[] + filtered_results = [] for error in pylint_results: - if(error["message-id"] in self.codes ): + if error["message-id"] in self.codes: filtered_results.append(error) return filtered_results @classmethod def filter_for_one_code_smell(pylint_results, code): - filtered_results =[] + filtered_results = [] for error in pylint_results: - if(error["message-id"] == code ): + if error["message-id"] == code: filtered_results.append(error) return filtered_results - - from pylint.lint import Run # Example usage @@ -86,5 +88,3 @@ def filter_for_one_code_smell(pylint_results, code): print("THIS IS REPORT for our smells:") print(analyzer.filter_for_all_wanted_code_smells(report)) - - \ No newline at end of file diff --git a/src/main.py b/src/main.py index 4508a68d..57631f15 100644 --- a/src/main.py +++ b/src/main.py @@ -1,15 +1,27 @@ from analyzers.pylint_analyzer import PylintAnalyzer + def main(): """ Entry point for the refactoring tool. - Create an instance of the analyzer. - Perform code analysis and print the results. """ - code_path = "path/to/your/code" # Path to the code to analyze - analyzer = PylintAnalyzer(code_path) - report = analyzer.analyze() # Analyze the code - print(report) # Print the analysis report + + # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug + path = "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + analyzer = PylintAnalyzer(path) + report = analyzer.analyze() + + print("THIS IS REPORT for our smells:") + detected_smells = analyzer.filter_for_all_wanted_code_smells(report) + print(detected_smells) + + for smell in detected_smells: + refactoring_class = analyzer.code_smells[smell["message-id"]] + + refactoring_class.refactor(smell, path) + if __name__ == "__main__": main() diff --git a/src/refactorer/long_lambda_function_refactorer.py b/src/refactorer/long_lambda_function_refactorer.py new file mode 100644 index 00000000..242e2ffb --- /dev/null +++ b/src/refactorer/long_lambda_function_refactorer.py @@ -0,0 +1,14 @@ +from .base_refactorer import BaseRefactorer + +class LongLambdaFunctionRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + @classmethod + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass diff --git a/src/refactorer/long_message_chain_refactorer.py b/src/refactorer/long_message_chain_refactorer.py new file mode 100644 index 00000000..03dc4bb5 --- /dev/null +++ b/src/refactorer/long_message_chain_refactorer.py @@ -0,0 +1,14 @@ +from .base_refactorer import BaseRefactorer + +class LongMessageChainRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + @classmethod + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass From 51f8fbfd3cf1638307ad46543273778ec7a75316 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 2 Nov 2024 23:17:06 -0400 Subject: [PATCH 007/105] code [POC] added stricter class definitions --- src/refactorer/base_refactorer.py | 4 +++- src/refactorer/long_lambda_function_refactorer.py | 2 +- src/refactorer/long_message_chain_refactorer.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/refactorer/base_refactorer.py b/src/refactorer/base_refactorer.py index 698440fb..fe541721 100644 --- a/src/refactorer/base_refactorer.py +++ b/src/refactorer/base_refactorer.py @@ -2,6 +2,7 @@ from abc import ABC, abstractmethod + class BaseRefactorer(ABC): """ Abstract base class for refactorers. @@ -16,7 +17,8 @@ def __init__(self, code): """ self.code = code - def refactor(self): + @staticmethod + def refactor(code_smell_error, input_code): """ Perform the refactoring process. Must be implemented by subclasses. diff --git a/src/refactorer/long_lambda_function_refactorer.py b/src/refactorer/long_lambda_function_refactorer.py index 242e2ffb..9a3a0abf 100644 --- a/src/refactorer/long_lambda_function_refactorer.py +++ b/src/refactorer/long_lambda_function_refactorer.py @@ -4,7 +4,7 @@ class LongLambdaFunctionRefactorer(BaseRefactorer): """ Refactorer that targets long methods to improve readability. """ - @classmethod + @staticmethod def refactor(self): """ Refactor long methods into smaller methods. diff --git a/src/refactorer/long_message_chain_refactorer.py b/src/refactorer/long_message_chain_refactorer.py index 03dc4bb5..f3365c20 100644 --- a/src/refactorer/long_message_chain_refactorer.py +++ b/src/refactorer/long_message_chain_refactorer.py @@ -4,7 +4,7 @@ class LongMessageChainRefactorer(BaseRefactorer): """ Refactorer that targets long methods to improve readability. """ - @classmethod + @staticmethod def refactor(self): """ Refactor long methods into smaller methods. From cc5142d6a261b23e2fd457680bb1da6349fc4260 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Mon, 4 Nov 2024 19:46:17 -0500 Subject: [PATCH 008/105] Added placeholder code for long element chain refactorer --- src/refactorer/long_element_chain.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/refactorer/long_element_chain.py diff --git a/src/refactorer/long_element_chain.py b/src/refactorer/long_element_chain.py new file mode 100644 index 00000000..4096b4a7 --- /dev/null +++ b/src/refactorer/long_element_chain.py @@ -0,0 +1,19 @@ +class LongElementChainRefactorer: + """ + Refactorer for data objects (dictionary) that have too many deeply nested elements inside. + Ex: deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + """ + + def __init__(self, code: str, element_threshold: int = 5): + """ + Initializes the refactorer. + + :param code: The source code of the class to refactor. + :param method_threshold: The number of nested elements allowed before dictionary has too many deeply nested elements. + """ + self.code = code + self.element_threshold = element_threshold + + def refactor(self): + + return self.code \ No newline at end of file From 856f48265b2260b4160bd151f911ce89bec0e822 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Mon, 4 Nov 2024 19:48:25 -0500 Subject: [PATCH 009/105] Added placeholder code for long scope chaining refactorer --- src/refactorer/long_scope_chaining.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/refactorer/long_scope_chaining.py diff --git a/src/refactorer/long_scope_chaining.py b/src/refactorer/long_scope_chaining.py new file mode 100644 index 00000000..727b0f7b --- /dev/null +++ b/src/refactorer/long_scope_chaining.py @@ -0,0 +1,23 @@ +class LongScopeRefactorer: + """ + Refactorer for methods that have too many deeply nested loops. + """ + + def __init__(self, code: str, loop_threshold: int = 5): + """ + Initializes the refactorer. + + :param code: The source code of the class to refactor. + :param method_threshold: The number of loops allowed before method is considered one with too many nested loops. + """ + self.code = code + self.loop_threshold = loop_threshold + + def refactor(self): + """ + Refactor code by ... + + Return: refactored code + """ + + return self.code \ No newline at end of file From 45b9fb5ce72cc85fbcca13e5b904bc2626c13e66 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 4 Nov 2024 23:58:26 -0500 Subject: [PATCH 010/105] fixed path issue in pylint analyzer --- src/analyzers/pylint_analyzer.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index fa2a4b1d..a2c0ea8c 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -1,8 +1,14 @@ -import io import json from io import StringIO -import os +from os.path import dirname, abspath +import sys + +# Sets src as absolute path, everything needs to be relative to src folder +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) + from pylint import run_pylint +from pylint.lint import Run from base_analyzer import BaseAnalyzer from refactorer.large_class_refactorer import LargeClassRefactorer from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer @@ -10,7 +16,6 @@ # THIS WORKS ITS JUST THE PATH - class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): super().__init__(code_path) @@ -37,7 +42,7 @@ def analyze(self): :return: A list of dictionaries with pylint messages. """ # Capture pylint output into a string stream - output_stream = io.StringIO() + output_stream = StringIO() # Run pylint Run(["--output-format=json", self.code_path]) @@ -69,20 +74,17 @@ def filter_for_one_code_smell(pylint_results, code): return filtered_results - -from pylint.lint import Run - # Example usage if __name__ == "__main__": - print(os.path.abspath("../test/inefficent_code_example.py")) + print(abspath("../test/inefficent_code_example.py")) # FOR SOME REASON THIS ISNT WORKING UNLESS THE PATH IS ABSOLUTE # this is probably because its executing from the location of the interpreter # weird thing is it breaks when you use abs path instead... uhhh idk what to do here rn ... analyzer = PylintAnalyzer( - "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + "test/inefficent_code_example.py" ) report = analyzer.analyze() From 2549b80a93540da19e43e7a54ae2548040af9a09 Mon Sep 17 00:00:00 2001 From: mya Date: Wed, 6 Nov 2024 14:54:39 -0500 Subject: [PATCH 011/105] code carbon test --- src/analyzers/pylint_analyzer.py | 1 - src/main.py | 2 +- src/measurement/tracarbon.py | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/measurement/tracarbon.py diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index a2c0ea8c..0405c17c 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -14,7 +14,6 @@ from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer -# THIS WORKS ITS JUST THE PATH class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): diff --git a/src/main.py b/src/main.py index 57631f15..374ac8b9 100644 --- a/src/main.py +++ b/src/main.py @@ -20,7 +20,7 @@ def main(): for smell in detected_smells: refactoring_class = analyzer.code_smells[smell["message-id"]] - refactoring_class.refactor(smell, path) + refactoring_class.refactor(smell, path) if __name__ == "__main__": diff --git a/src/measurement/tracarbon.py b/src/measurement/tracarbon.py new file mode 100644 index 00000000..8bfd94e2 --- /dev/null +++ b/src/measurement/tracarbon.py @@ -0,0 +1,61 @@ +import subprocess +from codecarbon import EmissionsTracker +from pathlib import Path + +# To run run +# pip install codecarbon + + +class CarbonAnalyzer: + def __init__(self, script_path: str): + """ + Initialize with the path to the Python script to analyze. + """ + self.script_path = script_path + self.tracker = EmissionsTracker() + + def run_and_measure(self): + """ + Run the specified Python script and measure its energy consumption and CO2 emissions. + """ + script = Path(self.script_path) + + # Check if the file exists and is a Python file + if not script.exists() or script.suffix != ".py": + raise ValueError("Please provide a valid Python script path.") + + # Start tracking emissions + self.tracker.start() + + try: + # Run the Python script as a subprocess + subprocess.run(["python", str(script)], check=True) + except subprocess.CalledProcessError as e: + print(f"Error: The script encountered an error: {e}") + finally: + # Stop tracking and get emissions data + emissions = self.tracker.stop() + print("Emissions data:", emissions) + + def save_report(self, report_path: str = "carbon_report.csv"): + """ + Save the emissions report to a CSV file. + """ + import pandas as pd + + data = self.tracker.emissions_data + if data: + df = pd.DataFrame(data) + df.to_csv(report_path, index=False) + print(f"Report saved to {report_path}") + else: + print("No data to save.") + + +# Example usage +if __name__ == "__main__": + analyzer = CarbonAnalyzer("/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/test/inefficent_code_example.py") + analyzer.run_and_measure() + analyzer.save_report( + "/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/measurement/carbon_report.csv" + ) From 9d117100c7cb8551e0551f0fa54c62a5047677f3 Mon Sep 17 00:00:00 2001 From: mya Date: Wed, 6 Nov 2024 15:00:03 -0500 Subject: [PATCH 012/105] code carbon meter added --- src/measurement/{tracarbon.py => code_carbon_meter.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/measurement/{tracarbon.py => code_carbon_meter.py} (100%) diff --git a/src/measurement/tracarbon.py b/src/measurement/code_carbon_meter.py similarity index 100% rename from src/measurement/tracarbon.py rename to src/measurement/code_carbon_meter.py From 92a337e3edd26bde4477e647e4d958c678d1da87 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:03:04 -0500 Subject: [PATCH 013/105] added ternary condition smell init changes --- .gitignore | 11 ++- mypy.ini | 12 +++ pyproject.toml | 48 ++++++++++ src/__init__.py | 5 ++ src/analyzers/pylint_analyzer.py | 90 +++++++++++-------- src/main.py | 38 ++++++-- src/refactorer/base_refactorer.py | 6 +- .../long_lambda_function_refactorer.py | 4 +- .../long_message_chain_refactorer.py | 5 +- .../long_ternary_cond_expression.py | 17 ++++ src/utils/ast_parser.py | 17 ++++ src/utils/code_smells.py | 22 +++++ src/utils/factory.py | 23 +++++ 13 files changed, 249 insertions(+), 49 deletions(-) create mode 100644 mypy.ini create mode 100644 pyproject.toml create mode 100644 src/__init__.py create mode 100644 src/refactorer/long_ternary_cond_expression.py create mode 100644 src/utils/ast_parser.py create mode 100644 src/utils/code_smells.py create mode 100644 src/utils/factory.py diff --git a/.gitignore b/.gitignore index 51b86108..2a2a6f88 100644 --- a/.gitignore +++ b/.gitignore @@ -286,4 +286,13 @@ TSWLatexianTemp* # DRAW.IO files *.drawio -*.drawio.bkp \ No newline at end of file +*.drawio.bkp + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# Rope +.ropeproject + +output/ \ No newline at end of file diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..f02ab91e --- /dev/null +++ b/mypy.ini @@ -0,0 +1,12 @@ +[mypy] +files = test, src/**/*.py + +disallow_any_generics = True +disallow_untyped_calls = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +disallow_untyped_decorators = True +no_implicit_optional = True +warn_redundant_casts = True +implicit_reexport = False +strict_equality = True \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..85a19af8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,48 @@ +[build-system] +requires = ["setuptools >= 61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "ecooptimizer" +version = "0.0.1" +dependencies = [ + "pylint", + "flake8", + "radon", + "rope" +] +requires-python = ">=3.8" +authors = [ + {name = "Sevhena Walker"}, + {name = "Mya Hussain"}, + {name = "Nivetha Kuruparan"}, + {name = "Ayushi Amin"}, + {name = "Tanveer Brar"} +] + +description = "A source code eco optimizer" +readme = "README.md" +license = {file = "LICENSE"} + +[dependency-groups] +dev = ["pytest", "mypy", "ruff", "coverage"] + +[project.urls] +Documentation = "https://readthedocs.org" +Repository = "https://github.com/ssm-lab/capstone--source-code-optimizer" +"Bug Tracker" = "https://github.com/ssm-lab/capstone--source-code-optimizer/issues" + +[tool.pytest.ini_options] +testpaths = ["test"] + +[tool.ruff] +line-length = 100 + +[tool.ruff.lint] +ignore = ["E402"] + +[tool.ruff.format] +quote-style = "single" +indent-style = "tab" +docstring-code-format = true +docstring-code-line-length = 50 \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 00000000..56f09c20 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,5 @@ +from . import analyzers +from . import measurement +from . import refactorer +from . import testing +from . import utils \ No newline at end of file diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index a2c0ea8c..247395db 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -1,37 +1,33 @@ import json from io import StringIO -from os.path import dirname, abspath -import sys +# ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN +# you will need to change imports too +# ====================================================== +# from os.path import dirname, abspath +# import sys -# Sets src as absolute path, everything needs to be relative to src folder -REFACTOR_DIR = dirname(abspath(__file__)) -sys.path.append(dirname(REFACTOR_DIR)) -from pylint import run_pylint +# # Sets src as absolute path, everything needs to be relative to src folder +# REFACTOR_DIR = dirname(abspath(__file__)) +# sys.path.append(dirname(REFACTOR_DIR)) + from pylint.lint import Run -from base_analyzer import BaseAnalyzer +from pylint.reporters.json_reporter import JSON2Reporter + +from analyzers.base_analyzer import BaseAnalyzer from refactorer.large_class_refactorer import LargeClassRefactorer from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer +from utils.code_smells import CodeSmells +from utils.ast_parser import parse_line, parse_file + # THIS WORKS ITS JUST THE PATH class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): super().__init__(code_path) # We are going to use the codes to identify the smells this is a dict of all of them - self.code_smells = { - # "R0902": LargeClassRefactorer, # Too many instance attributes - # "R0913": "Long Parameter List", # Too many arguments - # "R0915": "Long Method", # Too many statements - # "C0200": "Complex List Comprehension", # Loop can be simplified - # "C0103": "Invalid Naming Convention", # Non-standard names - "R0912": LongLambdaFunctionRefactorer, - "R0914": LongMessageChainRefactorer, - # Add other pylint codes as needed - } - - self.codes = set(self.code_smells.keys()) def analyze(self): """ @@ -43,12 +39,14 @@ def analyze(self): """ # Capture pylint output into a string stream output_stream = StringIO() + reporter = JSON2Reporter(output_stream) # Run pylint - Run(["--output-format=json", self.code_path]) + Run(["--max-line-length=80", "--max-nested-blocks=3", "--max-branches=3", "--max-parents=3", self.code_path], reporter=reporter, exit=False) # Retrieve and parse output as JSON output = output_stream.getvalue() + try: pylint_results = json.loads(output) except json.JSONDecodeError: @@ -58,35 +56,55 @@ def analyze(self): return pylint_results def filter_for_all_wanted_code_smells(self, pylint_results): + statistics = {} + report = [] filtered_results = [] + for error in pylint_results: - if error["message-id"] in self.codes: + if error["messageId"] in CodeSmells.list(): + statistics[error["messageId"]] = True filtered_results.append(error) + + report.append(filtered_results) + report.append(statistics) - return filtered_results + with open("src/output/report.txt", "w+") as f: + print(json.dumps(report, indent=2), file=f) + + return report - @classmethod - def filter_for_one_code_smell(pylint_results, code): + def filter_for_one_code_smell(self, pylint_results, code): filtered_results = [] for error in pylint_results: - if error["message-id"] == code: + if error["messageId"] == code: filtered_results.append(error) return filtered_results # Example usage -if __name__ == "__main__": +# if __name__ == "__main__": + +# FILE_PATH = abspath("test/inefficent_code_example.py") + +# analyzer = PylintAnalyzer(FILE_PATH) + +# # print("THIS IS REPORT for our smells:") +# report = analyzer.analyze() + +# with open("src/output/ast.txt", "w+") as f: +# print(parse_file(FILE_PATH), file=f) + +# filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") + - print(abspath("../test/inefficent_code_example.py")) +# with open(FILE_PATH, "r") as f: +# file_lines = f.readlines() - # FOR SOME REASON THIS ISNT WORKING UNLESS THE PATH IS ABSOLUTE - # this is probably because its executing from the location of the interpreter - # weird thing is it breaks when you use abs path instead... uhhh idk what to do here rn ... +# for smell in filtered_results: +# with open("src/output/ast_lines.txt", "a+") as f: +# print("Parsing line ", smell["line"], file=f) +# print(parse_line(file_lines, smell["line"]), end="\n", file=f) + - analyzer = PylintAnalyzer( - "test/inefficent_code_example.py" - ) - report = analyzer.analyze() - print("THIS IS REPORT for our smells:") - print(analyzer.filter_for_all_wanted_code_smells(report)) + diff --git a/src/main.py b/src/main.py index 57631f15..94c5ca2c 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,12 @@ +import ast +import os + from analyzers.pylint_analyzer import PylintAnalyzer +from utils.factory import RefactorerFactory +from utils.code_smells import CodeSmells +from utils import ast_parser +dirname = os.path.dirname(__file__) def main(): """ @@ -9,18 +16,35 @@ def main(): """ # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug - path = "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - analyzer = PylintAnalyzer(path) + FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") + + analyzer = PylintAnalyzer(FILE_PATH) report = analyzer.analyze() - print("THIS IS REPORT for our smells:") - detected_smells = analyzer.filter_for_all_wanted_code_smells(report) - print(detected_smells) + filtered_report = analyzer.filter_for_all_wanted_code_smells(report["messages"]) + detected_smells = filtered_report[0] + # statistics = filtered_report[1] for smell in detected_smells: - refactoring_class = analyzer.code_smells[smell["message-id"]] + smell_id = smell["messageId"] + + if smell_id == CodeSmells.LINE_TOO_LONG.value: + root_node = ast_parser.parse_line(FILE_PATH, smell["line"]) + + if root_node is None: + continue + + smell_id = CodeSmells.LONG_TERN_EXPR + + # for node in ast.walk(root_node): + # print("Body: ", node["body"]) + # for expr in ast.walk(node.body[0]): + # if isinstance(expr, ast.IfExp): + # smell_id = CodeSmells.LONG_TERN_EXPR - refactoring_class.refactor(smell, path) + print("Refactoring ", smell_id) + refactoring_class = RefactorerFactory.build(smell_id, FILE_PATH) + refactoring_class.refactor() if __name__ == "__main__": diff --git a/src/refactorer/base_refactorer.py b/src/refactorer/base_refactorer.py index fe541721..3450ad9f 100644 --- a/src/refactorer/base_refactorer.py +++ b/src/refactorer/base_refactorer.py @@ -8,7 +8,7 @@ class BaseRefactorer(ABC): Abstract base class for refactorers. Subclasses should implement the `refactor` method. """ - + @abstractmethod def __init__(self, code): """ Initialize the refactorer with the code to refactor. @@ -17,10 +17,10 @@ def __init__(self, code): """ self.code = code - @staticmethod + @abstractmethod def refactor(code_smell_error, input_code): """ Perform the refactoring process. Must be implemented by subclasses. """ - raise NotImplementedError("Subclasses should implement this method") + pass diff --git a/src/refactorer/long_lambda_function_refactorer.py b/src/refactorer/long_lambda_function_refactorer.py index 9a3a0abf..421ada60 100644 --- a/src/refactorer/long_lambda_function_refactorer.py +++ b/src/refactorer/long_lambda_function_refactorer.py @@ -4,7 +4,9 @@ class LongLambdaFunctionRefactorer(BaseRefactorer): """ Refactorer that targets long methods to improve readability. """ - @staticmethod + def __init__(self, code): + super().__init__(code) + def refactor(self): """ Refactor long methods into smaller methods. diff --git a/src/refactorer/long_message_chain_refactorer.py b/src/refactorer/long_message_chain_refactorer.py index f3365c20..2438910f 100644 --- a/src/refactorer/long_message_chain_refactorer.py +++ b/src/refactorer/long_message_chain_refactorer.py @@ -4,7 +4,10 @@ class LongMessageChainRefactorer(BaseRefactorer): """ Refactorer that targets long methods to improve readability. """ - @staticmethod + + def __init__(self, code): + super().__init__(code) + def refactor(self): """ Refactor long methods into smaller methods. diff --git a/src/refactorer/long_ternary_cond_expression.py b/src/refactorer/long_ternary_cond_expression.py new file mode 100644 index 00000000..994ccfc3 --- /dev/null +++ b/src/refactorer/long_ternary_cond_expression.py @@ -0,0 +1,17 @@ +from .base_refactorer import BaseRefactorer + +class LTCERefactorer(BaseRefactorer): + """ + Refactorer that targets long ternary conditional expressions (LTCEs) to improve readability. + """ + + def __init__(self, code): + super().__init__(code) + + def refactor(self): + """ + Refactor LTCEs into smaller methods. + Implement the logic to detect and refactor LTCEs. + """ + # Logic to identify LTCEs goes here + pass diff --git a/src/utils/ast_parser.py b/src/utils/ast_parser.py new file mode 100644 index 00000000..6a7f6fd8 --- /dev/null +++ b/src/utils/ast_parser.py @@ -0,0 +1,17 @@ +import ast + +def parse_line(file: str, line: int): + with open(file, "r") as f: + file_lines = f.readlines() + try: + node = ast.parse(file_lines[line - 1].strip()) + except(SyntaxError) as e: + return None + + return node + +def parse_file(file: str): + with open(file, "r") as f: + source = f.read() + + return ast.parse(source) \ No newline at end of file diff --git a/src/utils/code_smells.py b/src/utils/code_smells.py new file mode 100644 index 00000000..0a9391bd --- /dev/null +++ b/src/utils/code_smells.py @@ -0,0 +1,22 @@ +from enum import Enum + +class ExtendedEnum(Enum): + + @classmethod + def list(cls) -> list[str]: + return [c.value for c in cls] + +class CodeSmells(ExtendedEnum): + # Add codes here + LINE_TOO_LONG = "C0301" + LONG_MESSAGE_CHAIN = "R0914" + LONG_LAMBDA_FUNC = "R0914" + LONG_TERN_EXPR = "CUST-1" + # "R0902": LargeClassRefactorer, # Too many instance attributes + # "R0913": "Long Parameter List", # Too many arguments + # "R0915": "Long Method", # Too many statements + # "C0200": "Complex List Comprehension", # Loop can be simplified + # "C0103": "Invalid Naming Convention", # Non-standard names + + def __str__(self): + return str(self.value) diff --git a/src/utils/factory.py b/src/utils/factory.py new file mode 100644 index 00000000..a60628b4 --- /dev/null +++ b/src/utils/factory.py @@ -0,0 +1,23 @@ +from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer as LLFR +from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer as LMCR +from refactorer.long_ternary_cond_expression import LTCERefactorer as LTCER + +from refactorer.base_refactorer import BaseRefactorer + +from utils.code_smells import CodeSmells + +class RefactorerFactory(): + + @staticmethod + def build(smell_name: str, file_path: str) -> BaseRefactorer: + selected = None + match smell_name: + case CodeSmells.LONG_LAMBDA_FUNC: + selected = LLFR(file_path) + case CodeSmells.LONG_MESSAGE_CHAIN: + selected = LMCR(file_path) + case CodeSmells.LONG_TERN_EXPR: + selected = LTCER(file_path) + case _: + raise ValueError(smell_name) + return selected \ No newline at end of file From 09d19ffa632dbdf525203ed8d98ff07d40af8b09 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Wed, 6 Nov 2024 15:17:45 -0500 Subject: [PATCH 014/105] Added multiple runs for code carbon --- src/measurement/code_carbon_meter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py index 8bfd94e2..f169f726 100644 --- a/src/measurement/code_carbon_meter.py +++ b/src/measurement/code_carbon_meter.py @@ -12,7 +12,7 @@ def __init__(self, script_path: str): Initialize with the path to the Python script to analyze. """ self.script_path = script_path - self.tracker = EmissionsTracker() + self.tracker = EmissionsTracker(allow_multiple_runs=True) def run_and_measure(self): """ From 4e8e6f70821fff32bc1a57ee50c1e4659d1adbe0 Mon Sep 17 00:00:00 2001 From: mya Date: Wed, 6 Nov 2024 15:23:06 -0500 Subject: [PATCH 015/105] Paths partiall fixed --- emissions.csv | 2 + powermetrics_log.txt | 817 +++++++++++++++++++++++++++ src/measurement/code_carbon_meter.py | 15 +- 3 files changed, 830 insertions(+), 4 deletions(-) create mode 100644 emissions.csv create mode 100644 powermetrics_log.txt diff --git a/emissions.csv b/emissions.csv new file mode 100644 index 00000000..165f1ccf --- /dev/null +++ b/emissions.csv @@ -0,0 +1,2 @@ +timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue +2024-11-06T15:21:23,codecarbon,2ec14d2b-4953-4007-b41d-c7db318b4d4d,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944075577000035,,,,,6.0,,,1.0667413333370253e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 diff --git a/powermetrics_log.txt b/powermetrics_log.txt new file mode 100644 index 00000000..b88054b3 --- /dev/null +++ b/powermetrics_log.txt @@ -0,0 +1,817 @@ +Machine model: MacBookPro16,1 +SMC version: Unknown +EFI version: 2022.22.0 +OS version: 23E214 +Boot arguments: +Boot time: Wed Nov 6 15:12:37 2024 + + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (102.87ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.63W + +LLC flushed residency: 82.1% + +System Average frequency as fraction of nominal: 69.98% (1609.54 Mhz) +Package 0 C-state residency: 84.41% (C2: 9.13% C3: 5.10% C6: 0.00% C7: 70.17% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 13.07% +GPU Active: 0.00% +Avg Num of Cores Active: 0.23 + +Core 0 C-state residency: 89.51% (C3: 1.34% C6: 0.00% C7: 88.17% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 97.21/58.33] [< 32 us: 19.44/0.00] [< 64 us: 48.61/19.44] [< 128 us: 204.15/38.89] [< 256 us: 136.10/68.05] [< 512 us: 29.16/38.89] [< 1024 us: 19.44/48.61] [< 2048 us: 0.00/106.93] [< 4096 us: 0.00/77.77] [< 8192 us: 0.00/97.21] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.20% (1338.67 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 388.85/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.89] [< 128 us: 9.72/38.89] [< 256 us: 0.00/68.05] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/38.89] [< 2048 us: 0.00/58.33] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/77.77] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 68.03% (1564.73 Mhz) + +Core 1 C-state residency: 93.91% (C3: 0.00% C6: 0.00% C7: 93.91% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 223.59/19.44] [< 32 us: 19.44/0.00] [< 64 us: 29.16/0.00] [< 128 us: 77.77/97.21] [< 256 us: 29.16/19.44] [< 512 us: 19.44/38.89] [< 1024 us: 9.72/58.33] [< 2048 us: 9.72/38.89] [< 4096 us: 0.00/38.89] [< 8192 us: 0.00/87.49] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.60% (1324.84 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 184.71/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.72/29.16] [< 128 us: 0.00/29.16] [< 256 us: 0.00/19.44] [< 512 us: 0.00/29.16] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/19.44] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/29.16] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 68.11% (1566.59 Mhz) + +Core 2 C-state residency: 94.37% (C3: 0.00% C6: 0.00% C7: 94.37% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 223.59/38.89] [< 32 us: 29.16/0.00] [< 64 us: 29.16/48.61] [< 128 us: 38.89/48.61] [< 256 us: 9.72/29.16] [< 512 us: 29.16/19.44] [< 1024 us: 0.00/19.44] [< 2048 us: 9.72/38.89] [< 4096 us: 0.00/19.44] [< 8192 us: 0.00/68.05] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 116.24% (2673.46 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 126.38/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.72] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/38.89] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 79.71% (1833.29 Mhz) + +Core 3 C-state residency: 97.08% (C3: 0.00% C6: 0.00% C7: 97.08% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 184.71/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.44/9.72] [< 256 us: 9.72/29.16] [< 512 us: 19.44/58.33] [< 1024 us: 0.00/19.44] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/48.61] [< 16384 us: 0.00/48.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.16% (1337.72 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 111.40% (2562.24 Mhz) + +Core 4 C-state residency: 98.66% (C3: 0.00% C6: 0.00% C7: 98.66% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 97.21/9.72] [< 32 us: 0.00/0.00] [< 64 us: 29.16/0.00] [< 128 us: 0.00/29.16] [< 256 us: 9.72/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/19.44] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 60.93% (1401.46 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.72/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.84% (1652.34 Mhz) + +Core 5 C-state residency: 97.49% (C3: 0.00% C6: 0.00% C7: 97.49% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 68.05/0.00] [< 32 us: 9.72/0.00] [< 64 us: 29.16/0.00] [< 128 us: 38.89/9.72] [< 256 us: 0.00/9.72] [< 512 us: 0.00/29.16] [< 1024 us: 9.72/9.72] [< 2048 us: 0.00/29.16] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/38.89] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 67.63% (1555.58 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 77.77/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.72/9.72] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.04% (1542.01 Mhz) + +Core 6 C-state residency: 98.62% (C3: 0.00% C6: 0.00% C7: 98.62% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 87.49/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 29.16/48.61] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 59.40% (1366.23 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 106.93/0.00] [< 32 us: 0.00/9.72] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.44] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 87.63% (2015.59 Mhz) + +Core 7 C-state residency: 98.90% (C3: 0.00% C6: 0.00% C7: 98.90% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 29.16/0.00] [< 32 us: 9.72/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.44/0.00] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 61.16% (1406.63 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 68.05/0.00] [< 32 us: 9.72/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 92.09% (2118.14 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.17ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.18W + +LLC flushed residency: 81.1% + +System Average frequency as fraction of nominal: 69.36% (1595.28 Mhz) +Package 0 C-state residency: 82.06% (C2: 7.37% C3: 4.73% C6: 0.00% C7: 69.95% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 15.86% +GPU Active: 0.00% +Avg Num of Cores Active: 0.28 + +Core 0 C-state residency: 86.75% (C3: 0.00% C6: 0.00% C7: 86.75% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 28.80/57.60] [< 32 us: 28.80/9.60] [< 64 us: 28.80/0.00] [< 128 us: 124.80/9.60] [< 256 us: 115.20/19.20] [< 512 us: 9.60/9.60] [< 1024 us: 19.20/9.60] [< 2048 us: 0.00/67.20] [< 4096 us: 19.20/105.60] [< 8192 us: 0.00/86.40] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.30% (1547.89 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 278.39/0.00] [< 32 us: 0.00/28.80] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.20] [< 256 us: 0.00/19.20] [< 512 us: 0.00/19.20] [< 1024 us: 0.00/28.80] [< 2048 us: 0.00/38.40] [< 4096 us: 0.00/48.00] [< 8192 us: 0.00/28.80] [< 16384 us: 0.00/38.40] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 61.32% (1410.39 Mhz) + +Core 1 C-state residency: 95.13% (C3: 0.00% C6: 0.00% C7: 95.13% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 124.80/9.60] [< 32 us: 28.80/0.00] [< 64 us: 28.80/9.60] [< 128 us: 28.80/48.00] [< 256 us: 67.20/38.40] [< 512 us: 0.00/9.60] [< 1024 us: 19.20/19.20] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/38.40] [< 8192 us: 0.00/67.20] [< 16384 us: 0.00/38.40] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.09% (1589.03 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 211.19/0.00] [< 32 us: 0.00/19.20] [< 64 us: 0.00/28.80] [< 128 us: 0.00/19.20] [< 256 us: 0.00/9.60] [< 512 us: 0.00/28.80] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/28.80] [< 32768 us: 0.00/19.20] +CPU Average frequency as fraction of nominal: 63.82% (1467.92 Mhz) + +Core 2 C-state residency: 92.00% (C3: 0.00% C6: 0.00% C7: 92.00% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 143.99/19.20] [< 32 us: 9.60/0.00] [< 64 us: 19.20/9.60] [< 128 us: 57.60/48.00] [< 256 us: 19.20/38.40] [< 512 us: 28.80/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/19.20] [< 8192 us: 9.60/57.60] [< 16384 us: 0.00/48.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 77.40% (1780.22 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 124.80/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/9.60] [< 128 us: 0.00/9.60] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 65.82% (1513.92 Mhz) + +Core 3 C-state residency: 97.36% (C3: 0.00% C6: 0.00% C7: 97.36% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 134.40/28.80] [< 32 us: 9.60/0.00] [< 64 us: 28.80/9.60] [< 128 us: 9.60/19.20] [< 256 us: 28.80/28.80] [< 512 us: 9.60/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/57.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 62.24% (1431.57 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 57.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 62.57% (1439.03 Mhz) + +Core 4 C-state residency: 98.76% (C3: 0.00% C6: 0.00% C7: 98.76% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 96.00/0.00] [< 32 us: 9.60/0.00] [< 64 us: 9.60/9.60] [< 128 us: 19.20/28.80] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/38.40] +CPU Average frequency as fraction of nominal: 59.43% (1366.80 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 48.00/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.17% (1475.94 Mhz) + +Core 5 C-state residency: 97.36% (C3: 0.00% C6: 0.00% C7: 97.36% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 28.80/0.00] [< 32 us: 9.60/0.00] [< 64 us: 9.60/0.00] [< 128 us: 19.20/9.60] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 9.60/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 66.35% (1525.98 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 57.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 62.31% (1433.12 Mhz) + +Core 6 C-state residency: 98.89% (C3: 0.00% C6: 0.00% C7: 98.89% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 67.20/0.00] [< 32 us: 9.60/9.60] [< 64 us: 9.60/0.00] [< 128 us: 19.20/0.00] [< 256 us: 0.00/28.80] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 65.74% (1511.99 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 67.20/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 63.68% (1464.75 Mhz) + +Core 7 C-state residency: 98.82% (C3: 0.00% C6: 0.00% C7: 98.82% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 57.60/9.60] [< 32 us: 19.20/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.60/0.00] [< 256 us: 9.60/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/28.80] +CPU Average frequency as fraction of nominal: 57.93% (1332.39 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 48.00/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 62.22% (1430.98 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.37ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 9.65W + +LLC flushed residency: 20.9% + +System Average frequency as fraction of nominal: 133.93% (3080.32 Mhz) +Package 0 C-state residency: 21.43% (C2: 2.66% C3: 0.29% C6: 4.91% C7: 13.58% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 71.04% +GPU Active: 0.00% +Avg Num of Cores Active: 0.97 + +Core 0 C-state residency: 46.39% (C3: 1.42% C6: 0.00% C7: 44.97% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 536.56/392.84] [< 32 us: 105.40/86.23] [< 64 us: 86.23/172.47] [< 128 us: 105.40/162.89] [< 256 us: 124.56/47.91] [< 512 us: 76.65/19.16] [< 1024 us: 19.16/76.65] [< 2048 us: 9.58/86.23] [< 4096 us: 9.58/38.33] [< 8192 us: 19.16/19.16] [< 16384 us: 19.16/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 137.37% (3159.51 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 1082.71/249.12] [< 32 us: 38.33/134.14] [< 64 us: 38.33/105.40] [< 128 us: 9.58/239.54] [< 256 us: 0.00/134.14] [< 512 us: 0.00/67.07] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/76.65] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/57.49] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 134.66% (3097.24 Mhz) + +Core 1 C-state residency: 75.42% (C3: 0.07% C6: 0.00% C7: 75.35% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 1983.37/258.70] [< 32 us: 172.47/948.57] [< 64 us: 76.65/498.24] [< 128 us: 114.98/220.37] [< 256 us: 38.33/95.81] [< 512 us: 47.91/95.81] [< 1024 us: 9.58/76.65] [< 2048 us: 0.00/143.72] [< 4096 us: 9.58/76.65] [< 8192 us: 9.58/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 120.91% (2781.00 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 1264.76/182.05] [< 32 us: 19.16/134.14] [< 64 us: 19.16/277.86] [< 128 us: 9.58/249.12] [< 256 us: 9.58/95.81] [< 512 us: 0.00/86.23] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/153.30] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 137.76% (3168.48 Mhz) + +Core 2 C-state residency: 79.60% (C3: 0.88% C6: 0.00% C7: 78.72% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 804.85/191.63] [< 32 us: 95.81/105.40] [< 64 us: 105.40/124.56] [< 128 us: 76.65/210.79] [< 256 us: 28.74/143.72] [< 512 us: 57.49/105.40] [< 1024 us: 0.00/57.49] [< 2048 us: 0.00/86.23] [< 4096 us: 9.58/105.40] [< 8192 us: 9.58/38.33] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 131.87% (3032.98 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 910.24/153.30] [< 32 us: 19.16/95.81] [< 64 us: 0.00/105.40] [< 128 us: 19.16/182.05] [< 256 us: 0.00/95.81] [< 512 us: 0.00/38.33] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/67.07] [< 4096 us: 0.00/114.98] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 133.30% (3065.93 Mhz) + +Core 3 C-state residency: 74.06% (C3: 0.04% C6: 0.00% C7: 74.02% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 804.85/229.96] [< 32 us: 76.65/277.86] [< 64 us: 124.56/172.47] [< 128 us: 57.49/124.56] [< 256 us: 86.23/67.07] [< 512 us: 28.74/47.91] [< 1024 us: 9.58/38.33] [< 2048 us: 9.58/105.40] [< 4096 us: 0.00/86.23] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 144.93% (3333.50 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 498.24/47.91] [< 32 us: 9.58/0.00] [< 64 us: 0.00/47.91] [< 128 us: 0.00/86.23] [< 256 us: 0.00/57.49] [< 512 us: 0.00/67.07] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/38.33] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/57.49] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.16] +CPU Average frequency as fraction of nominal: 120.95% (2781.92 Mhz) + +Core 4 C-state residency: 95.11% (C3: 0.00% C6: 0.00% C7: 95.11% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 459.91/124.56] [< 32 us: 57.49/19.16] [< 64 us: 38.33/67.07] [< 128 us: 47.91/105.40] [< 256 us: 38.33/67.07] [< 512 us: 9.58/38.33] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/67.07] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 136.08% (3129.85 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 440.75/95.81] [< 32 us: 0.00/19.16] [< 64 us: 0.00/38.33] [< 128 us: 0.00/47.91] [< 256 us: 9.58/47.91] [< 512 us: 0.00/57.49] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 139.06% (3198.40 Mhz) + +Core 5 C-state residency: 94.28% (C3: 0.00% C6: 0.00% C7: 94.28% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 335.35/105.40] [< 32 us: 19.16/9.58] [< 64 us: 57.49/47.91] [< 128 us: 19.16/76.65] [< 256 us: 19.16/28.74] [< 512 us: 28.74/19.16] [< 1024 us: 0.00/38.33] [< 2048 us: 9.58/57.49] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 143.62% (3303.35 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 220.37/19.16] [< 32 us: 0.00/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/19.16] [< 256 us: 0.00/38.33] [< 512 us: 0.00/28.74] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.74] +CPU Average frequency as fraction of nominal: 93.60% (2152.91 Mhz) + +Core 6 C-state residency: 95.80% (C3: 0.00% C6: 0.00% C7: 95.80% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 239.54/105.40] [< 32 us: 38.33/0.00] [< 64 us: 9.58/9.58] [< 128 us: 47.91/57.49] [< 256 us: 19.16/38.33] [< 512 us: 9.58/19.16] [< 1024 us: 19.16/28.74] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.16] +CPU Average frequency as fraction of nominal: 115.08% (2646.90 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 383.26/114.98] [< 32 us: 9.58/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/67.07] [< 256 us: 0.00/47.91] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.74] +CPU Average frequency as fraction of nominal: 109.28% (2513.54 Mhz) + +Core 7 C-state residency: 96.83% (C3: 0.00% C6: 0.00% C7: 96.83% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 210.79/86.23] [< 32 us: 9.58/0.00] [< 64 us: 19.16/28.74] [< 128 us: 28.74/47.91] [< 256 us: 47.91/9.58] [< 512 us: 9.58/19.16] [< 1024 us: 0.00/28.74] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 131.31% (3020.23 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 249.12/9.58] [< 32 us: 0.00/28.74] [< 64 us: 0.00/38.33] [< 128 us: 0.00/47.91] [< 256 us: 0.00/38.33] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 91.27% (2099.14 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.46ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.31W + +LLC flushed residency: 77.6% + +System Average frequency as fraction of nominal: 73.78% (1697.04 Mhz) +Package 0 C-state residency: 78.86% (C2: 9.83% C3: 4.09% C6: 1.98% C7: 62.95% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 18.32% +GPU Active: 0.00% +Avg Num of Cores Active: 0.28 + +Core 0 C-state residency: 85.10% (C3: 0.00% C6: 0.00% C7: 85.10% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 124.45/9.57] [< 32 us: 38.29/38.29] [< 64 us: 28.72/86.16] [< 128 us: 181.89/19.15] [< 256 us: 124.45/28.72] [< 512 us: 67.01/76.59] [< 1024 us: 9.57/76.59] [< 2048 us: 9.57/114.88] [< 4096 us: 9.57/67.01] [< 8192 us: 0.00/76.59] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.56% (1645.92 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 382.93/0.00] [< 32 us: 0.00/9.57] [< 64 us: 0.00/38.29] [< 128 us: 0.00/19.15] [< 256 us: 0.00/38.29] [< 512 us: 0.00/57.44] [< 1024 us: 0.00/57.44] [< 2048 us: 0.00/47.87] [< 4096 us: 0.00/47.87] [< 8192 us: 0.00/38.29] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 67.82% (1559.93 Mhz) + +Core 1 C-state residency: 90.91% (C3: 0.00% C6: 0.00% C7: 90.91% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 201.04/47.87] [< 32 us: 28.72/9.57] [< 64 us: 57.44/38.29] [< 128 us: 95.73/28.72] [< 256 us: 38.29/57.44] [< 512 us: 19.15/38.29] [< 1024 us: 0.00/76.59] [< 2048 us: 0.00/28.72] [< 4096 us: 0.00/38.29] [< 8192 us: 9.57/76.59] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.79% (1812.17 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 172.32/0.00] [< 32 us: 9.57/9.57] [< 64 us: 0.00/19.15] [< 128 us: 0.00/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/28.72] [< 1024 us: 0.00/38.29] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 70.63% (1624.55 Mhz) + +Core 2 C-state residency: 94.64% (C3: 0.00% C6: 0.00% C7: 94.64% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 277.62/9.57] [< 32 us: 28.72/0.00] [< 64 us: 28.72/28.72] [< 128 us: 19.15/86.16] [< 256 us: 19.15/38.29] [< 512 us: 38.29/28.72] [< 1024 us: 9.57/67.01] [< 2048 us: 0.00/67.01] [< 4096 us: 0.00/28.72] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/38.29] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 67.88% (1561.19 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 153.17/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/9.57] [< 128 us: 0.00/9.57] [< 256 us: 0.00/28.72] [< 512 us: 0.00/9.57] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/28.72] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.72] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.24% (1569.56 Mhz) + +Core 3 C-state residency: 97.42% (C3: 0.00% C6: 0.00% C7: 97.42% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 172.32/0.00] [< 32 us: 47.87/0.00] [< 64 us: 19.15/0.00] [< 128 us: 9.57/19.15] [< 256 us: 9.57/28.72] [< 512 us: 9.57/47.87] [< 1024 us: 0.00/57.44] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/28.72] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/28.72] +CPU Average frequency as fraction of nominal: 66.89% (1538.56 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.57] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 72.30% (1662.83 Mhz) + +Core 4 C-state residency: 98.98% (C3: 0.00% C6: 0.00% C7: 98.98% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 74.35% (1710.04 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 67.01/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.15] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 73.26% (1684.87 Mhz) + +Core 5 C-state residency: 97.18% (C3: 0.00% C6: 0.00% C7: 97.18% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 67.01/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/19.15] [< 128 us: 9.57/0.00] [< 256 us: 0.00/9.57] [< 512 us: 9.57/0.00] [< 1024 us: 0.00/28.72] [< 2048 us: 9.57/9.57] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.72] +CPU Average frequency as fraction of nominal: 83.47% (1919.78 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 66.85% (1537.45 Mhz) + +Core 6 C-state residency: 99.22% (C3: 0.00% C6: 0.00% C7: 99.22% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 73.97% (1701.28 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.94% (1608.53 Mhz) + +Core 7 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 64.77% (1489.79 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/9.57] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.61% (1555.01 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (103.88ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 2.51W + +LLC flushed residency: 67.5% + +System Average frequency as fraction of nominal: 97.92% (2252.27 Mhz) +Package 0 C-state residency: 68.50% (C2: 7.24% C3: 3.45% C6: 0.00% C7: 57.81% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 29.41% +GPU Active: 0.00% +Avg Num of Cores Active: 0.40 + +Core 0 C-state residency: 73.20% (C3: 0.08% C6: 0.00% C7: 73.12% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 413.95/77.01] [< 32 us: 19.25/38.51] [< 64 us: 38.51/115.52] [< 128 us: 163.65/182.91] [< 256 us: 48.13/48.13] [< 512 us: 38.51/28.88] [< 1024 us: 48.13/28.88] [< 2048 us: 0.00/134.77] [< 4096 us: 9.63/77.01] [< 8192 us: 9.63/48.13] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 88.68% (2039.57 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 490.96/9.63] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.51] [< 128 us: 0.00/96.27] [< 256 us: 0.00/96.27] [< 512 us: 0.00/28.88] [< 1024 us: 0.00/96.27] [< 2048 us: 0.00/48.13] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 83.30% (1915.92 Mhz) + +Core 1 C-state residency: 83.97% (C3: 0.10% C6: 0.00% C7: 83.87% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 433.20/154.03] [< 32 us: 38.51/19.25] [< 64 us: 67.39/125.15] [< 128 us: 96.27/96.27] [< 256 us: 48.13/96.27] [< 512 us: 19.25/48.13] [< 1024 us: 19.25/48.13] [< 2048 us: 19.25/38.51] [< 4096 us: 0.00/19.25] [< 8192 us: 0.00/67.39] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 95.83% (2204.10 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 452.46/57.76] [< 32 us: 0.00/48.13] [< 64 us: 0.00/96.27] [< 128 us: 0.00/38.51] [< 256 us: 0.00/19.25] [< 512 us: 0.00/19.25] [< 1024 us: 0.00/67.39] [< 2048 us: 0.00/28.88] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/28.88] [< 16384 us: 0.00/28.88] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 86.71% (1994.26 Mhz) + +Core 2 C-state residency: 89.49% (C3: 0.01% C6: 0.00% C7: 89.48% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 385.07/77.01] [< 32 us: 38.51/38.51] [< 64 us: 38.51/77.01] [< 128 us: 38.51/77.01] [< 256 us: 19.25/77.01] [< 512 us: 19.25/57.76] [< 1024 us: 0.00/57.76] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 92.98% (2138.57 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 336.94/77.01] [< 32 us: 0.00/28.88] [< 64 us: 0.00/19.25] [< 128 us: 0.00/48.13] [< 256 us: 0.00/19.25] [< 512 us: 0.00/38.51] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.25] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 88.82% (2042.88 Mhz) + +Core 3 C-state residency: 89.00% (C3: 0.00% C6: 0.00% C7: 89.00% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 202.16/9.63] [< 32 us: 19.25/0.00] [< 64 us: 0.00/38.51] [< 128 us: 57.76/28.88] [< 256 us: 0.00/67.39] [< 512 us: 9.63/48.13] [< 1024 us: 28.88/48.13] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/19.25] [< 8192 us: 9.63/19.25] [< 16384 us: 0.00/28.88] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 118.16% (2717.78 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 48.13/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/28.88] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.67% (1487.44 Mhz) + +Core 4 C-state residency: 98.73% (C3: 0.00% C6: 0.00% C7: 98.73% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 86.64/0.00] [< 32 us: 9.63/0.00] [< 64 us: 9.63/28.88] [< 128 us: 28.88/9.63] [< 256 us: 0.00/9.63] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 104.21% (2396.89 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.25] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 79.83% (1836.00 Mhz) + +Core 5 C-state residency: 99.29% (C3: 0.00% C6: 0.00% C7: 99.29% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.63] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 82.60% (1899.75 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.45% (1620.37 Mhz) + +Core 6 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.87% (1584.08 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.83% (1652.19 Mhz) + +Core 7 C-state residency: 99.46% (C3: 0.00% C6: 0.00% C7: 99.46% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.18% (1568.13 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/9.63] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.06% (1611.29 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.09ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 4.84W + +LLC flushed residency: 40.4% + +System Average frequency as fraction of nominal: 98.03% (2254.73 Mhz) +Package 0 C-state residency: 41.40% (C2: 5.26% C3: 2.47% C6: 1.63% C7: 32.04% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 56.77% +GPU Active: 0.00% +Avg Num of Cores Active: 0.73 + +Core 0 C-state residency: 77.11% (C3: 0.00% C6: 0.00% C7: 77.11% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 115.29/9.61] [< 32 us: 48.04/9.61] [< 64 us: 28.82/38.43] [< 128 us: 124.90/38.43] [< 256 us: 86.47/19.21] [< 512 us: 28.82/105.68] [< 1024 us: 9.61/67.25] [< 2048 us: 28.82/86.47] [< 4096 us: 9.61/67.25] [< 8192 us: 9.61/38.43] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.77% (1604.72 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 441.94/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/28.82] [< 128 us: 0.00/38.43] [< 256 us: 0.00/28.82] [< 512 us: 0.00/38.43] [< 1024 us: 0.00/105.68] [< 2048 us: 0.00/76.86] [< 4096 us: 0.00/57.64] [< 8192 us: 0.00/28.82] [< 16384 us: 0.00/28.82] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.33% (1801.51 Mhz) + +Core 1 C-state residency: 56.98% (C3: 0.01% C6: 0.00% C7: 56.97% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 355.48/57.64] [< 32 us: 19.21/9.61] [< 64 us: 57.64/96.07] [< 128 us: 48.04/105.68] [< 256 us: 48.04/57.64] [< 512 us: 9.61/57.64] [< 1024 us: 9.61/124.90] [< 2048 us: 38.43/38.43] [< 4096 us: 9.61/28.82] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/28.82] [< 32768 us: 9.61/0.00] +CPU Average frequency as fraction of nominal: 118.92% (2735.18 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 374.69/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/48.04] [< 128 us: 0.00/76.86] [< 256 us: 0.00/28.82] [< 512 us: 0.00/48.04] [< 1024 us: 0.00/57.64] [< 2048 us: 0.00/48.04] [< 4096 us: 0.00/19.21] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/19.21] [< 32768 us: 0.00/19.21] +CPU Average frequency as fraction of nominal: 71.96% (1655.15 Mhz) + +Core 2 C-state residency: 86.83% (C3: 0.04% C6: 0.00% C7: 86.79% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 365.08/38.43] [< 32 us: 57.64/9.61] [< 64 us: 76.86/96.07] [< 128 us: 57.64/105.68] [< 256 us: 0.00/86.47] [< 512 us: 0.00/28.82] [< 1024 us: 9.61/48.04] [< 2048 us: 9.61/38.43] [< 4096 us: 0.00/38.43] [< 8192 us: 0.00/38.43] [< 16384 us: 0.00/38.43] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 77.23% (1776.34 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 384.30/19.21] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.21] [< 128 us: 0.00/48.04] [< 256 us: 0.00/48.04] [< 512 us: 0.00/76.86] [< 1024 us: 0.00/48.04] [< 2048 us: 0.00/38.43] [< 4096 us: 0.00/38.43] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/38.43] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 71.01% (1633.22 Mhz) + +Core 3 C-state residency: 93.67% (C3: 0.00% C6: 0.00% C7: 93.67% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 230.58/28.82] [< 32 us: 19.21/0.00] [< 64 us: 57.64/28.82] [< 128 us: 19.21/86.47] [< 256 us: 28.82/0.00] [< 512 us: 0.00/38.43] [< 1024 us: 28.82/48.04] [< 2048 us: 9.61/48.04] [< 4096 us: 0.00/28.82] [< 8192 us: 0.00/38.43] [< 16384 us: 0.00/28.82] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 74.03% (1702.80 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 76.86/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.61] [< 256 us: 0.00/9.61] [< 512 us: 0.00/28.82] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 65.13% (1498.00 Mhz) + +Core 4 C-state residency: 97.79% (C3: 0.00% C6: 0.00% C7: 97.79% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 182.54/0.00] [< 32 us: 9.61/0.00] [< 64 us: 19.21/19.21] [< 128 us: 9.61/38.43] [< 256 us: 9.61/57.64] [< 512 us: 9.61/0.00] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/28.82] [< 4096 us: 0.00/19.21] [< 8192 us: 0.00/19.21] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 75.13% (1727.94 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 124.90/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/9.61] [< 128 us: 0.00/19.21] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 65.36% (1503.23 Mhz) + +Core 5 C-state residency: 98.63% (C3: 0.00% C6: 0.00% C7: 98.63% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 144.11/48.04] [< 32 us: 38.43/0.00] [< 64 us: 0.00/9.61] [< 128 us: 9.61/48.04] [< 256 us: 9.61/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/19.21] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 69.64% (1601.70 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 48.04/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.17% (1429.92 Mhz) + +Core 6 C-state residency: 99.19% (C3: 0.00% C6: 0.00% C7: 99.19% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 19.21/0.00] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 28.82/0.00] [< 256 us: 0.00/9.61] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.82% (1352.89 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 57.64/0.00] [< 32 us: 9.61/9.61] [< 64 us: 0.00/19.21] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.89% (1469.58 Mhz) + +Core 7 C-state residency: 99.25% (C3: 0.00% C6: 0.00% C7: 99.25% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 38.43/0.00] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 9.61/0.00] [< 256 us: 0.00/9.61] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 60.16% (1383.65 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 48.04/0.00] [< 32 us: 9.61/9.61] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.61] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.49% (1483.26 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.36ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.48W + +LLC flushed residency: 64.1% + +System Average frequency as fraction of nominal: 60.01% (1380.21 Mhz) +Package 0 C-state residency: 65.09% (C2: 6.04% C3: 4.55% C6: 0.00% C7: 54.50% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 33.30% +GPU Active: 0.00% +Avg Num of Cores Active: 0.41 + +Core 0 C-state residency: 86.19% (C3: 0.00% C6: 0.00% C7: 86.19% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 38.33/28.75] [< 32 us: 0.00/0.00] [< 64 us: 9.58/9.58] [< 128 us: 124.57/28.75] [< 256 us: 95.83/0.00] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/0.00] [< 2048 us: 0.00/67.08] [< 4096 us: 0.00/86.24] [< 8192 us: 0.00/57.50] [< 16384 us: 9.58/19.17] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.14% (1429.23 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 210.82/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/28.75] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 58.90% (1354.75 Mhz) + +Core 1 C-state residency: 94.87% (C3: 0.00% C6: 0.00% C7: 94.87% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 76.66/28.75] [< 32 us: 9.58/0.00] [< 64 us: 57.50/9.58] [< 128 us: 28.75/9.58] [< 256 us: 19.17/0.00] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.58] [< 4096 us: 9.58/28.75] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 72.80% (1674.47 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 86.24/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 58.55% (1346.76 Mhz) + +Core 2 C-state residency: 98.20% (C3: 0.00% C6: 0.00% C7: 98.20% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 86.24/19.17] [< 32 us: 19.17/0.00] [< 64 us: 47.91/19.17] [< 128 us: 28.75/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 56.94% (1309.72 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 86.24/0.00] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 58.51% (1345.73 Mhz) + +Core 3 C-state residency: 97.94% (C3: 0.00% C6: 0.00% C7: 97.94% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 86.24/47.91] [< 32 us: 28.75/0.00] [< 64 us: 19.17/0.00] [< 128 us: 28.75/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 56.82% (1306.77 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 47.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 58.29% (1340.59 Mhz) + +Core 4 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 38.33/9.58] [< 32 us: 9.58/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.75] +CPU Average frequency as fraction of nominal: 58.15% (1337.47 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 67.08/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.17] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 60.99% (1402.71 Mhz) + +Core 5 C-state residency: 99.02% (C3: 0.00% C6: 0.00% C7: 99.02% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.29% (1317.62 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 61.39% (1412.03 Mhz) + +Core 6 C-state residency: 79.36% (C3: 0.00% C6: 0.00% C7: 79.36% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 9.58/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 56.54% (1300.40 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.53% (1461.23 Mhz) + +Core 7 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.82% (1329.82 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 47.91/19.17] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.45% (1344.25 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.01ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.62W + +LLC flushed residency: 65.5% + +System Average frequency as fraction of nominal: 60.14% (1383.16 Mhz) +Package 0 C-state residency: 66.43% (C2: 5.32% C3: 4.49% C6: 0.00% C7: 56.61% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 31.87% +GPU Active: 0.00% +Avg Num of Cores Active: 0.54 + +Core 0 C-state residency: 83.04% (C3: 0.00% C6: 0.00% C7: 83.04% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 230.75/57.69] [< 32 us: 48.07/0.00] [< 64 us: 57.69/86.53] [< 128 us: 124.99/134.60] [< 256 us: 105.76/76.92] [< 512 us: 28.84/48.07] [< 1024 us: 28.84/38.46] [< 2048 us: 28.84/86.53] [< 4096 us: 9.61/57.69] [< 8192 us: 0.00/48.07] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.25% (1454.86 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 644.17/48.07] [< 32 us: 0.00/19.23] [< 64 us: 0.00/28.84] [< 128 us: 19.23/173.06] [< 256 us: 9.61/67.30] [< 512 us: 0.00/76.92] [< 1024 us: 0.00/76.92] [< 2048 us: 0.00/76.92] [< 4096 us: 0.00/48.07] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/28.84] [< 32768 us: 0.00/19.23] +CPU Average frequency as fraction of nominal: 57.37% (1319.43 Mhz) + +Core 1 C-state residency: 87.78% (C3: 0.00% C6: 0.00% C7: 87.78% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 173.06/19.23] [< 32 us: 28.84/9.61] [< 64 us: 67.30/19.23] [< 128 us: 28.84/48.07] [< 256 us: 19.23/28.84] [< 512 us: 28.84/67.30] [< 1024 us: 19.23/86.53] [< 2048 us: 19.23/28.84] [< 4096 us: 19.23/38.46] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/19.23] +CPU Average frequency as fraction of nominal: 58.04% (1334.93 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 288.44/38.46] [< 32 us: 0.00/19.23] [< 64 us: 0.00/19.23] [< 128 us: 9.61/28.84] [< 256 us: 19.23/57.69] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/38.46] [< 2048 us: 0.00/28.84] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 57.07% (1312.58 Mhz) + +Core 2 C-state residency: 89.81% (C3: 0.00% C6: 0.00% C7: 89.81% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 163.45/0.00] [< 32 us: 67.30/0.00] [< 64 us: 9.61/19.23] [< 128 us: 28.84/57.69] [< 256 us: 0.00/28.84] [< 512 us: 19.23/57.69] [< 1024 us: 19.23/48.07] [< 2048 us: 19.23/38.46] [< 4096 us: 9.61/19.23] [< 8192 us: 0.00/38.46] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/19.23] +CPU Average frequency as fraction of nominal: 58.04% (1334.92 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 346.12/28.84] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/48.07] [< 256 us: 0.00/19.23] [< 512 us: 9.61/48.07] [< 1024 us: 0.00/76.92] [< 2048 us: 0.00/48.07] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/28.84] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] +CPU Average frequency as fraction of nominal: 57.33% (1318.70 Mhz) + +Core 3 C-state residency: 95.29% (C3: 0.00% C6: 0.00% C7: 95.29% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 124.99/9.61] [< 32 us: 0.00/0.00] [< 64 us: 19.23/0.00] [< 128 us: 57.69/0.00] [< 256 us: 38.46/28.84] [< 512 us: 9.61/48.07] [< 1024 us: 0.00/48.07] [< 2048 us: 9.61/48.07] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/19.23] +CPU Average frequency as fraction of nominal: 56.64% (1302.80 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 96.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.61/9.61] [< 128 us: 19.23/28.84] [< 256 us: 9.61/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/38.46] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.24% (1316.50 Mhz) + +Core 4 C-state residency: 96.61% (C3: 0.00% C6: 0.00% C7: 96.61% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 57.69/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/0.00] [< 128 us: 9.61/0.00] [< 256 us: 9.61/0.00] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 9.61/9.61] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.82% (1306.94 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 134.60/38.46] [< 32 us: 0.00/9.61] [< 64 us: 9.61/9.61] [< 128 us: 0.00/9.61] [< 256 us: 9.61/9.61] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/28.84] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.70% (1327.07 Mhz) + +Core 5 C-state residency: 95.70% (C3: 0.00% C6: 0.00% C7: 95.70% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 38.46/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.52% (1345.95 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 144.22/9.61] [< 32 us: 0.00/9.61] [< 64 us: 0.00/38.46] [< 128 us: 9.61/9.61] [< 256 us: 0.00/9.61] [< 512 us: 0.00/28.84] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.05% (1335.13 Mhz) + +Core 6 C-state residency: 90.03% (C3: 0.00% C6: 0.00% C7: 90.03% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 38.46/19.23] [< 32 us: 19.23/0.00] [< 64 us: 9.61/9.61] [< 128 us: 9.61/0.00] [< 256 us: 0.00/19.23] [< 512 us: 19.23/9.61] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.61] [< 4096 us: 9.61/19.23] [< 8192 us: 9.61/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.76% (1466.37 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 96.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.61] [< 128 us: 9.61/9.61] [< 256 us: 9.61/19.23] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/19.23] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.16% (1314.61 Mhz) + +Core 7 C-state residency: 98.34% (C3: 0.00% C6: 0.00% C7: 98.34% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 67.30/9.61] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 9.61/19.23] [< 256 us: 0.00/9.61] [< 512 us: 19.23/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.88% (1308.15 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 134.60/19.23] [< 32 us: 0.00/19.23] [< 64 us: 0.00/9.61] [< 128 us: 19.23/28.84] [< 256 us: 0.00/9.61] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.93% (1332.48 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.14ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 1.32W + +LLC flushed residency: 74.5% + +System Average frequency as fraction of nominal: 61.90% (1423.80 Mhz) +Package 0 C-state residency: 75.84% (C2: 8.39% C3: 3.87% C6: 1.67% C7: 61.92% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 21.94% +GPU Active: 0.00% +Avg Num of Cores Active: 0.34 + +Core 0 C-state residency: 86.82% (C3: 0.00% C6: 0.00% C7: 86.82% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 105.63/57.61] [< 32 us: 38.41/9.60] [< 64 us: 38.41/19.20] [< 128 us: 134.43/67.22] [< 256 us: 86.42/28.81] [< 512 us: 48.01/76.82] [< 1024 us: 48.01/28.81] [< 2048 us: 19.20/96.02] [< 4096 us: 0.00/48.01] [< 8192 us: 0.00/96.02] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.91% (1332.02 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 364.89/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.81] [< 128 us: 0.00/48.01] [< 256 us: 0.00/38.41] [< 512 us: 0.00/19.20] [< 1024 us: 0.00/38.41] [< 2048 us: 0.00/48.01] [< 4096 us: 0.00/38.41] [< 8192 us: 0.00/67.22] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.92% (1470.08 Mhz) + +Core 1 C-state residency: 95.13% (C3: 0.00% C6: 0.00% C7: 95.13% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 201.65/9.60] [< 32 us: 0.00/0.00] [< 64 us: 67.22/19.20] [< 128 us: 28.81/48.01] [< 256 us: 38.41/9.60] [< 512 us: 0.00/38.41] [< 1024 us: 19.20/48.01] [< 2048 us: 0.00/38.41] [< 4096 us: 0.00/48.01] [< 8192 us: 0.00/67.22] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.06% (1335.45 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 182.44/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/9.60] [< 128 us: 9.60/9.60] [< 256 us: 0.00/19.20] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/28.81] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/57.61] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 60.13% (1383.10 Mhz) + +Core 2 C-state residency: 96.56% (C3: 0.00% C6: 0.00% C7: 96.56% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 163.24/28.81] [< 32 us: 0.00/0.00] [< 64 us: 28.81/9.60] [< 128 us: 19.20/19.20] [< 256 us: 19.20/9.60] [< 512 us: 0.00/9.60] [< 1024 us: 19.20/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/28.81] [< 8192 us: 0.00/57.61] [< 16384 us: 0.00/48.01] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 59.36% (1365.28 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 153.64/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.20] [< 256 us: 0.00/19.20] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/19.20] +CPU Average frequency as fraction of nominal: 66.66% (1533.23 Mhz) + +Core 3 C-state residency: 97.00% (C3: 0.00% C6: 0.00% C7: 97.00% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 96.02/38.41] [< 32 us: 0.00/0.00] [< 64 us: 38.41/0.00] [< 128 us: 28.81/38.41] [< 256 us: 38.41/9.60] [< 512 us: 0.00/19.20] [< 1024 us: 9.60/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/57.61] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 57.64% (1325.75 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 76.82/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/19.20] +CPU Average frequency as fraction of nominal: 71.16% (1636.70 Mhz) + +Core 4 C-state residency: 96.66% (C3: 0.00% C6: 0.00% C7: 96.66% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 86.42/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.60] [< 128 us: 9.60/19.20] [< 256 us: 19.20/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/19.20] [< 2048 us: 9.60/9.60] [< 4096 us: 0.00/19.20] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] +CPU Average frequency as fraction of nominal: 69.62% (1601.19 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 134.43/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.20] [< 128 us: 0.00/19.20] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.20] +CPU Average frequency as fraction of nominal: 73.20% (1683.49 Mhz) + +Core 5 C-state residency: 91.77% (C3: 0.00% C6: 0.00% C7: 91.77% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 86.42/19.20] [< 32 us: 9.60/0.00] [< 64 us: 19.20/19.20] [< 128 us: 9.60/19.20] [< 256 us: 9.60/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/28.81] [< 2048 us: 0.00/0.00] [< 4096 us: 19.20/0.00] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] +CPU Average frequency as fraction of nominal: 70.61% (1624.07 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 67.22/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 63.94% (1470.67 Mhz) + +Core 6 C-state residency: 98.60% (C3: 0.00% C6: 0.00% C7: 98.60% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 57.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.60/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] +CPU Average frequency as fraction of nominal: 57.37% (1319.57 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 28.81/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 73.71% (1695.23 Mhz) + +Core 7 C-state residency: 96.33% (C3: 0.00% C6: 0.00% C7: 96.33% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 28.81/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.60/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 9.60/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 56.71% (1304.35 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 57.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.68% (1579.65 Mhz) + + +*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (103.87ms elapsed) *** + + +**** Processor usage **** + +Intel energy model derived package power (CPUs+GT+SA): 0.79W + +LLC flushed residency: 86.3% + +System Average frequency as fraction of nominal: 63.83% (1468.17 Mhz) +Package 0 C-state residency: 87.31% (C2: 8.20% C3: 4.67% C6: 0.00% C7: 74.44% C8: 0.00% C9: 0.00% C10: 0.00% ) +CPU/GPU Overlap: 0.00% +Cores Active: 10.20% +GPU Active: 0.00% +Avg Num of Cores Active: 0.15 + +Core 0 C-state residency: 89.68% (C3: 0.00% C6: 0.00% C7: 89.68% ) + +CPU 0 duty cycles/s: active/idle [< 16 us: 28.88/28.88] [< 32 us: 86.65/0.00] [< 64 us: 19.25/19.25] [< 128 us: 163.67/67.39] [< 256 us: 96.27/19.25] [< 512 us: 9.63/9.63] [< 1024 us: 9.63/19.25] [< 2048 us: 0.00/115.53] [< 4096 us: 9.63/48.14] [< 8192 us: 0.00/86.65] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.81% (1513.66 Mhz) + +CPU 1 duty cycles/s: active/idle [< 16 us: 173.29/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/38.51] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.58% (1439.27 Mhz) + +Core 1 C-state residency: 95.97% (C3: 0.00% C6: 0.00% C7: 95.97% ) + +CPU 2 duty cycles/s: active/idle [< 16 us: 96.27/0.00] [< 32 us: 0.00/0.00] [< 64 us: 57.76/9.63] [< 128 us: 38.51/28.88] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.63/9.63] [< 2048 us: 9.63/48.14] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/57.76] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/19.25] +CPU Average frequency as fraction of nominal: 60.65% (1394.93 Mhz) + +CPU 3 duty cycles/s: active/idle [< 16 us: 115.53/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/19.25] +CPU Average frequency as fraction of nominal: 64.12% (1474.70 Mhz) + +Core 2 C-state residency: 97.57% (C3: 0.00% C6: 0.00% C7: 97.57% ) + +CPU 4 duty cycles/s: active/idle [< 16 us: 125.16/19.25] [< 32 us: 38.51/0.00] [< 64 us: 19.25/9.63] [< 128 us: 28.88/38.51] [< 256 us: 9.63/0.00] [< 512 us: 9.63/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/48.14] [< 16384 us: 0.00/38.51] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 60.48% (1390.93 Mhz) + +CPU 5 duty cycles/s: active/idle [< 16 us: 96.27/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/19.25] [< 256 us: 0.00/9.63] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.25] +CPU Average frequency as fraction of nominal: 65.09% (1496.99 Mhz) + +Core 3 C-state residency: 97.95% (C3: 0.00% C6: 0.00% C7: 97.95% ) + +CPU 6 duty cycles/s: active/idle [< 16 us: 77.02/9.63] [< 32 us: 0.00/0.00] [< 64 us: 19.25/0.00] [< 128 us: 19.25/9.63] [< 256 us: 28.88/9.63] [< 512 us: 9.63/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/19.25] [< 16384 us: 0.00/38.51] [< 32768 us: 0.00/19.25] +CPU Average frequency as fraction of nominal: 61.94% (1424.51 Mhz) + +CPU 7 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 75.91% (1745.85 Mhz) + +Core 4 C-state residency: 98.81% (C3: 0.00% C6: 0.00% C7: 98.81% ) + +CPU 8 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.63/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.63/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/19.25] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 58.05% (1335.25 Mhz) + +CPU 9 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.05% (1795.24 Mhz) + +Core 5 C-state residency: 99.47% (C3: 0.00% C6: 0.00% C7: 99.47% ) + +CPU 10 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 70.32% (1617.30 Mhz) + +CPU 11 duty cycles/s: active/idle [< 16 us: 19.25/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.31% (1801.12 Mhz) + +Core 6 C-state residency: 99.33% (C3: 0.00% C6: 0.00% C7: 99.33% ) + +CPU 12 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 9.63/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.63] +CPU Average frequency as fraction of nominal: 61.07% (1404.60 Mhz) + +CPU 13 duty cycles/s: active/idle [< 16 us: 48.14/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 74.18% (1706.16 Mhz) + +Core 7 C-state residency: 99.47% (C3: 0.00% C6: 0.00% C7: 99.47% ) + +CPU 14 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.68% (1510.60 Mhz) + +CPU 15 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.81% (1812.74 Mhz) diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py index f169f726..b5241feb 100644 --- a/src/measurement/code_carbon_meter.py +++ b/src/measurement/code_carbon_meter.py @@ -1,9 +1,16 @@ import subprocess +import sys from codecarbon import EmissionsTracker from pathlib import Path # To run run # pip install codecarbon +from os.path import dirname, abspath +import sys + +# Sets src as absolute path, everything needs to be relative to src folder +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) class CarbonAnalyzer: @@ -46,6 +53,8 @@ def save_report(self, report_path: str = "carbon_report.csv"): data = self.tracker.emissions_data if data: df = pd.DataFrame(data) + print("THIS IS THE DF:") + print(df) df.to_csv(report_path, index=False) print(f"Report saved to {report_path}") else: @@ -54,8 +63,6 @@ def save_report(self, report_path: str = "carbon_report.csv"): # Example usage if __name__ == "__main__": - analyzer = CarbonAnalyzer("/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/test/inefficent_code_example.py") + analyzer = CarbonAnalyzer("test/inefficent_code_example.py") analyzer.run_and_measure() - analyzer.save_report( - "/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/measurement/carbon_report.csv" - ) + analyzer.save_report("test/carbon_report.csv") From bd9656f7057ee42b0db7d28ecfe618bd5e9dce1d Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:34:58 -0500 Subject: [PATCH 016/105] made path fixes --- src/measurement/code_carbon_meter.py | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py index 8bfd94e2..3e2b6313 100644 --- a/src/measurement/code_carbon_meter.py +++ b/src/measurement/code_carbon_meter.py @@ -1,18 +1,27 @@ import subprocess from codecarbon import EmissionsTracker from pathlib import Path +import pandas as pd + +from os.path import dirname, abspath +import sys + +# FOR TESTING!!! Not necessary when running from main +# Sets src as absolute path, everything needs to be relative to src folder +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) # To run run # pip install codecarbon class CarbonAnalyzer: - def __init__(self, script_path: str): + def __init__(self, script_path: str, report_path: str): """ Initialize with the path to the Python script to analyze. """ self.script_path = script_path - self.tracker = EmissionsTracker() + self.tracker = EmissionsTracker(output_file=report_path) def run_and_measure(self): """ @@ -37,13 +46,11 @@ def run_and_measure(self): emissions = self.tracker.stop() print("Emissions data:", emissions) - def save_report(self, report_path: str = "carbon_report.csv"): + def save_report(self, report_path: str): """ Save the emissions report to a CSV file. """ - import pandas as pd - - data = self.tracker.emissions_data + data = self.tracker.final_emissions_data if data: df = pd.DataFrame(data) df.to_csv(report_path, index=False) @@ -54,8 +61,10 @@ def save_report(self, report_path: str = "carbon_report.csv"): # Example usage if __name__ == "__main__": - analyzer = CarbonAnalyzer("/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/test/inefficent_code_example.py") + + TEST_FILE_PATH = abspath("test/inefficent_code_example.py") + REPORT_FILE_PATH = abspath("src/output/carbon_report.csv") + print(REPORT_FILE_PATH) + analyzer = CarbonAnalyzer(TEST_FILE_PATH, REPORT_FILE_PATH) analyzer.run_and_measure() - analyzer.save_report( - "/Users/mya/Code/Capstone/capstone--source-code-optimizer/src/measurement/carbon_report.csv" - ) + analyzer.save_report(REPORT_FILE_PATH) From dcd3ad0d67619f61bc5ffdc4b7ceea0d5ed643dc Mon Sep 17 00:00:00 2001 From: mya Date: Wed, 6 Nov 2024 15:41:51 -0500 Subject: [PATCH 017/105] Fixed code carbon --- emissions.csv | 7 + powermetrics_log.txt | 940 +++++++++++++-------------- src/measurement/code_carbon_meter.py | 52 +- test/carbon_report.csv | 33 + 4 files changed, 532 insertions(+), 500 deletions(-) create mode 100644 test/carbon_report.csv diff --git a/emissions.csv b/emissions.csv index 165f1ccf..6e513fc3 100644 --- a/emissions.csv +++ b/emissions.csv @@ -1,2 +1,9 @@ timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue 2024-11-06T15:21:23,codecarbon,2ec14d2b-4953-4007-b41d-c7db318b4d4d,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944075577000035,,,,,6.0,,,1.0667413333370253e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:31:43,codecarbon,560d6fac-3aa6-47f5-85ca-0d25d8489762,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.8978115110001,,,,,6.0,,,8.699338333523581e-09,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:33:37,codecarbon,b8f4cef7-225e-4119-89f8-e453b5a9f666,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.9268195259999175,,,,,6.0,,,8.771991000003254e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:35:02,codecarbon,e2d61f7a-9ac9-4089-ae49-c33869d93080,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.936623557999837,,,,,6.0,,,8.79429716667346e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:36:07,codecarbon,532ad45f-7e13-4689-ab66-6292208f6b21,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.927878704000023,,,,,6.0,,,8.450502833322089e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:37:41,codecarbon,d7c396c8-6e78-460a-b888-30e09802ba5b,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944484815000124,,,,,6.0,,,8.56689950001055e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:40:04,codecarbon,cb6477c2-f7d1-4b05-82d2-30c0431852e1,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.977463085000181,,,,,6.0,,,8.772543833363975e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:41:03,codecarbon,7de42608-e864-4267-bcac-db887eedee97,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944858557000089,,,,,6.0,,,8.524578333322096e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 diff --git a/powermetrics_log.txt b/powermetrics_log.txt index b88054b3..f3c78899 100644 --- a/powermetrics_log.txt +++ b/powermetrics_log.txt @@ -7,811 +7,811 @@ Boot time: Wed Nov 6 15:12:37 2024 -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (102.87ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (102.89ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.63W +Intel energy model derived package power (CPUs+GT+SA): 1.56W -LLC flushed residency: 82.1% +LLC flushed residency: 85.6% -System Average frequency as fraction of nominal: 69.98% (1609.54 Mhz) -Package 0 C-state residency: 84.41% (C2: 9.13% C3: 5.10% C6: 0.00% C7: 70.17% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 77.75% (1788.25 Mhz) +Package 0 C-state residency: 86.77% (C2: 8.30% C3: 4.09% C6: 0.00% C7: 74.38% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 13.07% +Cores Active: 10.93% GPU Active: 0.00% -Avg Num of Cores Active: 0.23 +Avg Num of Cores Active: 0.16 -Core 0 C-state residency: 89.51% (C3: 1.34% C6: 0.00% C7: 88.17% ) +Core 0 C-state residency: 90.34% (C3: 0.00% C6: 0.00% C7: 90.34% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 97.21/58.33] [< 32 us: 19.44/0.00] [< 64 us: 48.61/19.44] [< 128 us: 204.15/38.89] [< 256 us: 136.10/68.05] [< 512 us: 29.16/38.89] [< 1024 us: 19.44/48.61] [< 2048 us: 0.00/106.93] [< 4096 us: 0.00/77.77] [< 8192 us: 0.00/97.21] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.20% (1338.67 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 77.75/29.16] [< 32 us: 19.44/0.00] [< 64 us: 29.16/58.32] [< 128 us: 174.95/9.72] [< 256 us: 87.47/9.72] [< 512 us: 9.72/48.60] [< 1024 us: 19.44/9.72] [< 2048 us: 9.72/58.32] [< 4096 us: 0.00/116.63] [< 8192 us: 0.00/87.47] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 72.31% (1663.08 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 388.85/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.89] [< 128 us: 9.72/38.89] [< 256 us: 0.00/68.05] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/38.89] [< 2048 us: 0.00/58.33] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/77.77] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 68.03% (1564.73 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 291.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.88] [< 128 us: 0.00/19.44] [< 256 us: 0.00/0.00] [< 512 us: 0.00/29.16] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/68.03] [< 8192 us: 0.00/48.60] [< 16384 us: 0.00/48.60] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 77.86% (1790.76 Mhz) -Core 1 C-state residency: 93.91% (C3: 0.00% C6: 0.00% C7: 93.91% ) +Core 1 C-state residency: 95.66% (C3: 0.00% C6: 0.00% C7: 95.66% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 223.59/19.44] [< 32 us: 19.44/0.00] [< 64 us: 29.16/0.00] [< 128 us: 77.77/97.21] [< 256 us: 29.16/19.44] [< 512 us: 19.44/38.89] [< 1024 us: 9.72/58.33] [< 2048 us: 9.72/38.89] [< 4096 us: 0.00/38.89] [< 8192 us: 0.00/87.49] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.60% (1324.84 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 97.19/0.00] [< 32 us: 29.16/0.00] [< 64 us: 48.60/0.00] [< 128 us: 29.16/38.88] [< 256 us: 29.16/29.16] [< 512 us: 19.44/19.44] [< 1024 us: 9.72/9.72] [< 2048 us: 0.00/38.88] [< 4096 us: 0.00/38.88] [< 8192 us: 0.00/58.32] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.24% (1431.42 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 184.71/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.72/29.16] [< 128 us: 0.00/29.16] [< 256 us: 0.00/19.44] [< 512 us: 0.00/29.16] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/19.44] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/29.16] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 68.11% (1566.59 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 126.35/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/19.44] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 84.40% (1941.31 Mhz) -Core 2 C-state residency: 94.37% (C3: 0.00% C6: 0.00% C7: 94.37% ) +Core 2 C-state residency: 97.49% (C3: 0.00% C6: 0.00% C7: 97.49% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 223.59/38.89] [< 32 us: 29.16/0.00] [< 64 us: 29.16/48.61] [< 128 us: 38.89/48.61] [< 256 us: 9.72/29.16] [< 512 us: 29.16/19.44] [< 1024 us: 0.00/19.44] [< 2048 us: 9.72/38.89] [< 4096 us: 0.00/19.44] [< 8192 us: 0.00/68.05] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 116.24% (2673.46 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 116.63/9.72] [< 32 us: 19.44/0.00] [< 64 us: 29.16/0.00] [< 128 us: 38.88/9.72] [< 256 us: 19.44/9.72] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/29.16] [< 4096 us: 0.00/38.88] [< 8192 us: 0.00/58.32] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 59.75% (1374.27 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 126.38/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.72] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/38.89] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 79.71% (1833.29 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 145.79/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.44] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/38.88] [< 16384 us: 0.00/29.16] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 81.83% (1882.19 Mhz) -Core 3 C-state residency: 97.08% (C3: 0.00% C6: 0.00% C7: 97.08% ) +Core 3 C-state residency: 97.42% (C3: 0.00% C6: 0.00% C7: 97.42% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 184.71/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.44/9.72] [< 256 us: 9.72/29.16] [< 512 us: 19.44/58.33] [< 1024 us: 0.00/19.44] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/48.61] [< 16384 us: 0.00/48.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.16% (1337.72 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 136.07/9.72] [< 32 us: 0.00/0.00] [< 64 us: 9.72/9.72] [< 128 us: 29.16/9.72] [< 256 us: 0.00/19.44] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/0.00] [< 2048 us: 9.72/0.00] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/48.60] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 153.54% (3531.39 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 111.40% (2562.24 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 68.03/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 98.03% (2254.61 Mhz) -Core 4 C-state residency: 98.66% (C3: 0.00% C6: 0.00% C7: 98.66% ) +Core 4 C-state residency: 99.05% (C3: 0.00% C6: 0.00% C7: 99.05% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 97.21/9.72] [< 32 us: 0.00/0.00] [< 64 us: 29.16/0.00] [< 128 us: 0.00/29.16] [< 256 us: 9.72/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/19.44] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 60.93% (1401.46 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 68.03/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.72] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.72/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.68% (1441.60 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.72/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 71.84% (1652.34 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 58.32/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 94.54% (2174.40 Mhz) -Core 5 C-state residency: 97.49% (C3: 0.00% C6: 0.00% C7: 97.49% ) +Core 5 C-state residency: 98.64% (C3: 0.00% C6: 0.00% C7: 98.64% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 68.05/0.00] [< 32 us: 9.72/0.00] [< 64 us: 29.16/0.00] [< 128 us: 38.89/9.72] [< 256 us: 0.00/9.72] [< 512 us: 0.00/29.16] [< 1024 us: 9.72/9.72] [< 2048 us: 0.00/29.16] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/38.89] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 67.63% (1555.58 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 58.32/9.72] [< 32 us: 9.72/0.00] [< 64 us: 29.16/0.00] [< 128 us: 19.44/9.72] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/48.60] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 65.07% (1496.63 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 77.77/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.72/9.72] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 67.04% (1542.01 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 105.28% (2421.44 Mhz) -Core 6 C-state residency: 98.62% (C3: 0.00% C6: 0.00% C7: 98.62% ) +Core 6 C-state residency: 99.45% (C3: 0.00% C6: 0.00% C7: 99.45% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 87.49/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 29.16/48.61] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 59.40% (1366.23 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.72/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.94% (1654.55 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 106.93/0.00] [< 32 us: 0.00/9.72] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.44] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 87.63% (2015.59 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 106.63% (2452.44 Mhz) -Core 7 C-state residency: 98.90% (C3: 0.00% C6: 0.00% C7: 98.90% ) +Core 7 C-state residency: 99.53% (C3: 0.00% C6: 0.00% C7: 99.53% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 29.16/0.00] [< 32 us: 9.72/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.44/0.00] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 61.16% (1406.63 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 48.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 132.60% (3049.74 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 68.05/0.00] [< 32 us: 9.72/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 92.09% (2118.14 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 29.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 109.22% (2512.05 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.17ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.34ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.18W +Intel energy model derived package power (CPUs+GT+SA): 0.89W -LLC flushed residency: 81.1% +LLC flushed residency: 85.5% -System Average frequency as fraction of nominal: 69.36% (1595.28 Mhz) -Package 0 C-state residency: 82.06% (C2: 7.37% C3: 4.73% C6: 0.00% C7: 69.95% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 61.37% (1411.42 Mhz) +Package 0 C-state residency: 86.63% (C2: 8.78% C3: 3.60% C6: 0.25% C7: 74.01% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 15.86% +Cores Active: 10.96% GPU Active: 0.00% -Avg Num of Cores Active: 0.28 +Avg Num of Cores Active: 0.17 -Core 0 C-state residency: 86.75% (C3: 0.00% C6: 0.00% C7: 86.75% ) +Core 0 C-state residency: 89.97% (C3: 0.00% C6: 0.00% C7: 89.97% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 28.80/57.60] [< 32 us: 28.80/9.60] [< 64 us: 28.80/0.00] [< 128 us: 124.80/9.60] [< 256 us: 115.20/19.20] [< 512 us: 9.60/9.60] [< 1024 us: 19.20/9.60] [< 2048 us: 0.00/67.20] [< 4096 us: 19.20/105.60] [< 8192 us: 0.00/86.40] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 67.30% (1547.89 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 67.09/38.34] [< 32 us: 28.75/0.00] [< 64 us: 0.00/9.58] [< 128 us: 162.93/38.34] [< 256 us: 105.42/9.58] [< 512 us: 28.75/0.00] [< 1024 us: 0.00/38.34] [< 2048 us: 0.00/95.84] [< 4096 us: 9.58/86.26] [< 8192 us: 0.00/86.26] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.34% (1502.83 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 278.39/0.00] [< 32 us: 0.00/28.80] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.20] [< 256 us: 0.00/19.20] [< 512 us: 0.00/19.20] [< 1024 us: 0.00/28.80] [< 2048 us: 0.00/38.40] [< 4096 us: 0.00/48.00] [< 8192 us: 0.00/28.80] [< 16384 us: 0.00/38.40] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 61.32% (1410.39 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 220.43/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/67.09] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 58.79% (1352.11 Mhz) -Core 1 C-state residency: 95.13% (C3: 0.00% C6: 0.00% C7: 95.13% ) +Core 1 C-state residency: 94.37% (C3: 0.00% C6: 0.00% C7: 94.37% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 124.80/9.60] [< 32 us: 28.80/0.00] [< 64 us: 28.80/9.60] [< 128 us: 28.80/48.00] [< 256 us: 67.20/38.40] [< 512 us: 0.00/9.60] [< 1024 us: 19.20/19.20] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/38.40] [< 8192 us: 0.00/67.20] [< 16384 us: 0.00/38.40] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 69.09% (1589.03 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 105.42/19.17] [< 32 us: 0.00/0.00] [< 64 us: 38.34/0.00] [< 128 us: 57.50/38.34] [< 256 us: 47.92/28.75] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/19.17] [< 2048 us: 9.58/47.92] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/57.50] [< 16384 us: 0.00/38.34] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.73% (1304.71 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 211.19/0.00] [< 32 us: 0.00/19.20] [< 64 us: 0.00/28.80] [< 128 us: 0.00/19.20] [< 256 us: 0.00/9.60] [< 512 us: 0.00/28.80] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/28.80] [< 32768 us: 0.00/19.20] -CPU Average frequency as fraction of nominal: 63.82% (1467.92 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 143.76/0.00] [< 32 us: 0.00/9.58] [< 64 us: 0.00/9.58] [< 128 us: 9.58/28.75] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.75] +CPU Average frequency as fraction of nominal: 58.17% (1337.80 Mhz) -Core 2 C-state residency: 92.00% (C3: 0.00% C6: 0.00% C7: 92.00% ) +Core 2 C-state residency: 98.21% (C3: 0.00% C6: 0.00% C7: 98.21% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 143.99/19.20] [< 32 us: 9.60/0.00] [< 64 us: 19.20/9.60] [< 128 us: 57.60/48.00] [< 256 us: 19.20/38.40] [< 512 us: 28.80/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/19.20] [< 8192 us: 9.60/57.60] [< 16384 us: 0.00/48.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 77.40% (1780.22 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 115.01/19.17] [< 32 us: 9.58/0.00] [< 64 us: 38.34/0.00] [< 128 us: 19.17/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/47.92] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.08% (1312.79 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 124.80/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/9.60] [< 128 us: 0.00/9.60] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/28.80] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 65.82% (1513.92 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 86.26/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 60.93% (1401.29 Mhz) -Core 3 C-state residency: 97.36% (C3: 0.00% C6: 0.00% C7: 97.36% ) +Core 3 C-state residency: 98.40% (C3: 0.00% C6: 0.00% C7: 98.40% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 134.40/28.80] [< 32 us: 9.60/0.00] [< 64 us: 28.80/9.60] [< 128 us: 9.60/19.20] [< 256 us: 28.80/28.80] [< 512 us: 9.60/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/57.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 62.24% (1431.57 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 57.50/9.58] [< 32 us: 19.17/9.58] [< 64 us: 28.75/0.00] [< 128 us: 38.34/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.08% (1312.88 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 57.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 62.57% (1439.03 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.02% (1426.51 Mhz) -Core 4 C-state residency: 98.76% (C3: 0.00% C6: 0.00% C7: 98.76% ) +Core 4 C-state residency: 98.40% (C3: 0.00% C6: 0.00% C7: 98.40% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 96.00/0.00] [< 32 us: 9.60/0.00] [< 64 us: 9.60/9.60] [< 128 us: 19.20/28.80] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/38.40] -CPU Average frequency as fraction of nominal: 59.43% (1366.80 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 67.09/9.58] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.17/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 56.85% (1307.53 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 48.00/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.17% (1475.94 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 47.92/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 61.94% (1424.51 Mhz) -Core 5 C-state residency: 97.36% (C3: 0.00% C6: 0.00% C7: 97.36% ) +Core 5 C-state residency: 99.09% (C3: 0.00% C6: 0.00% C7: 99.09% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 28.80/0.00] [< 32 us: 9.60/0.00] [< 64 us: 9.60/0.00] [< 128 us: 19.20/9.60] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 9.60/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 66.35% (1525.98 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 38.34/0.00] [< 32 us: 9.58/0.00] [< 64 us: 9.58/0.00] [< 128 us: 19.17/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.72% (1327.48 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 57.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 62.31% (1433.12 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.34/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.56% (1461.91 Mhz) -Core 6 C-state residency: 98.89% (C3: 0.00% C6: 0.00% C7: 98.89% ) +Core 6 C-state residency: 99.20% (C3: 0.00% C6: 0.00% C7: 99.20% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 67.20/0.00] [< 32 us: 9.60/9.60] [< 64 us: 9.60/0.00] [< 128 us: 19.20/0.00] [< 256 us: 0.00/28.80] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 65.74% (1511.99 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.49% (1345.19 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 67.20/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 63.68% (1464.75 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.75% (1466.28 Mhz) -Core 7 C-state residency: 98.82% (C3: 0.00% C6: 0.00% C7: 98.82% ) +Core 7 C-state residency: 99.45% (C3: 0.00% C6: 0.00% C7: 99.45% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 57.60/9.60] [< 32 us: 19.20/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.60/0.00] [< 256 us: 9.60/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/19.20] [< 32768 us: 0.00/28.80] -CPU Average frequency as fraction of nominal: 57.93% (1332.39 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 59.59% (1370.63 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 48.00/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 62.22% (1430.98 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.37% (1480.53 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.37ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.34ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 9.65W +Intel energy model derived package power (CPUs+GT+SA): 1.15W -LLC flushed residency: 20.9% +LLC flushed residency: 77.9% -System Average frequency as fraction of nominal: 133.93% (3080.32 Mhz) -Package 0 C-state residency: 21.43% (C2: 2.66% C3: 0.29% C6: 4.91% C7: 13.58% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 66.51% (1529.80 Mhz) +Package 0 C-state residency: 78.76% (C2: 6.62% C3: 4.89% C6: 0.06% C7: 67.19% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 71.04% +Cores Active: 12.90% GPU Active: 0.00% -Avg Num of Cores Active: 0.97 +Avg Num of Cores Active: 0.19 -Core 0 C-state residency: 46.39% (C3: 1.42% C6: 0.00% C7: 44.97% ) +Core 0 C-state residency: 87.17% (C3: 0.00% C6: 0.00% C7: 87.17% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 536.56/392.84] [< 32 us: 105.40/86.23] [< 64 us: 86.23/172.47] [< 128 us: 105.40/162.89] [< 256 us: 124.56/47.91] [< 512 us: 76.65/19.16] [< 1024 us: 19.16/76.65] [< 2048 us: 9.58/86.23] [< 4096 us: 9.58/38.33] [< 8192 us: 19.16/19.16] [< 16384 us: 19.16/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 137.37% (3159.51 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 67.09/38.33] [< 32 us: 57.50/9.58] [< 64 us: 57.50/57.50] [< 128 us: 124.59/57.50] [< 256 us: 86.25/38.33] [< 512 us: 47.92/19.17] [< 1024 us: 9.58/28.75] [< 2048 us: 9.58/47.92] [< 4096 us: 9.58/95.84] [< 8192 us: 0.00/67.09] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.94% (1585.71 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 1082.71/249.12] [< 32 us: 38.33/134.14] [< 64 us: 38.33/105.40] [< 128 us: 9.58/239.54] [< 256 us: 0.00/134.14] [< 512 us: 0.00/67.07] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/76.65] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/57.49] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 134.66% (3097.24 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 297.10/9.58] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 0.00/38.33] [< 256 us: 0.00/38.33] [< 512 us: 0.00/28.75] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/76.67] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.78% (1443.96 Mhz) -Core 1 C-state residency: 75.42% (C3: 0.07% C6: 0.00% C7: 75.35% ) +Core 1 C-state residency: 91.19% (C3: 0.09% C6: 0.00% C7: 91.10% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 1983.37/258.70] [< 32 us: 172.47/948.57] [< 64 us: 76.65/498.24] [< 128 us: 114.98/220.37] [< 256 us: 38.33/95.81] [< 512 us: 47.91/95.81] [< 1024 us: 9.58/76.65] [< 2048 us: 0.00/143.72] [< 4096 us: 9.58/76.65] [< 8192 us: 9.58/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 120.91% (2781.00 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 201.26/57.50] [< 32 us: 95.84/0.00] [< 64 us: 47.92/19.17] [< 128 us: 28.75/124.59] [< 256 us: 0.00/19.17] [< 512 us: 19.17/0.00] [< 1024 us: 0.00/38.33] [< 2048 us: 9.58/28.75] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/47.92] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.17% (1475.99 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 1264.76/182.05] [< 32 us: 19.16/134.14] [< 64 us: 19.16/277.86] [< 128 us: 9.58/249.12] [< 256 us: 9.58/95.81] [< 512 us: 0.00/86.23] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/153.30] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 137.76% (3168.48 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 124.59/9.58] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 65.02% (1495.42 Mhz) -Core 2 C-state residency: 79.60% (C3: 0.88% C6: 0.00% C7: 78.72% ) +Core 2 C-state residency: 90.27% (C3: 0.08% C6: 0.00% C7: 90.19% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 804.85/191.63] [< 32 us: 95.81/105.40] [< 64 us: 105.40/124.56] [< 128 us: 76.65/210.79] [< 256 us: 28.74/143.72] [< 512 us: 57.49/105.40] [< 1024 us: 0.00/57.49] [< 2048 us: 0.00/86.23] [< 4096 us: 9.58/105.40] [< 8192 us: 9.58/38.33] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 131.87% (3032.98 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 268.34/9.58] [< 32 us: 47.92/9.58] [< 64 us: 28.75/38.33] [< 128 us: 47.92/105.42] [< 256 us: 9.58/47.92] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/47.92] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 64.12% (1474.86 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 910.24/153.30] [< 32 us: 19.16/95.81] [< 64 us: 0.00/105.40] [< 128 us: 19.16/182.05] [< 256 us: 0.00/95.81] [< 512 us: 0.00/38.33] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/67.07] [< 4096 us: 0.00/114.98] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 133.30% (3065.93 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 191.67/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/28.75] [< 256 us: 0.00/19.17] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.21% (1430.72 Mhz) -Core 3 C-state residency: 74.06% (C3: 0.04% C6: 0.00% C7: 74.02% ) +Core 3 C-state residency: 98.05% (C3: 0.00% C6: 0.00% C7: 98.05% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 804.85/229.96] [< 32 us: 76.65/277.86] [< 64 us: 124.56/172.47] [< 128 us: 57.49/124.56] [< 256 us: 86.23/67.07] [< 512 us: 28.74/47.91] [< 1024 us: 9.58/38.33] [< 2048 us: 9.58/105.40] [< 4096 us: 0.00/86.23] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 144.93% (3333.50 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 172.51/9.58] [< 32 us: 0.00/0.00] [< 64 us: 28.75/9.58] [< 128 us: 19.17/38.33] [< 256 us: 9.58/19.17] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 58.98% (1356.51 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 498.24/47.91] [< 32 us: 9.58/0.00] [< 64 us: 0.00/47.91] [< 128 us: 0.00/86.23] [< 256 us: 0.00/57.49] [< 512 us: 0.00/67.07] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/38.33] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/57.49] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.16] -CPU Average frequency as fraction of nominal: 120.95% (2781.92 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 62.56% (1438.87 Mhz) -Core 4 C-state residency: 95.11% (C3: 0.00% C6: 0.00% C7: 95.11% ) +Core 4 C-state residency: 99.37% (C3: 0.00% C6: 0.00% C7: 99.37% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 459.91/124.56] [< 32 us: 57.49/19.16] [< 64 us: 38.33/67.07] [< 128 us: 47.91/105.40] [< 256 us: 38.33/67.07] [< 512 us: 9.58/38.33] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/67.07] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 136.08% (3129.85 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 60.09% (1382.06 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 440.75/95.81] [< 32 us: 0.00/19.16] [< 64 us: 0.00/38.33] [< 128 us: 0.00/47.91] [< 256 us: 9.58/47.91] [< 512 us: 0.00/57.49] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 139.06% (3198.40 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 62.41% (1435.42 Mhz) -Core 5 C-state residency: 94.28% (C3: 0.00% C6: 0.00% C7: 94.28% ) +Core 5 C-state residency: 98.76% (C3: 0.00% C6: 0.00% C7: 98.76% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 335.35/105.40] [< 32 us: 19.16/9.58] [< 64 us: 57.49/47.91] [< 128 us: 19.16/76.65] [< 256 us: 19.16/28.74] [< 512 us: 28.74/19.16] [< 1024 us: 0.00/38.33] [< 2048 us: 9.58/57.49] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 143.62% (3303.35 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 57.50/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] +CPU Average frequency as fraction of nominal: 57.25% (1316.82 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 220.37/19.16] [< 32 us: 0.00/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/19.16] [< 256 us: 0.00/38.33] [< 512 us: 0.00/28.74] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.74] -CPU Average frequency as fraction of nominal: 93.60% (2152.91 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.90% (1446.76 Mhz) -Core 6 C-state residency: 95.80% (C3: 0.00% C6: 0.00% C7: 95.80% ) +Core 6 C-state residency: 99.58% (C3: 0.00% C6: 0.00% C7: 99.58% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 239.54/105.40] [< 32 us: 38.33/0.00] [< 64 us: 9.58/9.58] [< 128 us: 47.91/57.49] [< 256 us: 19.16/38.33] [< 512 us: 9.58/19.16] [< 1024 us: 19.16/28.74] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.16] -CPU Average frequency as fraction of nominal: 115.08% (2646.90 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 19.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.45% (1459.42 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 383.26/114.98] [< 32 us: 9.58/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/67.07] [< 256 us: 0.00/47.91] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.74] -CPU Average frequency as fraction of nominal: 109.28% (2513.54 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.88% (1446.33 Mhz) -Core 7 C-state residency: 96.83% (C3: 0.00% C6: 0.00% C7: 96.83% ) +Core 7 C-state residency: 99.58% (C3: 0.00% C6: 0.00% C7: 99.58% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 210.79/86.23] [< 32 us: 9.58/0.00] [< 64 us: 19.16/28.74] [< 128 us: 28.74/47.91] [< 256 us: 47.91/9.58] [< 512 us: 9.58/19.16] [< 1024 us: 0.00/28.74] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 131.31% (3020.23 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 19.17/0.00] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.51% (1483.83 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 249.12/9.58] [< 32 us: 0.00/28.74] [< 64 us: 0.00/38.33] [< 128 us: 0.00/47.91] [< 256 us: 0.00/38.33] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 91.27% (2099.14 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.06% (1473.40 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.46ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.73ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.31W +Intel energy model derived package power (CPUs+GT+SA): 9.42W -LLC flushed residency: 77.6% +LLC flushed residency: 27.2% -System Average frequency as fraction of nominal: 73.78% (1697.04 Mhz) -Package 0 C-state residency: 78.86% (C2: 9.83% C3: 4.09% C6: 1.98% C7: 62.95% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 132.91% (3056.95 Mhz) +Package 0 C-state residency: 27.77% (C2: 3.18% C3: 1.65% C6: 0.00% C7: 22.95% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 18.32% +Cores Active: 70.87% GPU Active: 0.00% -Avg Num of Cores Active: 0.28 +Avg Num of Cores Active: 1.02 -Core 0 C-state residency: 85.10% (C3: 0.00% C6: 0.00% C7: 85.10% ) +Core 0 C-state residency: 61.81% (C3: 0.00% C6: 0.00% C7: 61.81% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 124.45/9.57] [< 32 us: 38.29/38.29] [< 64 us: 28.72/86.16] [< 128 us: 181.89/19.15] [< 256 us: 124.45/28.72] [< 512 us: 67.01/76.59] [< 1024 us: 9.57/76.59] [< 2048 us: 9.57/114.88] [< 4096 us: 9.57/67.01] [< 8192 us: 0.00/76.59] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 71.56% (1645.92 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 472.39/318.14] [< 32 us: 125.33/86.76] [< 64 us: 144.61/163.89] [< 128 us: 96.41/154.25] [< 256 us: 86.76/57.84] [< 512 us: 48.20/48.20] [< 1024 us: 38.56/28.92] [< 2048 us: 0.00/96.41] [< 4096 us: 28.92/67.48] [< 8192 us: 9.64/38.56] [< 16384 us: 9.64/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 139.37% (3205.51 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 382.93/0.00] [< 32 us: 0.00/9.57] [< 64 us: 0.00/38.29] [< 128 us: 0.00/19.15] [< 256 us: 0.00/38.29] [< 512 us: 0.00/57.44] [< 1024 us: 0.00/57.44] [< 2048 us: 0.00/47.87] [< 4096 us: 0.00/47.87] [< 8192 us: 0.00/38.29] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 67.82% (1559.93 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 992.97/221.73] [< 32 us: 38.56/96.41] [< 64 us: 19.28/115.69] [< 128 us: 9.64/163.89] [< 256 us: 9.64/115.69] [< 512 us: 0.00/86.76] [< 1024 us: 0.00/57.84] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 137.49% (3162.26 Mhz) -Core 1 C-state residency: 90.91% (C3: 0.00% C6: 0.00% C7: 90.91% ) +Core 1 C-state residency: 74.15% (C3: 3.45% C6: 0.00% C7: 70.69% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 201.04/47.87] [< 32 us: 28.72/9.57] [< 64 us: 57.44/38.29] [< 128 us: 95.73/28.72] [< 256 us: 38.29/57.44] [< 512 us: 19.15/38.29] [< 1024 us: 0.00/76.59] [< 2048 us: 0.00/28.72] [< 4096 us: 0.00/38.29] [< 8192 us: 9.57/76.59] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 78.79% (1812.17 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 780.88/250.65] [< 32 us: 192.81/57.84] [< 64 us: 96.41/289.22] [< 128 us: 96.41/221.73] [< 256 us: 19.28/115.69] [< 512 us: 96.41/57.84] [< 1024 us: 9.64/86.76] [< 2048 us: 0.00/144.61] [< 4096 us: 0.00/48.20] [< 8192 us: 19.28/28.92] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 118.96% (2736.14 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 172.32/0.00] [< 32 us: 9.57/9.57] [< 64 us: 0.00/19.15] [< 128 us: 0.00/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/28.72] [< 1024 us: 0.00/38.29] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 70.63% (1624.55 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 838.73/106.05] [< 32 us: 38.56/48.20] [< 64 us: 9.64/163.89] [< 128 us: 9.64/125.33] [< 256 us: 9.64/86.76] [< 512 us: 0.00/96.41] [< 1024 us: 0.00/57.84] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/57.84] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 133.19% (3063.39 Mhz) -Core 2 C-state residency: 94.64% (C3: 0.00% C6: 0.00% C7: 94.64% ) +Core 2 C-state residency: 69.96% (C3: 1.29% C6: 0.00% C7: 68.66% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 277.62/9.57] [< 32 us: 28.72/0.00] [< 64 us: 28.72/28.72] [< 128 us: 19.15/86.16] [< 256 us: 19.15/38.29] [< 512 us: 38.29/28.72] [< 1024 us: 9.57/67.01] [< 2048 us: 0.00/67.01] [< 4096 us: 0.00/28.72] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/38.29] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 67.88% (1561.19 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 1513.56/279.58] [< 32 us: 144.61/877.29] [< 64 us: 134.97/183.17] [< 128 us: 77.12/250.65] [< 256 us: 57.84/163.89] [< 512 us: 77.12/57.84] [< 1024 us: 9.64/86.76] [< 2048 us: 9.64/77.12] [< 4096 us: 0.00/28.92] [< 8192 us: 28.92/38.56] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 137.98% (3173.49 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 153.17/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/9.57] [< 128 us: 0.00/9.57] [< 256 us: 0.00/28.72] [< 512 us: 0.00/9.57] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/28.72] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.72] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.24% (1569.56 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 1041.18/144.61] [< 32 us: 9.64/86.76] [< 64 us: 0.00/134.97] [< 128 us: 9.64/144.61] [< 256 us: 0.00/173.53] [< 512 us: 0.00/106.05] [< 1024 us: 0.00/67.48] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/38.56] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 132.09% (3037.98 Mhz) -Core 3 C-state residency: 97.42% (C3: 0.00% C6: 0.00% C7: 97.42% ) +Core 3 C-state residency: 84.48% (C3: 0.04% C6: 0.00% C7: 84.44% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 172.32/0.00] [< 32 us: 47.87/0.00] [< 64 us: 19.15/0.00] [< 128 us: 9.57/19.15] [< 256 us: 9.57/28.72] [< 512 us: 9.57/47.87] [< 1024 us: 0.00/57.44] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/28.72] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/28.72] -CPU Average frequency as fraction of nominal: 66.89% (1538.56 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 665.20/173.53] [< 32 us: 77.12/9.64] [< 64 us: 38.56/144.61] [< 128 us: 96.41/279.58] [< 256 us: 57.84/96.41] [< 512 us: 38.56/48.20] [< 1024 us: 9.64/77.12] [< 2048 us: 28.92/67.48] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 130.58% (3003.32 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.57] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 72.30% (1662.83 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 337.42/38.56] [< 32 us: 28.92/0.00] [< 64 us: 9.64/28.92] [< 128 us: 0.00/77.12] [< 256 us: 0.00/57.84] [< 512 us: 0.00/48.20] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 130.10% (2992.36 Mhz) -Core 4 C-state residency: 98.98% (C3: 0.00% C6: 0.00% C7: 98.98% ) +Core 4 C-state residency: 93.84% (C3: 2.03% C6: 0.00% C7: 91.81% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 74.35% (1710.04 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 645.91/163.89] [< 32 us: 86.76/86.76] [< 64 us: 0.00/77.12] [< 128 us: 28.92/183.17] [< 256 us: 28.92/28.92] [< 512 us: 28.92/57.84] [< 1024 us: 9.64/38.56] [< 2048 us: 0.00/77.12] [< 4096 us: 0.00/38.56] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 132.71% (3052.28 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 67.01/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.15] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 73.26% (1684.87 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 462.74/86.76] [< 32 us: 0.00/48.20] [< 64 us: 0.00/19.28] [< 128 us: 0.00/77.12] [< 256 us: 0.00/48.20] [< 512 us: 0.00/48.20] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/19.28] +CPU Average frequency as fraction of nominal: 116.52% (2680.06 Mhz) -Core 5 C-state residency: 97.18% (C3: 0.00% C6: 0.00% C7: 97.18% ) +Core 5 C-state residency: 96.10% (C3: 0.00% C6: 0.00% C7: 96.10% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 67.01/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/19.15] [< 128 us: 9.57/0.00] [< 256 us: 0.00/9.57] [< 512 us: 9.57/0.00] [< 1024 us: 0.00/28.72] [< 2048 us: 9.57/9.57] [< 4096 us: 0.00/9.57] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.72] -CPU Average frequency as fraction of nominal: 83.47% (1919.78 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 337.42/38.56] [< 32 us: 0.00/9.64] [< 64 us: 38.56/57.84] [< 128 us: 48.20/106.05] [< 256 us: 28.92/38.56] [< 512 us: 9.64/19.28] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 136.30% (3134.86 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 66.85% (1537.45 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 183.17/28.92] [< 32 us: 9.64/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/28.92] [< 256 us: 0.00/19.28] [< 512 us: 0.00/19.28] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 114.91% (2642.86 Mhz) -Core 6 C-state residency: 99.22% (C3: 0.00% C6: 0.00% C7: 99.22% ) +Core 6 C-state residency: 96.58% (C3: 0.00% C6: 0.00% C7: 96.58% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 57.44/0.00] [< 32 us: 19.15/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 73.97% (1701.28 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 260.29/77.12] [< 32 us: 48.20/19.28] [< 64 us: 9.64/19.28] [< 128 us: 19.28/96.41] [< 256 us: 28.92/9.64] [< 512 us: 19.28/0.00] [< 1024 us: 0.00/38.56] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 137.87% (3171.12 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 69.94% (1608.53 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 347.06/96.41] [< 32 us: 9.64/57.84] [< 64 us: 0.00/19.28] [< 128 us: 0.00/28.92] [< 256 us: 9.64/57.84] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 138.77% (3191.70 Mhz) -Core 7 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) +Core 7 C-state residency: 95.69% (C3: 0.00% C6: 0.00% C7: 95.69% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 64.77% (1489.79 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 260.29/77.12] [< 32 us: 38.56/9.64] [< 64 us: 0.00/57.84] [< 128 us: 48.20/67.48] [< 256 us: 38.56/19.28] [< 512 us: 0.00/19.28] [< 1024 us: 0.00/48.20] [< 2048 us: 9.64/9.64] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/19.28] +CPU Average frequency as fraction of nominal: 115.43% (2654.97 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 28.72/0.00] [< 32 us: 9.57/9.57] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 67.61% (1555.01 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 221.73/48.20] [< 32 us: 9.64/9.64] [< 64 us: 0.00/38.56] [< 128 us: 19.28/28.92] [< 256 us: 9.64/38.56] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.92] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 139.61% (3211.14 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (103.88ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.52ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 2.51W +Intel energy model derived package power (CPUs+GT+SA): 0.78W -LLC flushed residency: 67.5% +LLC flushed residency: 88% -System Average frequency as fraction of nominal: 97.92% (2252.27 Mhz) -Package 0 C-state residency: 68.50% (C2: 7.24% C3: 3.45% C6: 0.00% C7: 57.81% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 62.96% (1448.10 Mhz) +Package 0 C-state residency: 88.85% (C2: 7.70% C3: 4.74% C6: 0.00% C7: 76.42% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 29.41% +Cores Active: 9.01% GPU Active: 0.00% -Avg Num of Cores Active: 0.40 +Avg Num of Cores Active: 0.13 -Core 0 C-state residency: 73.20% (C3: 0.08% C6: 0.00% C7: 73.12% ) +Core 0 C-state residency: 92.40% (C3: 0.00% C6: 0.00% C7: 92.40% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 413.95/77.01] [< 32 us: 19.25/38.51] [< 64 us: 38.51/115.52] [< 128 us: 163.65/182.91] [< 256 us: 48.13/48.13] [< 512 us: 38.51/28.88] [< 1024 us: 48.13/28.88] [< 2048 us: 0.00/134.77] [< 4096 us: 9.63/77.01] [< 8192 us: 9.63/48.13] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 88.68% (2039.57 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 47.84/19.14] [< 32 us: 9.57/0.00] [< 64 us: 47.84/28.70] [< 128 us: 105.25/19.14] [< 256 us: 105.25/19.14] [< 512 us: 19.14/9.57] [< 1024 us: 19.14/0.00] [< 2048 us: 0.00/57.41] [< 4096 us: 0.00/124.38] [< 8192 us: 0.00/66.98] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.07% (1312.59 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 490.96/9.63] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.51] [< 128 us: 0.00/96.27] [< 256 us: 0.00/96.27] [< 512 us: 0.00/28.88] [< 1024 us: 0.00/96.27] [< 2048 us: 0.00/48.13] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 83.30% (1915.92 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 239.20/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.70] [< 128 us: 0.00/38.27] [< 256 us: 0.00/28.70] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/19.14] [< 4096 us: 0.00/19.14] [< 8192 us: 0.00/28.70] [< 16384 us: 0.00/66.98] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 59.21% (1361.88 Mhz) -Core 1 C-state residency: 83.97% (C3: 0.10% C6: 0.00% C7: 83.87% ) +Core 1 C-state residency: 94.38% (C3: 0.00% C6: 0.00% C7: 94.38% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 433.20/154.03] [< 32 us: 38.51/19.25] [< 64 us: 67.39/125.15] [< 128 us: 96.27/96.27] [< 256 us: 48.13/96.27] [< 512 us: 19.25/48.13] [< 1024 us: 19.25/48.13] [< 2048 us: 19.25/38.51] [< 4096 us: 0.00/19.25] [< 8192 us: 0.00/67.39] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 95.83% (2204.10 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 86.11/19.14] [< 32 us: 9.57/9.57] [< 64 us: 28.70/19.14] [< 128 us: 47.84/9.57] [< 256 us: 28.70/9.57] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.57] [< 4096 us: 9.57/28.70] [< 8192 us: 0.00/38.27] [< 16384 us: 0.00/57.41] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 72.24% (1661.54 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 452.46/57.76] [< 32 us: 0.00/48.13] [< 64 us: 0.00/96.27] [< 128 us: 0.00/38.51] [< 256 us: 0.00/19.25] [< 512 us: 0.00/19.25] [< 1024 us: 0.00/67.39] [< 2048 us: 0.00/28.88] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/28.88] [< 16384 us: 0.00/28.88] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 86.71% (1994.26 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 162.66/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.70] [< 128 us: 0.00/19.14] [< 256 us: 0.00/19.14] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.14] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/28.70] +CPU Average frequency as fraction of nominal: 59.63% (1371.50 Mhz) -Core 2 C-state residency: 89.49% (C3: 0.01% C6: 0.00% C7: 89.48% ) +Core 2 C-state residency: 98.45% (C3: 0.00% C6: 0.00% C7: 98.45% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 385.07/77.01] [< 32 us: 38.51/38.51] [< 64 us: 38.51/77.01] [< 128 us: 38.51/77.01] [< 256 us: 19.25/77.01] [< 512 us: 19.25/57.76] [< 1024 us: 0.00/57.76] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 92.98% (2138.57 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 114.82/0.00] [< 32 us: 19.14/0.00] [< 64 us: 0.00/19.14] [< 128 us: 28.70/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/19.14] [< 8192 us: 0.00/38.27] [< 16384 us: 0.00/57.41] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.20% (1315.61 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 336.94/77.01] [< 32 us: 0.00/28.88] [< 64 us: 0.00/19.25] [< 128 us: 0.00/48.13] [< 256 us: 0.00/19.25] [< 512 us: 0.00/38.51] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.25] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 88.82% (2042.88 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 86.11/9.57] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.57] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.27] +CPU Average frequency as fraction of nominal: 60.84% (1399.33 Mhz) -Core 3 C-state residency: 89.00% (C3: 0.00% C6: 0.00% C7: 89.00% ) +Core 3 C-state residency: 98.78% (C3: 0.00% C6: 0.00% C7: 98.78% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 202.16/9.63] [< 32 us: 19.25/0.00] [< 64 us: 0.00/38.51] [< 128 us: 57.76/28.88] [< 256 us: 0.00/67.39] [< 512 us: 9.63/48.13] [< 1024 us: 28.88/48.13] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/19.25] [< 8192 us: 9.63/19.25] [< 16384 us: 0.00/28.88] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 118.16% (2717.78 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 86.11/0.00] [< 32 us: 9.57/0.00] [< 64 us: 9.57/9.57] [< 128 us: 19.14/9.57] [< 256 us: 0.00/9.57] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/38.27] [< 32768 us: 0.00/19.14] +CPU Average frequency as fraction of nominal: 57.44% (1321.14 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 48.13/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/28.88] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.67% (1487.44 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.24% (1454.43 Mhz) -Core 4 C-state residency: 98.73% (C3: 0.00% C6: 0.00% C7: 98.73% ) +Core 4 C-state residency: 98.93% (C3: 0.00% C6: 0.00% C7: 98.93% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 86.64/0.00] [< 32 us: 9.63/0.00] [< 64 us: 9.63/28.88] [< 128 us: 28.88/9.63] [< 256 us: 0.00/9.63] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 104.21% (2396.89 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 19.14/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.14/0.00] [< 256 us: 9.57/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/28.70] +CPU Average frequency as fraction of nominal: 57.82% (1329.75 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.25] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 79.83% (1836.00 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 38.27/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 66.17% (1521.88 Mhz) -Core 5 C-state residency: 99.29% (C3: 0.00% C6: 0.00% C7: 99.29% ) +Core 5 C-state residency: 99.10% (C3: 0.00% C6: 0.00% C7: 99.10% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.63] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 82.60% (1899.75 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 47.84/9.57] [< 32 us: 9.57/0.00] [< 64 us: 9.57/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 58.76% (1351.43 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 70.45% (1620.37 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.27/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 65.69% (1510.92 Mhz) -Core 6 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) +Core 6 C-state residency: 98.92% (C3: 0.00% C6: 0.00% C7: 98.92% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.87% (1584.08 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 47.84/0.00] [< 32 us: 38.27/0.00] [< 64 us: 9.57/19.14] [< 128 us: 0.00/0.00] [< 256 us: 9.57/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.14] +CPU Average frequency as fraction of nominal: 58.23% (1339.36 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 71.83% (1652.19 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 28.70/9.57] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.61% (1554.95 Mhz) -Core 7 C-state residency: 99.46% (C3: 0.00% C6: 0.00% C7: 99.46% ) +Core 7 C-state residency: 99.13% (C3: 0.00% C6: 0.00% C7: 99.13% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.18% (1568.13 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 47.84/0.00] [< 32 us: 9.57/0.00] [< 64 us: 9.57/0.00] [< 128 us: 9.57/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.27] +CPU Average frequency as fraction of nominal: 58.65% (1348.89 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/9.63] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 70.06% (1611.29 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] +CPU Average frequency as fraction of nominal: 66.18% (1522.12 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.09ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.43ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 4.84W +Intel energy model derived package power (CPUs+GT+SA): 0.81W -LLC flushed residency: 40.4% +LLC flushed residency: 87.6% -System Average frequency as fraction of nominal: 98.03% (2254.73 Mhz) -Package 0 C-state residency: 41.40% (C2: 5.26% C3: 2.47% C6: 1.63% C7: 32.04% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 65.32% (1502.43 Mhz) +Package 0 C-state residency: 88.38% (C2: 6.69% C3: 4.64% C6: 0.00% C7: 77.06% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 56.77% +Cores Active: 9.71% GPU Active: 0.00% -Avg Num of Cores Active: 0.73 +Avg Num of Cores Active: 0.14 -Core 0 C-state residency: 77.11% (C3: 0.00% C6: 0.00% C7: 77.11% ) +Core 0 C-state residency: 90.71% (C3: 0.00% C6: 0.00% C7: 90.71% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 115.29/9.61] [< 32 us: 48.04/9.61] [< 64 us: 28.82/38.43] [< 128 us: 124.90/38.43] [< 256 us: 86.47/19.21] [< 512 us: 28.82/105.68] [< 1024 us: 9.61/67.25] [< 2048 us: 28.82/86.47] [< 4096 us: 9.61/67.25] [< 8192 us: 9.61/38.43] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 69.77% (1604.72 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 47.88/9.58] [< 32 us: 19.15/9.58] [< 64 us: 9.58/9.58] [< 128 us: 124.49/19.15] [< 256 us: 86.18/9.58] [< 512 us: 19.15/19.15] [< 1024 us: 9.58/19.15] [< 2048 us: 0.00/57.45] [< 4096 us: 9.58/76.61] [< 8192 us: 0.00/86.18] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 66.37% (1526.42 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 441.94/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/28.82] [< 128 us: 0.00/38.43] [< 256 us: 0.00/28.82] [< 512 us: 0.00/38.43] [< 1024 us: 0.00/105.68] [< 2048 us: 0.00/76.86] [< 4096 us: 0.00/57.64] [< 8192 us: 0.00/28.82] [< 16384 us: 0.00/28.82] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 78.33% (1801.51 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 181.94/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.15] [< 1024 us: 0.00/38.30] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/38.30] [< 8192 us: 0.00/28.73] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.73] +CPU Average frequency as fraction of nominal: 60.38% (1388.85 Mhz) -Core 1 C-state residency: 56.98% (C3: 0.01% C6: 0.00% C7: 56.97% ) +Core 1 C-state residency: 96.19% (C3: 0.00% C6: 0.00% C7: 96.19% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 355.48/57.64] [< 32 us: 19.21/9.61] [< 64 us: 57.64/96.07] [< 128 us: 48.04/105.68] [< 256 us: 48.04/57.64] [< 512 us: 9.61/57.64] [< 1024 us: 9.61/124.90] [< 2048 us: 38.43/38.43] [< 4096 us: 9.61/28.82] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/28.82] [< 32768 us: 9.61/0.00] -CPU Average frequency as fraction of nominal: 118.92% (2735.18 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 76.61/38.30] [< 32 us: 9.58/0.00] [< 64 us: 47.88/19.15] [< 128 us: 47.88/9.58] [< 256 us: 47.88/9.58] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/38.30] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/57.45] [< 8192 us: 0.00/28.73] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 65.71% (1511.44 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 374.69/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/48.04] [< 128 us: 0.00/76.86] [< 256 us: 0.00/28.82] [< 512 us: 0.00/48.04] [< 1024 us: 0.00/57.64] [< 2048 us: 0.00/48.04] [< 4096 us: 0.00/19.21] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/19.21] [< 32768 us: 0.00/19.21] -CPU Average frequency as fraction of nominal: 71.96% (1655.15 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 191.52/0.00] [< 32 us: 0.00/9.58] [< 64 us: 9.58/28.73] [< 128 us: 0.00/19.15] [< 256 us: 0.00/28.73] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/38.30] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 64.57% (1485.16 Mhz) -Core 2 C-state residency: 86.83% (C3: 0.04% C6: 0.00% C7: 86.79% ) +Core 2 C-state residency: 98.29% (C3: 0.00% C6: 0.00% C7: 98.29% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 365.08/38.43] [< 32 us: 57.64/9.61] [< 64 us: 76.86/96.07] [< 128 us: 57.64/105.68] [< 256 us: 0.00/86.47] [< 512 us: 0.00/28.82] [< 1024 us: 9.61/48.04] [< 2048 us: 9.61/38.43] [< 4096 us: 0.00/38.43] [< 8192 us: 0.00/38.43] [< 16384 us: 0.00/38.43] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 77.23% (1776.34 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 124.49/19.15] [< 32 us: 19.15/0.00] [< 64 us: 47.88/9.58] [< 128 us: 19.15/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/28.73] [< 2048 us: 0.00/38.30] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.73] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 60.36% (1388.24 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 384.30/19.21] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.21] [< 128 us: 0.00/48.04] [< 256 us: 0.00/48.04] [< 512 us: 0.00/76.86] [< 1024 us: 0.00/48.04] [< 2048 us: 0.00/38.43] [< 4096 us: 0.00/38.43] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/38.43] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 71.01% (1633.22 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 114.91/9.58] [< 32 us: 0.00/0.00] [< 64 us: 9.58/9.58] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/28.73] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/28.73] +CPU Average frequency as fraction of nominal: 64.85% (1491.45 Mhz) -Core 3 C-state residency: 93.67% (C3: 0.00% C6: 0.00% C7: 93.67% ) +Core 3 C-state residency: 98.74% (C3: 0.00% C6: 0.00% C7: 98.74% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 230.58/28.82] [< 32 us: 19.21/0.00] [< 64 us: 57.64/28.82] [< 128 us: 19.21/86.47] [< 256 us: 28.82/0.00] [< 512 us: 0.00/38.43] [< 1024 us: 28.82/48.04] [< 2048 us: 9.61/48.04] [< 4096 us: 0.00/28.82] [< 8192 us: 0.00/38.43] [< 16384 us: 0.00/28.82] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 74.03% (1702.80 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 57.45/0.00] [< 32 us: 9.58/0.00] [< 64 us: 28.73/0.00] [< 128 us: 9.58/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.73] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 66.84% (1537.31 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 76.86/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.61] [< 256 us: 0.00/9.61] [< 512 us: 0.00/28.82] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 65.13% (1498.00 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.87% (1514.95 Mhz) -Core 4 C-state residency: 97.79% (C3: 0.00% C6: 0.00% C7: 97.79% ) +Core 4 C-state residency: 99.42% (C3: 0.00% C6: 0.00% C7: 99.42% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 182.54/0.00] [< 32 us: 9.61/0.00] [< 64 us: 19.21/19.21] [< 128 us: 9.61/38.43] [< 256 us: 9.61/57.64] [< 512 us: 9.61/0.00] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/28.82] [< 4096 us: 0.00/19.21] [< 8192 us: 0.00/19.21] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 75.13% (1727.94 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 38.30/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 66.92% (1539.18 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 124.90/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/9.61] [< 128 us: 0.00/19.21] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 65.36% (1503.23 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 38.30/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 73.36% (1687.35 Mhz) -Core 5 C-state residency: 98.63% (C3: 0.00% C6: 0.00% C7: 98.63% ) +Core 5 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 144.11/48.04] [< 32 us: 38.43/0.00] [< 64 us: 0.00/9.61] [< 128 us: 9.61/48.04] [< 256 us: 9.61/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.21] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/19.21] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 69.64% (1601.70 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 28.73/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 61.10% (1405.34 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 48.04/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.17% (1429.92 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 69.53% (1599.21 Mhz) -Core 6 C-state residency: 99.19% (C3: 0.00% C6: 0.00% C7: 99.19% ) +Core 6 C-state residency: 98.64% (C3: 0.00% C6: 0.00% C7: 98.64% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 19.21/0.00] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 28.82/0.00] [< 256 us: 0.00/9.61] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.82% (1352.89 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 57.45/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.70% (1327.13 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 57.64/0.00] [< 32 us: 9.61/9.61] [< 64 us: 0.00/19.21] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.89% (1469.58 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 70.28% (1616.49 Mhz) -Core 7 C-state residency: 99.25% (C3: 0.00% C6: 0.00% C7: 99.25% ) +Core 7 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 38.43/0.00] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 9.61/0.00] [< 256 us: 0.00/9.61] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 60.16% (1383.65 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 63.02% (1449.54 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 48.04/0.00] [< 32 us: 9.61/9.61] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.61] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.49% (1483.26 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] +CPU Average frequency as fraction of nominal: 69.39% (1595.86 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.36ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.67ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.48W +Intel energy model derived package power (CPUs+GT+SA): 0.94W -LLC flushed residency: 64.1% +LLC flushed residency: 84% -System Average frequency as fraction of nominal: 60.01% (1380.21 Mhz) -Package 0 C-state residency: 65.09% (C2: 6.04% C3: 4.55% C6: 0.00% C7: 54.50% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 64.63% (1486.47 Mhz) +Package 0 C-state residency: 84.83% (C2: 7.14% C3: 6.21% C6: 0.00% C7: 71.47% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 33.30% +Cores Active: 12.90% GPU Active: 0.00% -Avg Num of Cores Active: 0.41 +Avg Num of Cores Active: 0.21 -Core 0 C-state residency: 86.19% (C3: 0.00% C6: 0.00% C7: 86.19% ) +Core 0 C-state residency: 89.13% (C3: 0.00% C6: 0.00% C7: 89.13% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 38.33/28.75] [< 32 us: 0.00/0.00] [< 64 us: 9.58/9.58] [< 128 us: 124.57/28.75] [< 256 us: 95.83/0.00] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/0.00] [< 2048 us: 0.00/67.08] [< 4096 us: 0.00/86.24] [< 8192 us: 0.00/57.50] [< 16384 us: 9.58/19.17] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.14% (1429.23 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 96.46/48.23] [< 32 us: 28.94/9.65] [< 64 us: 19.29/28.94] [< 128 us: 154.34/67.52] [< 256 us: 125.40/28.94] [< 512 us: 0.00/19.29] [< 1024 us: 9.65/9.65] [< 2048 us: 0.00/48.23] [< 4096 us: 9.65/106.11] [< 8192 us: 0.00/67.52] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.72% (1557.54 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 210.82/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/28.75] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 58.90% (1354.75 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 299.03/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/19.29] [< 128 us: 0.00/38.58] [< 256 us: 0.00/48.23] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/48.23] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 59.64% (1371.76 Mhz) -Core 1 C-state residency: 94.87% (C3: 0.00% C6: 0.00% C7: 94.87% ) +Core 1 C-state residency: 96.25% (C3: 0.00% C6: 0.00% C7: 96.25% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 76.66/28.75] [< 32 us: 9.58/0.00] [< 64 us: 57.50/9.58] [< 128 us: 28.75/9.58] [< 256 us: 19.17/0.00] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.58] [< 4096 us: 9.58/28.75] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 72.80% (1674.47 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 135.04/19.29] [< 32 us: 9.65/0.00] [< 64 us: 19.29/19.29] [< 128 us: 86.81/38.58] [< 256 us: 28.94/28.94] [< 512 us: 19.29/28.94] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/57.88] [< 16384 us: 0.00/48.23] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.43% (1320.99 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 86.24/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 58.55% (1346.76 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 192.92/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/48.23] [< 256 us: 0.00/19.29] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 62.14% (1429.31 Mhz) -Core 2 C-state residency: 98.20% (C3: 0.00% C6: 0.00% C7: 98.20% ) +Core 2 C-state residency: 94.99% (C3: 0.00% C6: 0.00% C7: 94.99% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 86.24/19.17] [< 32 us: 19.17/0.00] [< 64 us: 47.91/19.17] [< 128 us: 28.75/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 56.94% (1309.72 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 96.46/38.58] [< 32 us: 9.65/0.00] [< 64 us: 28.94/9.65] [< 128 us: 19.29/0.00] [< 256 us: 48.23/0.00] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/19.29] [< 4096 us: 9.65/9.65] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 69.52% (1599.00 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 86.24/0.00] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 58.51% (1345.73 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 154.34/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/19.29] [< 256 us: 0.00/9.65] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 62.58% (1439.40 Mhz) -Core 3 C-state residency: 97.94% (C3: 0.00% C6: 0.00% C7: 97.94% ) +Core 3 C-state residency: 98.06% (C3: 0.00% C6: 0.00% C7: 98.06% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 86.24/47.91] [< 32 us: 28.75/0.00] [< 64 us: 19.17/0.00] [< 128 us: 28.75/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 56.82% (1306.77 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 28.94/0.00] [< 128 us: 9.65/19.29] [< 256 us: 9.65/0.00] [< 512 us: 9.65/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/28.94] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 57.51% (1322.64 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 47.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 58.29% (1340.59 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 57.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.65] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 71.88% (1653.24 Mhz) -Core 4 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) +Core 4 C-state residency: 96.90% (C3: 0.00% C6: 0.00% C7: 96.90% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 38.33/9.58] [< 32 us: 9.58/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/28.75] -CPU Average frequency as fraction of nominal: 58.15% (1337.47 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 67.52/19.29] [< 32 us: 9.65/0.00] [< 64 us: 9.65/9.65] [< 128 us: 19.29/0.00] [< 256 us: 19.29/9.65] [< 512 us: 9.65/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 9.65/9.65] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 57.82% (1329.83 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 67.08/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.17] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 60.99% (1402.71 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 125.40/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 67.87% (1560.98 Mhz) -Core 5 C-state residency: 99.02% (C3: 0.00% C6: 0.00% C7: 99.02% ) +Core 5 C-state residency: 98.59% (C3: 0.00% C6: 0.00% C7: 98.59% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 57.29% (1317.62 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 67.52/9.65] [< 32 us: 0.00/0.00] [< 64 us: 19.29/0.00] [< 128 us: 28.94/19.29] [< 256 us: 9.65/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.58] +CPU Average frequency as fraction of nominal: 57.98% (1333.61 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 61.39% (1412.03 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 73.64% (1693.70 Mhz) -Core 6 C-state residency: 79.36% (C3: 0.00% C6: 0.00% C7: 79.36% ) +Core 6 C-state residency: 98.78% (C3: 0.00% C6: 0.00% C7: 98.78% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 9.58/9.58] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 56.54% (1300.40 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.29/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.65/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 58.04% (1334.83 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.53% (1461.23 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 67.52/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.66% (1648.25 Mhz) -Core 7 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) +Core 7 C-state residency: 99.15% (C3: 0.00% C6: 0.00% C7: 99.15% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 57.82% (1329.82 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.65/0.00] [< 128 us: 19.29/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 59.81% (1375.57 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 47.91/19.17] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.45% (1344.25 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 67.52/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 71.80% (1651.50 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.01ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.69ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.62W +Intel energy model derived package power (CPUs+GT+SA): 1.16W -LLC flushed residency: 65.5% +LLC flushed residency: 79.9% -System Average frequency as fraction of nominal: 60.14% (1383.16 Mhz) -Package 0 C-state residency: 66.43% (C2: 5.32% C3: 4.49% C6: 0.00% C7: 56.61% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 69.02% (1587.56 Mhz) +Package 0 C-state residency: 80.91% (C2: 7.72% C3: 3.81% C6: 3.13% C7: 66.24% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 31.87% +Cores Active: 17.28% GPU Active: 0.00% -Avg Num of Cores Active: 0.54 +Avg Num of Cores Active: 0.23 -Core 0 C-state residency: 83.04% (C3: 0.00% C6: 0.00% C7: 83.04% ) +Core 0 C-state residency: 86.72% (C3: 0.00% C6: 0.00% C7: 86.72% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 230.75/57.69] [< 32 us: 48.07/0.00] [< 64 us: 57.69/86.53] [< 128 us: 124.99/134.60] [< 256 us: 105.76/76.92] [< 512 us: 28.84/48.07] [< 1024 us: 28.84/38.46] [< 2048 us: 28.84/86.53] [< 4096 us: 9.61/57.69] [< 8192 us: 0.00/48.07] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.25% (1454.86 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 67.51/19.29] [< 32 us: 9.64/0.00] [< 64 us: 19.29/19.29] [< 128 us: 144.67/28.93] [< 256 us: 77.16/57.87] [< 512 us: 48.22/19.29] [< 1024 us: 9.64/19.29] [< 2048 us: 9.64/48.22] [< 4096 us: 19.29/115.73] [< 8192 us: 0.00/77.16] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.43% (1596.92 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 644.17/48.07] [< 32 us: 0.00/19.23] [< 64 us: 0.00/28.84] [< 128 us: 19.23/173.06] [< 256 us: 9.61/67.30] [< 512 us: 0.00/76.92] [< 1024 us: 0.00/76.92] [< 2048 us: 0.00/76.92] [< 4096 us: 0.00/48.07] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/28.84] [< 32768 us: 0.00/19.23] -CPU Average frequency as fraction of nominal: 57.37% (1319.43 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 327.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.93] [< 128 us: 0.00/28.93] [< 256 us: 0.00/48.22] [< 512 us: 0.00/28.93] [< 1024 us: 0.00/48.22] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/28.93] [< 16384 us: 0.00/48.22] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.48% (1482.99 Mhz) -Core 1 C-state residency: 87.78% (C3: 0.00% C6: 0.00% C7: 87.78% ) +Core 1 C-state residency: 91.47% (C3: 0.00% C6: 0.00% C7: 91.47% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 173.06/19.23] [< 32 us: 28.84/9.61] [< 64 us: 67.30/19.23] [< 128 us: 28.84/48.07] [< 256 us: 19.23/28.84] [< 512 us: 28.84/67.30] [< 1024 us: 19.23/86.53] [< 2048 us: 19.23/28.84] [< 4096 us: 19.23/38.46] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/19.23] -CPU Average frequency as fraction of nominal: 58.04% (1334.93 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 135.02/19.29] [< 32 us: 0.00/0.00] [< 64 us: 19.29/19.29] [< 128 us: 57.87/19.29] [< 256 us: 19.29/0.00] [< 512 us: 9.64/0.00] [< 1024 us: 19.29/19.29] [< 2048 us: 0.00/57.87] [< 4096 us: 9.64/57.87] [< 8192 us: 0.00/48.22] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.66% (1625.10 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 288.44/38.46] [< 32 us: 0.00/19.23] [< 64 us: 0.00/19.23] [< 128 us: 9.61/28.84] [< 256 us: 19.23/57.69] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/38.46] [< 2048 us: 0.00/28.84] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 57.07% (1312.58 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 154.31/9.64] [< 32 us: 0.00/9.64] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 73.00% (1679.01 Mhz) -Core 2 C-state residency: 89.81% (C3: 0.00% C6: 0.00% C7: 89.81% ) +Core 2 C-state residency: 96.74% (C3: 0.00% C6: 0.00% C7: 96.74% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 163.45/0.00] [< 32 us: 67.30/0.00] [< 64 us: 9.61/19.23] [< 128 us: 28.84/57.69] [< 256 us: 0.00/28.84] [< 512 us: 19.23/57.69] [< 1024 us: 19.23/48.07] [< 2048 us: 19.23/38.46] [< 4096 us: 9.61/19.23] [< 8192 us: 0.00/38.46] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/19.23] -CPU Average frequency as fraction of nominal: 58.04% (1334.92 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 173.60/38.58] [< 32 us: 28.93/0.00] [< 64 us: 28.93/9.64] [< 128 us: 48.22/28.93] [< 256 us: 0.00/28.93] [< 512 us: 19.29/9.64] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/38.58] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/48.22] [< 16384 us: 0.00/28.93] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 63.83% (1468.01 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 346.12/28.84] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/48.07] [< 256 us: 0.00/19.23] [< 512 us: 9.61/48.07] [< 1024 us: 0.00/76.92] [< 2048 us: 0.00/48.07] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/28.84] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/9.61] -CPU Average frequency as fraction of nominal: 57.33% (1318.70 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 154.31/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.64] [< 128 us: 0.00/9.64] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.27% (1616.19 Mhz) -Core 3 C-state residency: 95.29% (C3: 0.00% C6: 0.00% C7: 95.29% ) +Core 3 C-state residency: 98.62% (C3: 0.00% C6: 0.00% C7: 98.62% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 124.99/9.61] [< 32 us: 0.00/0.00] [< 64 us: 19.23/0.00] [< 128 us: 57.69/0.00] [< 256 us: 38.46/28.84] [< 512 us: 9.61/48.07] [< 1024 us: 0.00/48.07] [< 2048 us: 9.61/48.07] [< 4096 us: 0.00/28.84] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/19.23] [< 32768 us: 0.00/19.23] -CPU Average frequency as fraction of nominal: 56.64% (1302.80 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 115.73/9.64] [< 32 us: 0.00/0.00] [< 64 us: 9.64/9.64] [< 128 us: 19.29/9.64] [< 256 us: 9.64/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/28.93] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 58.55% (1346.61 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 96.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.61/9.61] [< 128 us: 19.23/28.84] [< 256 us: 9.61/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/38.46] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.24% (1316.50 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 28.93/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 89.67% (2062.47 Mhz) -Core 4 C-state residency: 96.61% (C3: 0.00% C6: 0.00% C7: 96.61% ) +Core 4 C-state residency: 99.02% (C3: 0.00% C6: 0.00% C7: 99.02% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 57.69/0.00] [< 32 us: 0.00/9.61] [< 64 us: 0.00/0.00] [< 128 us: 9.61/0.00] [< 256 us: 9.61/0.00] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 9.61/9.61] [< 8192 us: 0.00/19.23] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 56.82% (1306.94 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 67.51/0.00] [< 32 us: 9.64/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 9.64/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 59.41% (1366.39 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 134.60/38.46] [< 32 us: 0.00/9.61] [< 64 us: 9.61/9.61] [< 128 us: 0.00/9.61] [< 256 us: 9.61/9.61] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/28.84] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.61] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.70% (1327.07 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 82.80% (1904.33 Mhz) -Core 5 C-state residency: 95.70% (C3: 0.00% C6: 0.00% C7: 95.70% ) +Core 5 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 38.46/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.52% (1345.95 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 48.22/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.64/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 62.78% (1443.94 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 144.22/9.61] [< 32 us: 0.00/9.61] [< 64 us: 0.00/38.46] [< 128 us: 9.61/9.61] [< 256 us: 0.00/9.61] [< 512 us: 0.00/28.84] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.05% (1335.13 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 82.53% (1898.30 Mhz) -Core 6 C-state residency: 90.03% (C3: 0.00% C6: 0.00% C7: 90.03% ) +Core 6 C-state residency: 99.30% (C3: 0.00% C6: 0.00% C7: 99.30% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 38.46/19.23] [< 32 us: 19.23/0.00] [< 64 us: 9.61/9.61] [< 128 us: 9.61/0.00] [< 256 us: 0.00/19.23] [< 512 us: 19.23/9.61] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.61] [< 4096 us: 9.61/19.23] [< 8192 us: 9.61/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.76% (1466.37 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 28.93/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.64] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 64.62% (1486.35 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 96.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.61] [< 128 us: 9.61/9.61] [< 256 us: 9.61/19.23] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/19.23] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.16% (1314.61 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 85.15% (1958.47 Mhz) -Core 7 C-state residency: 98.34% (C3: 0.00% C6: 0.00% C7: 98.34% ) +Core 7 C-state residency: 99.44% (C3: 0.00% C6: 0.00% C7: 99.44% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 67.30/9.61] [< 32 us: 9.61/0.00] [< 64 us: 9.61/0.00] [< 128 us: 9.61/19.23] [< 256 us: 0.00/9.61] [< 512 us: 19.23/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/9.61] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.61] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 56.88% (1308.15 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.64/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.28% (1501.36 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 134.60/19.23] [< 32 us: 0.00/19.23] [< 64 us: 0.00/9.61] [< 128 us: 19.23/28.84] [< 256 us: 0.00/9.61] [< 512 us: 0.00/9.61] [< 1024 us: 0.00/9.61] [< 2048 us: 0.00/19.23] [< 4096 us: 0.00/9.61] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.93% (1332.48 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 87.15% (2004.55 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (104.14ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:03 2024 -0500) (103.67ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.32W +Intel energy model derived package power (CPUs+GT+SA): 2.50W -LLC flushed residency: 74.5% +LLC flushed residency: 51.9% -System Average frequency as fraction of nominal: 61.90% (1423.80 Mhz) -Package 0 C-state residency: 75.84% (C2: 8.39% C3: 3.87% C6: 1.67% C7: 61.92% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 73.05% (1680.13 Mhz) +Package 0 C-state residency: 52.70% (C2: 5.09% C3: 4.26% C6: 0.00% C7: 43.35% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 21.94% +Cores Active: 45.54% GPU Active: 0.00% -Avg Num of Cores Active: 0.34 +Avg Num of Cores Active: 0.60 -Core 0 C-state residency: 86.82% (C3: 0.00% C6: 0.00% C7: 86.82% ) +Core 0 C-state residency: 76.06% (C3: 0.00% C6: 0.00% C7: 76.06% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 105.63/57.61] [< 32 us: 38.41/9.60] [< 64 us: 38.41/19.20] [< 128 us: 134.43/67.22] [< 256 us: 86.42/28.81] [< 512 us: 48.01/76.82] [< 1024 us: 48.01/28.81] [< 2048 us: 19.20/96.02] [< 4096 us: 0.00/48.01] [< 8192 us: 0.00/96.02] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.91% (1332.02 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 135.04/57.87] [< 32 us: 19.29/0.00] [< 64 us: 96.46/67.52] [< 128 us: 192.91/48.23] [< 256 us: 48.23/9.65] [< 512 us: 19.29/125.39] [< 1024 us: 9.65/28.94] [< 2048 us: 9.65/48.23] [< 4096 us: 9.65/86.81] [< 8192 us: 19.29/77.17] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 81.28% (1869.48 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 364.89/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.81] [< 128 us: 0.00/48.01] [< 256 us: 0.00/38.41] [< 512 us: 0.00/19.20] [< 1024 us: 0.00/38.41] [< 2048 us: 0.00/48.01] [< 4096 us: 0.00/38.41] [< 8192 us: 0.00/67.22] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.92% (1470.08 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 472.64/19.29] [< 32 us: 0.00/9.65] [< 64 us: 0.00/77.17] [< 128 us: 0.00/57.87] [< 256 us: 0.00/9.65] [< 512 us: 0.00/48.23] [< 1024 us: 0.00/48.23] [< 2048 us: 0.00/57.87] [< 4096 us: 0.00/48.23] [< 8192 us: 0.00/57.87] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.27% (1501.32 Mhz) -Core 1 C-state residency: 95.13% (C3: 0.00% C6: 0.00% C7: 95.13% ) +Core 1 C-state residency: 87.63% (C3: 0.00% C6: 0.00% C7: 87.63% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 201.65/9.60] [< 32 us: 0.00/0.00] [< 64 us: 67.22/19.20] [< 128 us: 28.81/48.01] [< 256 us: 38.41/9.60] [< 512 us: 0.00/38.41] [< 1024 us: 19.20/48.01] [< 2048 us: 0.00/38.41] [< 4096 us: 0.00/48.01] [< 8192 us: 0.00/67.22] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.06% (1335.45 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 163.98/38.58] [< 32 us: 28.94/0.00] [< 64 us: 57.87/38.58] [< 128 us: 154.33/38.58] [< 256 us: 9.65/28.94] [< 512 us: 0.00/67.52] [< 1024 us: 9.65/19.29] [< 2048 us: 0.00/67.52] [< 4096 us: 0.00/57.87] [< 8192 us: 9.65/57.87] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 59.08% (1358.73 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 182.44/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/9.60] [< 128 us: 9.60/9.60] [< 256 us: 0.00/19.20] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/28.81] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/57.61] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 60.13% (1383.10 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 337.60/9.65] [< 32 us: 0.00/19.29] [< 64 us: 0.00/19.29] [< 128 us: 0.00/38.58] [< 256 us: 0.00/9.65] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/77.17] [< 4096 us: 0.00/57.87] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 68.62% (1578.36 Mhz) -Core 2 C-state residency: 96.56% (C3: 0.00% C6: 0.00% C7: 96.56% ) +Core 2 C-state residency: 77.17% (C3: 0.00% C6: 0.00% C7: 77.17% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 163.24/28.81] [< 32 us: 0.00/0.00] [< 64 us: 28.81/9.60] [< 128 us: 19.20/19.20] [< 256 us: 19.20/9.60] [< 512 us: 0.00/9.60] [< 1024 us: 19.20/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/28.81] [< 8192 us: 0.00/57.61] [< 16384 us: 0.00/48.01] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 59.36% (1365.28 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 135.04/67.52] [< 32 us: 38.58/0.00] [< 64 us: 86.81/9.65] [< 128 us: 77.17/28.94] [< 256 us: 19.29/28.94] [< 512 us: 0.00/86.81] [< 1024 us: 9.65/9.65] [< 2048 us: 0.00/57.87] [< 4096 us: 9.65/48.23] [< 8192 us: 0.00/38.58] [< 16384 us: 9.65/19.29] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 73.29% (1685.64 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 153.64/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.20] [< 256 us: 0.00/19.20] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/38.41] [< 32768 us: 0.00/19.20] -CPU Average frequency as fraction of nominal: 66.66% (1533.23 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 385.83/0.00] [< 32 us: 0.00/28.94] [< 64 us: 0.00/19.29] [< 128 us: 0.00/19.29] [< 256 us: 0.00/38.58] [< 512 us: 0.00/38.58] [< 1024 us: 0.00/96.46] [< 2048 us: 0.00/48.23] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 66.25% (1523.76 Mhz) -Core 3 C-state residency: 97.00% (C3: 0.00% C6: 0.00% C7: 97.00% ) +Core 3 C-state residency: 94.43% (C3: 0.00% C6: 0.00% C7: 94.43% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 96.02/38.41] [< 32 us: 0.00/0.00] [< 64 us: 38.41/0.00] [< 128 us: 28.81/38.41] [< 256 us: 38.41/9.60] [< 512 us: 0.00/19.20] [< 1024 us: 9.60/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/57.61] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 57.64% (1325.75 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 655.90/9.65] [< 32 us: 86.81/482.28] [< 64 us: 115.75/19.29] [< 128 us: 19.29/28.94] [< 256 us: 9.65/19.29] [< 512 us: 9.65/125.39] [< 1024 us: 0.00/57.87] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/48.23] [< 16384 us: 0.00/48.23] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 73.72% (1695.61 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 76.82/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/19.20] -CPU Average frequency as fraction of nominal: 71.16% (1636.70 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.14% (1567.20 Mhz) -Core 4 C-state residency: 96.66% (C3: 0.00% C6: 0.00% C7: 96.66% ) +Core 4 C-state residency: 98.39% (C3: 0.00% C6: 0.00% C7: 98.39% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 86.42/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.60] [< 128 us: 9.60/19.20] [< 256 us: 19.20/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/19.20] [< 2048 us: 9.60/9.60] [< 4096 us: 0.00/19.20] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] -CPU Average frequency as fraction of nominal: 69.62% (1601.19 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 135.04/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.65/9.65] [< 128 us: 0.00/0.00] [< 256 us: 19.29/9.65] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/28.94] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/28.94] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/19.29] +CPU Average frequency as fraction of nominal: 59.81% (1375.61 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 134.43/9.60] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.20] [< 128 us: 0.00/19.20] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.20] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.20] -CPU Average frequency as fraction of nominal: 73.20% (1683.49 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.29] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.80% (1605.33 Mhz) -Core 5 C-state residency: 91.77% (C3: 0.00% C6: 0.00% C7: 91.77% ) +Core 5 C-state residency: 98.77% (C3: 0.00% C6: 0.00% C7: 98.77% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 86.42/19.20] [< 32 us: 9.60/0.00] [< 64 us: 19.20/19.20] [< 128 us: 9.60/19.20] [< 256 us: 9.60/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/28.81] [< 2048 us: 0.00/0.00] [< 4096 us: 19.20/0.00] [< 8192 us: 0.00/19.20] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] -CPU Average frequency as fraction of nominal: 70.61% (1624.07 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 9.65/0.00] [< 64 us: 19.29/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.65] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/28.94] +CPU Average frequency as fraction of nominal: 62.76% (1443.53 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 67.22/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 63.94% (1470.67 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.35% (1503.12 Mhz) -Core 6 C-state residency: 98.60% (C3: 0.00% C6: 0.00% C7: 98.60% ) +Core 6 C-state residency: 99.39% (C3: 0.00% C6: 0.00% C7: 99.39% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 57.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.60/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.60/9.60] [< 2048 us: 0.00/19.20] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.81] -CPU Average frequency as fraction of nominal: 57.37% (1319.57 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 9.65/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 63.15% (1452.39 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 28.81/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 73.71% (1695.23 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] +CPU Average frequency as fraction of nominal: 70.33% (1617.55 Mhz) -Core 7 C-state residency: 96.33% (C3: 0.00% C6: 0.00% C7: 96.33% ) +Core 7 C-state residency: 97.61% (C3: 0.00% C6: 0.00% C7: 97.61% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 28.81/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.60/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 9.60/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] -CPU Average frequency as fraction of nominal: 56.71% (1304.35 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 106.10/0.00] [< 128 us: 38.58/0.00] [< 256 us: 9.65/0.00] [< 512 us: 0.00/144.68] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.01% (1311.29 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 57.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.60] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.68% (1579.65 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 192.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/67.52] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/28.94] [< 1024 us: 0.00/67.52] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 62.71% (1442.44 Mhz) -*** Sampled system activity (Wed Nov 6 15:21:22 2024 -0500) (103.87ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:41:03 2024 -0500) (102.48ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 0.79W +Intel energy model derived package power (CPUs+GT+SA): 10.59W -LLC flushed residency: 86.3% +LLC flushed residency: 27.4% -System Average frequency as fraction of nominal: 63.83% (1468.17 Mhz) -Package 0 C-state residency: 87.31% (C2: 8.20% C3: 4.67% C6: 0.00% C7: 74.44% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 132.95% (3057.91 Mhz) +Package 0 C-state residency: 32.45% (C2: 2.51% C3: 5.20% C6: 0.00% C7: 24.74% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 10.20% +Cores Active: 66.84% GPU Active: 0.00% -Avg Num of Cores Active: 0.15 +Avg Num of Cores Active: 1.12 -Core 0 C-state residency: 89.68% (C3: 0.00% C6: 0.00% C7: 89.68% ) +Core 0 C-state residency: 74.00% (C3: 10.71% C6: 0.00% C7: 63.28% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 28.88/28.88] [< 32 us: 86.65/0.00] [< 64 us: 19.25/19.25] [< 128 us: 163.67/67.39] [< 256 us: 96.27/19.25] [< 512 us: 9.63/9.63] [< 1024 us: 9.63/19.25] [< 2048 us: 0.00/115.53] [< 4096 us: 9.63/48.14] [< 8192 us: 0.00/86.65] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.81% (1513.66 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 624.52/204.92] [< 32 us: 214.68/58.55] [< 64 us: 146.37/195.16] [< 128 us: 146.37/243.95] [< 256 us: 87.82/224.44] [< 512 us: 29.27/87.82] [< 1024 us: 39.03/87.82] [< 2048 us: 19.52/126.86] [< 4096 us: 9.76/48.79] [< 8192 us: 9.76/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 134.74% (3099.07 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 173.29/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/38.51] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/38.51] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.58% (1439.27 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 1239.29/214.68] [< 32 us: 58.55/97.58] [< 64 us: 9.76/156.13] [< 128 us: 29.27/243.95] [< 256 us: 9.76/214.68] [< 512 us: 9.76/58.55] [< 1024 us: 0.00/97.58] [< 2048 us: 0.00/146.37] [< 4096 us: 0.00/58.55] [< 8192 us: 0.00/48.79] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 145.14% (3338.19 Mhz) -Core 1 C-state residency: 95.97% (C3: 0.00% C6: 0.00% C7: 95.97% ) +Core 1 C-state residency: 81.31% (C3: 5.38% C6: 0.00% C7: 75.94% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 96.27/0.00] [< 32 us: 0.00/0.00] [< 64 us: 57.76/9.63] [< 128 us: 38.51/28.88] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.63/9.63] [< 2048 us: 9.63/48.14] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/57.76] [< 16384 us: 0.00/19.25] [< 32768 us: 0.00/19.25] -CPU Average frequency as fraction of nominal: 60.65% (1394.93 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 1297.84/322.02] [< 32 us: 156.13/487.91] [< 64 us: 146.37/204.92] [< 128 us: 68.31/195.16] [< 256 us: 39.03/117.10] [< 512 us: 58.55/136.61] [< 1024 us: 0.00/78.07] [< 2048 us: 9.76/87.82] [< 4096 us: 9.76/97.58] [< 8192 us: 0.00/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 123.70% (2844.99 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 115.53/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.63] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/19.25] -CPU Average frequency as fraction of nominal: 64.12% (1474.70 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 1190.50/214.68] [< 32 us: 39.03/97.58] [< 64 us: 0.00/322.02] [< 128 us: 9.76/97.58] [< 256 us: 19.52/58.55] [< 512 us: 0.00/87.82] [< 1024 us: 0.00/156.13] [< 2048 us: 0.00/126.86] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/39.03] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 147.30% (3387.89 Mhz) -Core 2 C-state residency: 97.57% (C3: 0.00% C6: 0.00% C7: 97.57% ) +Core 2 C-state residency: 69.58% (C3: 0.00% C6: 0.00% C7: 69.58% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 125.16/19.25] [< 32 us: 38.51/0.00] [< 64 us: 19.25/9.63] [< 128 us: 28.88/38.51] [< 256 us: 9.63/0.00] [< 512 us: 9.63/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/38.51] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/48.14] [< 16384 us: 0.00/38.51] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 60.48% (1390.93 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 497.67/146.37] [< 32 us: 107.34/87.82] [< 64 us: 87.82/97.58] [< 128 us: 68.31/185.41] [< 256 us: 68.31/87.82] [< 512 us: 39.03/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/48.79] [< 4096 us: 9.76/68.31] [< 8192 us: 9.76/48.79] [< 16384 us: 9.76/9.76] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 104.74% (2408.92 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 96.27/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/19.25] [< 256 us: 0.00/9.63] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.25] -CPU Average frequency as fraction of nominal: 65.09% (1496.99 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 975.82/175.65] [< 32 us: 9.76/58.55] [< 64 us: 9.76/107.34] [< 128 us: 0.00/175.65] [< 256 us: 9.76/126.86] [< 512 us: 9.76/68.31] [< 1024 us: 0.00/87.82] [< 2048 us: 0.00/87.82] [< 4096 us: 0.00/68.31] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 147.01% (3381.24 Mhz) -Core 3 C-state residency: 97.95% (C3: 0.00% C6: 0.00% C7: 97.95% ) +Core 3 C-state residency: 84.42% (C3: 0.00% C6: 0.00% C7: 84.42% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 77.02/9.63] [< 32 us: 0.00/0.00] [< 64 us: 19.25/0.00] [< 128 us: 19.25/9.63] [< 256 us: 28.88/9.63] [< 512 us: 9.63/0.00] [< 1024 us: 0.00/19.25] [< 2048 us: 0.00/19.25] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/19.25] [< 16384 us: 0.00/38.51] [< 32768 us: 0.00/19.25] -CPU Average frequency as fraction of nominal: 61.94% (1424.51 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 429.36/97.58] [< 32 us: 87.82/9.76] [< 64 us: 58.55/68.31] [< 128 us: 58.55/126.86] [< 256 us: 9.76/97.58] [< 512 us: 39.03/58.55] [< 1024 us: 0.00/68.31] [< 2048 us: 0.00/68.31] [< 4096 us: 0.00/58.55] [< 8192 us: 19.52/29.27] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 143.49% (3300.16 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 75.91% (1745.85 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 263.47/9.76] [< 32 us: 0.00/19.52] [< 64 us: 9.76/19.52] [< 128 us: 0.00/19.52] [< 256 us: 9.76/39.03] [< 512 us: 9.76/48.79] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/29.27] [< 4096 us: 0.00/9.76] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 152.51% (3507.83 Mhz) -Core 4 C-state residency: 98.81% (C3: 0.00% C6: 0.00% C7: 98.81% ) +Core 4 C-state residency: 70.63% (C3: 3.05% C6: 0.00% C7: 67.58% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 57.76/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.63/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.63/9.63] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/19.25] [< 8192 us: 0.00/9.63] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 58.05% (1335.25 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 653.80/243.95] [< 32 us: 263.47/48.79] [< 64 us: 165.89/165.89] [< 128 us: 68.31/146.37] [< 256 us: 29.27/322.02] [< 512 us: 39.03/87.82] [< 1024 us: 19.52/146.37] [< 2048 us: 19.52/48.79] [< 4096 us: 9.76/9.76] [< 8192 us: 0.00/48.79] [< 16384 us: 9.76/0.00] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 148.58% (3417.25 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 78.05% (1795.24 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 917.27/146.37] [< 32 us: 9.76/78.07] [< 64 us: 9.76/126.86] [< 128 us: 9.76/156.13] [< 256 us: 9.76/78.07] [< 512 us: 0.00/39.03] [< 1024 us: 0.00/136.61] [< 2048 us: 0.00/87.82] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 146.14% (3361.24 Mhz) -Core 5 C-state residency: 99.47% (C3: 0.00% C6: 0.00% C7: 99.47% ) +Core 5 C-state residency: 83.86% (C3: 0.03% C6: 0.00% C7: 83.83% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 38.51/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 70.32% (1617.30 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 556.22/107.34] [< 32 us: 19.52/78.07] [< 64 us: 29.27/68.31] [< 128 us: 19.52/146.37] [< 256 us: 9.76/39.03] [< 512 us: 58.55/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/48.79] [< 4096 us: 0.00/68.31] [< 8192 us: 9.76/9.76] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 149.83% (3446.04 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 19.25/0.00] [< 32 us: 9.63/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 78.31% (1801.12 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 234.20/19.52] [< 32 us: 19.52/0.00] [< 64 us: 0.00/19.52] [< 128 us: 0.00/58.55] [< 256 us: 0.00/39.03] [< 512 us: 9.76/19.52] [< 1024 us: 0.00/29.27] [< 2048 us: 0.00/19.52] [< 4096 us: 0.00/9.76] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 151.88% (3493.13 Mhz) -Core 6 C-state residency: 99.33% (C3: 0.00% C6: 0.00% C7: 99.33% ) +Core 6 C-state residency: 96.23% (C3: 0.00% C6: 0.00% C7: 96.23% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 9.63/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.63] -CPU Average frequency as fraction of nominal: 61.07% (1404.60 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 312.26/87.82] [< 32 us: 58.55/0.00] [< 64 us: 29.27/48.79] [< 128 us: 29.27/87.82] [< 256 us: 39.03/19.52] [< 512 us: 9.76/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/39.03] [< 4096 us: 0.00/48.79] [< 8192 us: 0.00/19.52] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 148.78% (3422.00 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 48.14/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.63] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/9.63] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 74.18% (1706.16 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 341.54/87.82] [< 32 us: 0.00/29.27] [< 64 us: 9.76/9.76] [< 128 us: 0.00/68.31] [< 256 us: 9.76/29.27] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/29.27] [< 4096 us: 0.00/19.52] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 148.20% (3408.54 Mhz) -Core 7 C-state residency: 99.47% (C3: 0.00% C6: 0.00% C7: 99.47% ) +Core 7 C-state residency: 93.91% (C3: 0.00% C6: 0.00% C7: 93.91% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.63/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.63] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.68% (1510.60 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 292.75/136.61] [< 32 us: 29.27/0.00] [< 64 us: 29.27/87.82] [< 128 us: 29.27/48.79] [< 256 us: 39.03/29.27] [< 512 us: 9.76/19.52] [< 1024 us: 0.00/19.52] [< 2048 us: 19.52/29.27] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/19.52] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 152.37% (3504.58 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 28.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.63] [< 2048 us: 0.00/9.63] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 78.81% (1812.74 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 380.57/78.07] [< 32 us: 9.76/39.03] [< 64 us: 0.00/68.31] [< 128 us: 0.00/87.82] [< 256 us: 19.52/29.27] [< 512 us: 0.00/9.76] [< 1024 us: 0.00/19.52] [< 2048 us: 0.00/19.52] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/39.03] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] +CPU Average frequency as fraction of nominal: 152.18% (3500.08 Mhz) diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py index b5241feb..6716ec79 100644 --- a/src/measurement/code_carbon_meter.py +++ b/src/measurement/code_carbon_meter.py @@ -2,64 +2,56 @@ import sys from codecarbon import EmissionsTracker from pathlib import Path - -# To run run -# pip install codecarbon +import pandas as pd from os.path import dirname, abspath -import sys -# Sets src as absolute path, everything needs to be relative to src folder REFACTOR_DIR = dirname(abspath(__file__)) sys.path.append(dirname(REFACTOR_DIR)) - class CarbonAnalyzer: def __init__(self, script_path: str): - """ - Initialize with the path to the Python script to analyze. - """ self.script_path = script_path self.tracker = EmissionsTracker(allow_multiple_runs=True) def run_and_measure(self): - """ - Run the specified Python script and measure its energy consumption and CO2 emissions. - """ script = Path(self.script_path) - - # Check if the file exists and is a Python file if not script.exists() or script.suffix != ".py": raise ValueError("Please provide a valid Python script path.") - - # Start tracking emissions self.tracker.start() - try: - # Run the Python script as a subprocess - subprocess.run(["python", str(script)], check=True) + subprocess.run([sys.executable, str(script)], check=True) except subprocess.CalledProcessError as e: print(f"Error: The script encountered an error: {e}") finally: # Stop tracking and get emissions data emissions = self.tracker.stop() - print("Emissions data:", emissions) + if emissions is None or pd.isna(emissions): + print("Warning: No valid emissions data collected. Check system compatibility.") + else: + print("Emissions data:", emissions) def save_report(self, report_path: str = "carbon_report.csv"): """ - Save the emissions report to a CSV file. + Save the emissions report to a CSV file with two columns: attribute and value. """ - import pandas as pd - - data = self.tracker.emissions_data - if data: - df = pd.DataFrame(data) - print("THIS IS THE DF:") - print(df) + emissions_data = self.tracker.final_emissions_data + if emissions_data: + # Convert EmissionsData object to a dictionary and create rows for each attribute + emissions_dict = emissions_data.__dict__ + attributes = list(emissions_dict.keys()) + values = list(emissions_dict.values()) + + # Create a DataFrame with two columns: 'Attribute' and 'Value' + df = pd.DataFrame({ + "Attribute": attributes, + "Value": values + }) + + # Save the DataFrame to CSV df.to_csv(report_path, index=False) print(f"Report saved to {report_path}") else: - print("No data to save.") - + print("No data to save. Ensure CodeCarbon supports your system hardware for emissions tracking.") # Example usage if __name__ == "__main__": diff --git a/test/carbon_report.csv b/test/carbon_report.csv new file mode 100644 index 00000000..eada118d --- /dev/null +++ b/test/carbon_report.csv @@ -0,0 +1,33 @@ +Attribute,Value +timestamp,2024-11-06T15:41:03 +project_name,codecarbon +run_id,7de42608-e864-4267-bcac-db887eedee97 +experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 +duration,4.944858557000089 +emissions, +emissions_rate, +cpu_power, +gpu_power, +ram_power,6.0 +cpu_energy, +gpu_energy, +ram_energy,8.524578333322096e-08 +energy_consumed, +country_name,Canada +country_iso_code,CAN +region,ontario +cloud_provider, +cloud_region, +os,macOS-14.4-x86_64-i386-64bit +python_version,3.10.10 +codecarbon_version,2.7.2 +cpu_count,16 +cpu_model,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz +gpu_count,1 +gpu_model,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz +longitude,-79.7172 +latitude,43.5639 +ram_total_size,16.0 +tracking_mode,machine +on_cloud,N +pue,1.0 From 7b4f4fd64da4230da738571f8a3e93c33df1b931 Mon Sep 17 00:00:00 2001 From: mya Date: Wed, 6 Nov 2024 15:51:27 -0500 Subject: [PATCH 018/105] code carbon fixed --- emissions.csv | 1 + powermetrics_log.txt | 943 +++++++++++++++++++++-------------------- test/carbon_report.csv | 8 +- 3 files changed, 478 insertions(+), 474 deletions(-) diff --git a/emissions.csv b/emissions.csv index 6e513fc3..95396d62 100644 --- a/emissions.csv +++ b/emissions.csv @@ -7,3 +7,4 @@ timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cp 2024-11-06T15:37:41,codecarbon,d7c396c8-6e78-460a-b888-30e09802ba5b,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944484815000124,,,,,6.0,,,8.56689950001055e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 2024-11-06T15:40:04,codecarbon,cb6477c2-f7d1-4b05-82d2-30c0431852e1,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.977463085000181,,,,,6.0,,,8.772543833363975e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 2024-11-06T15:41:03,codecarbon,7de42608-e864-4267-bcac-db887eedee97,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944858557000089,,,,,6.0,,,8.524578333322096e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:51:06,codecarbon,427229d2-013a-4e77-8913-69eff642024e,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.923058721999951,,,,,6.0,,,8.657804333324749e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 diff --git a/powermetrics_log.txt b/powermetrics_log.txt index f3c78899..66c5b616 100644 --- a/powermetrics_log.txt +++ b/powermetrics_log.txt @@ -7,811 +7,814 @@ Boot time: Wed Nov 6 15:12:37 2024 -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (102.89ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (102.86ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.56W +Intel energy model derived package power (CPUs+GT+SA): 1.55W -LLC flushed residency: 85.6% +LLC flushed residency: 80.9% -System Average frequency as fraction of nominal: 77.75% (1788.25 Mhz) -Package 0 C-state residency: 86.77% (C2: 8.30% C3: 4.09% C6: 0.00% C7: 74.38% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 72.49% (1667.22 Mhz) +Package 0 C-state residency: 82.18% (C2: 8.29% C3: 3.75% C6: 0.00% C7: 70.15% C8: 0.00% C9: 0.00% C10: 0.00% ) + +Performance Limited Due to: +CPU LIMIT TURBO_ATTENUATION CPU/GPU Overlap: 0.00% -Cores Active: 10.93% +Cores Active: 15.72% GPU Active: 0.00% -Avg Num of Cores Active: 0.16 +Avg Num of Cores Active: 0.22 -Core 0 C-state residency: 90.34% (C3: 0.00% C6: 0.00% C7: 90.34% ) +Core 0 C-state residency: 90.99% (C3: 0.00% C6: 0.00% C7: 90.99% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 77.75/29.16] [< 32 us: 19.44/0.00] [< 64 us: 29.16/58.32] [< 128 us: 174.95/9.72] [< 256 us: 87.47/9.72] [< 512 us: 9.72/48.60] [< 1024 us: 19.44/9.72] [< 2048 us: 9.72/58.32] [< 4096 us: 0.00/116.63] [< 8192 us: 0.00/87.47] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 72.31% (1663.08 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 175.00/38.89] [< 32 us: 38.89/0.00] [< 64 us: 29.17/29.17] [< 128 us: 145.83/48.61] [< 256 us: 87.50/48.61] [< 512 us: 29.17/48.61] [< 1024 us: 19.44/38.89] [< 2048 us: 0.00/106.94] [< 4096 us: 0.00/87.50] [< 8192 us: 0.00/87.50] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.43% (1343.85 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 291.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/38.88] [< 128 us: 0.00/19.44] [< 256 us: 0.00/0.00] [< 512 us: 0.00/29.16] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/68.03] [< 8192 us: 0.00/48.60] [< 16384 us: 0.00/48.60] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 77.86% (1790.76 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 359.72/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.44] [< 128 us: 0.00/38.89] [< 256 us: 0.00/29.17] [< 512 us: 0.00/38.89] [< 1024 us: 0.00/29.17] [< 2048 us: 0.00/58.33] [< 4096 us: 0.00/29.17] [< 8192 us: 0.00/68.05] [< 16384 us: 0.00/38.89] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 71.14% (1636.14 Mhz) -Core 1 C-state residency: 95.66% (C3: 0.00% C6: 0.00% C7: 95.66% ) +Core 1 C-state residency: 90.14% (C3: 0.00% C6: 0.00% C7: 90.14% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 97.19/0.00] [< 32 us: 29.16/0.00] [< 64 us: 48.60/0.00] [< 128 us: 29.16/38.88] [< 256 us: 29.16/29.16] [< 512 us: 19.44/19.44] [< 1024 us: 9.72/9.72] [< 2048 us: 0.00/38.88] [< 4096 us: 0.00/38.88] [< 8192 us: 0.00/58.32] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.24% (1431.42 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 175.00/19.44] [< 32 us: 19.44/0.00] [< 64 us: 38.89/19.44] [< 128 us: 87.50/38.89] [< 256 us: 29.17/68.05] [< 512 us: 29.17/48.61] [< 1024 us: 19.44/19.44] [< 2048 us: 0.00/48.61] [< 4096 us: 9.72/58.33] [< 8192 us: 0.00/68.05] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 66.76% (1535.53 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 126.35/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/19.44] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 84.40% (1941.31 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 184.72/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.72] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/38.89] [< 4096 us: 0.00/29.17] [< 8192 us: 0.00/29.17] [< 16384 us: 0.00/58.33] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 75.84% (1744.39 Mhz) -Core 2 C-state residency: 97.49% (C3: 0.00% C6: 0.00% C7: 97.49% ) +Core 2 C-state residency: 95.23% (C3: 0.00% C6: 0.00% C7: 95.23% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 116.63/9.72] [< 32 us: 19.44/0.00] [< 64 us: 29.16/0.00] [< 128 us: 38.88/9.72] [< 256 us: 19.44/9.72] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/29.16] [< 4096 us: 0.00/38.88] [< 8192 us: 0.00/58.32] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 59.75% (1374.27 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 155.55/0.00] [< 32 us: 0.00/0.00] [< 64 us: 48.61/29.17] [< 128 us: 29.17/19.44] [< 256 us: 9.72/9.72] [< 512 us: 0.00/0.00] [< 1024 us: 9.72/19.44] [< 2048 us: 9.72/48.61] [< 4096 us: 0.00/29.17] [< 8192 us: 0.00/58.33] [< 16384 us: 0.00/48.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 122.88% (2826.29 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 145.79/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.44] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/38.88] [< 16384 us: 0.00/29.16] [< 32768 us: 0.00/19.44] -CPU Average frequency as fraction of nominal: 81.83% (1882.19 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 145.83/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.44] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/19.44] [< 16384 us: 0.00/48.61] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 73.52% (1690.95 Mhz) -Core 3 C-state residency: 97.42% (C3: 0.00% C6: 0.00% C7: 97.42% ) +Core 3 C-state residency: 97.18% (C3: 0.00% C6: 0.00% C7: 97.18% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 136.07/9.72] [< 32 us: 0.00/0.00] [< 64 us: 9.72/9.72] [< 128 us: 29.16/9.72] [< 256 us: 0.00/19.44] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/0.00] [< 2048 us: 9.72/0.00] [< 4096 us: 0.00/29.16] [< 8192 us: 0.00/48.60] [< 16384 us: 0.00/38.88] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 153.54% (3531.39 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 175.00/19.44] [< 32 us: 9.72/0.00] [< 64 us: 9.72/29.17] [< 128 us: 19.44/0.00] [< 256 us: 29.17/19.44] [< 512 us: 9.72/19.44] [< 1024 us: 0.00/19.44] [< 2048 us: 0.00/48.61] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/38.89] [< 16384 us: 0.00/48.61] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.22% (1339.05 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 68.03/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 98.03% (2254.61 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 107.09% (2463.02 Mhz) -Core 4 C-state residency: 99.05% (C3: 0.00% C6: 0.00% C7: 99.05% ) +Core 4 C-state residency: 98.58% (C3: 0.00% C6: 0.00% C7: 98.58% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 68.03/9.72] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.72] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.72/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.68% (1441.60 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 68.05/0.00] [< 32 us: 19.44/0.00] [< 64 us: 29.17/0.00] [< 128 us: 9.72/9.72] [< 256 us: 9.72/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/29.17] [< 16384 us: 0.00/29.17] [< 32768 us: 0.00/19.44] +CPU Average frequency as fraction of nominal: 65.70% (1511.09 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 58.32/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 94.54% (2174.40 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 38.89/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 105.60% (2428.73 Mhz) -Core 5 C-state residency: 98.64% (C3: 0.00% C6: 0.00% C7: 98.64% ) +Core 5 C-state residency: 99.12% (C3: 0.00% C6: 0.00% C7: 99.12% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 58.32/9.72] [< 32 us: 9.72/0.00] [< 64 us: 29.16/0.00] [< 128 us: 19.44/9.72] [< 256 us: 9.72/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/19.44] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/48.60] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 65.07% (1496.63 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 58.33/19.44] [< 32 us: 19.44/0.00] [< 64 us: 19.44/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.72] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 64.74% (1488.91 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 105.28% (2421.44 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 48.61/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 91.86% (2112.75 Mhz) -Core 6 C-state residency: 99.45% (C3: 0.00% C6: 0.00% C7: 99.45% ) +Core 6 C-state residency: 99.32% (C3: 0.00% C6: 0.00% C7: 99.32% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.72/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.44] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 71.94% (1654.55 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 58.33/0.00] [< 32 us: 9.72/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.72] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/9.72] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 80.64% (1854.80 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 38.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] -CPU Average frequency as fraction of nominal: 106.63% (2452.44 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 29.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 114.43% (2631.83 Mhz) -Core 7 C-state residency: 99.53% (C3: 0.00% C6: 0.00% C7: 99.53% ) +Core 7 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 48.60/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.72] [< 512 us: 0.00/19.44] [< 1024 us: 0.00/9.72] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 132.60% (3049.74 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 38.89/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.72/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.72] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 69.84% (1606.41 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 29.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 109.22% (2512.05 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 38.89/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.72] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.72] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.72] +CPU Average frequency as fraction of nominal: 106.51% (2449.77 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.34ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (104.37ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 0.89W +Intel energy model derived package power (CPUs+GT+SA): 3.87W -LLC flushed residency: 85.5% +LLC flushed residency: 45.9% -System Average frequency as fraction of nominal: 61.37% (1411.42 Mhz) -Package 0 C-state residency: 86.63% (C2: 8.78% C3: 3.60% C6: 0.25% C7: 74.01% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 92.62% (2130.29 Mhz) +Package 0 C-state residency: 46.92% (C2: 6.15% C3: 1.48% C6: 2.95% C7: 36.34% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 10.96% +Cores Active: 51.22% GPU Active: 0.00% -Avg Num of Cores Active: 0.17 +Avg Num of Cores Active: 0.75 -Core 0 C-state residency: 89.97% (C3: 0.00% C6: 0.00% C7: 89.97% ) +Core 0 C-state residency: 79.40% (C3: 0.00% C6: 0.00% C7: 79.40% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 67.09/38.34] [< 32 us: 28.75/0.00] [< 64 us: 0.00/9.58] [< 128 us: 162.93/38.34] [< 256 us: 105.42/9.58] [< 512 us: 28.75/0.00] [< 1024 us: 0.00/38.34] [< 2048 us: 0.00/95.84] [< 4096 us: 9.58/86.26] [< 8192 us: 0.00/86.26] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.34% (1502.83 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 201.21/114.98] [< 32 us: 95.82/0.00] [< 64 us: 86.23/19.16] [< 128 us: 105.40/124.56] [< 256 us: 105.40/47.91] [< 512 us: 114.98/95.82] [< 1024 us: 28.74/86.23] [< 2048 us: 9.58/143.72] [< 4096 us: 19.16/105.40] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 90.66% (2085.21 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 220.43/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/67.09] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 58.79% (1352.11 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 718.62/28.74] [< 32 us: 0.00/19.16] [< 64 us: 0.00/19.16] [< 128 us: 0.00/114.98] [< 256 us: 0.00/57.49] [< 512 us: 0.00/124.56] [< 1024 us: 0.00/86.23] [< 2048 us: 0.00/114.98] [< 4096 us: 0.00/95.82] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 77.65% (1786.03 Mhz) -Core 1 C-state residency: 94.37% (C3: 0.00% C6: 0.00% C7: 94.37% ) +Core 1 C-state residency: 77.01% (C3: 0.00% C6: 0.00% C7: 77.01% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 105.42/19.17] [< 32 us: 0.00/0.00] [< 64 us: 38.34/0.00] [< 128 us: 57.50/38.34] [< 256 us: 47.92/28.75] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/19.17] [< 2048 us: 9.58/47.92] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/57.50] [< 16384 us: 0.00/38.34] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 56.73% (1304.71 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 316.19/38.33] [< 32 us: 47.91/0.00] [< 64 us: 47.91/38.33] [< 128 us: 67.07/172.47] [< 256 us: 67.07/67.07] [< 512 us: 38.33/38.33] [< 1024 us: 38.33/67.07] [< 2048 us: 0.00/95.82] [< 4096 us: 9.58/67.07] [< 8192 us: 0.00/47.91] [< 16384 us: 9.58/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 75.42% (1734.71 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 143.76/0.00] [< 32 us: 0.00/9.58] [< 64 us: 0.00/9.58] [< 128 us: 9.58/28.75] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.75] -CPU Average frequency as fraction of nominal: 58.17% (1337.80 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 421.59/28.74] [< 32 us: 9.58/38.33] [< 64 us: 0.00/0.00] [< 128 us: 0.00/47.91] [< 256 us: 0.00/38.33] [< 512 us: 0.00/67.07] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/67.07] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 77.56% (1783.98 Mhz) -Core 2 C-state residency: 98.21% (C3: 0.00% C6: 0.00% C7: 98.21% ) +Core 2 C-state residency: 94.00% (C3: 1.94% C6: 0.00% C7: 92.06% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 115.01/19.17] [< 32 us: 9.58/0.00] [< 64 us: 38.34/0.00] [< 128 us: 19.17/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/47.92] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 57.08% (1312.79 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 412.01/38.33] [< 32 us: 28.74/0.00] [< 64 us: 67.07/76.65] [< 128 us: 76.65/114.98] [< 256 us: 19.16/67.07] [< 512 us: 38.33/47.91] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/76.65] [< 4096 us: 0.00/86.23] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 88.35% (2032.15 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 86.26/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 60.93% (1401.29 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 450.33/67.07] [< 32 us: 0.00/47.91] [< 64 us: 19.16/19.16] [< 128 us: 0.00/38.33] [< 256 us: 0.00/38.33] [< 512 us: 0.00/47.91] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/47.91] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 94.01% (2162.12 Mhz) -Core 3 C-state residency: 98.40% (C3: 0.00% C6: 0.00% C7: 98.40% ) +Core 3 C-state residency: 93.10% (C3: 0.00% C6: 0.00% C7: 93.10% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 57.50/9.58] [< 32 us: 19.17/9.58] [< 64 us: 28.75/0.00] [< 128 us: 38.34/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.17] [< 16384 us: 0.00/47.92] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 57.08% (1312.88 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 239.54/67.07] [< 32 us: 28.74/0.00] [< 64 us: 28.74/28.74] [< 128 us: 76.65/57.49] [< 256 us: 38.33/28.74] [< 512 us: 9.58/38.33] [< 1024 us: 0.00/28.74] [< 2048 us: 19.16/57.49] [< 4096 us: 0.00/67.07] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 102.84% (2365.32 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.02% (1426.51 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 172.47/0.00] [< 32 us: 9.58/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/28.74] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 75.72% (1741.66 Mhz) -Core 4 C-state residency: 98.40% (C3: 0.00% C6: 0.00% C7: 98.40% ) +Core 4 C-state residency: 84.28% (C3: 0.00% C6: 0.00% C7: 84.28% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 67.09/9.58] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.17/19.17] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 56.85% (1307.53 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 143.72/0.00] [< 32 us: 47.91/0.00] [< 64 us: 57.49/28.74] [< 128 us: 0.00/47.91] [< 256 us: 9.58/28.74] [< 512 us: 9.58/19.16] [< 1024 us: 9.58/28.74] [< 2048 us: 0.00/28.74] [< 4096 us: 9.58/47.91] [< 8192 us: 0.00/28.74] [< 16384 us: 9.58/9.58] [< 32768 us: 0.00/19.16] +CPU Average frequency as fraction of nominal: 90.97% (2092.39 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 47.92/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.17] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 61.94% (1424.51 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 287.45/28.74] [< 32 us: 0.00/38.33] [< 64 us: 0.00/9.58] [< 128 us: 0.00/19.16] [< 256 us: 0.00/19.16] [< 512 us: 0.00/19.16] [< 1024 us: 0.00/47.91] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 80.70% (1856.11 Mhz) -Core 5 C-state residency: 99.09% (C3: 0.00% C6: 0.00% C7: 99.09% ) +Core 5 C-state residency: 96.49% (C3: 0.00% C6: 0.00% C7: 96.49% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 38.34/0.00] [< 32 us: 9.58/0.00] [< 64 us: 9.58/0.00] [< 128 us: 19.17/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.72% (1327.48 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 143.72/19.16] [< 32 us: 9.58/0.00] [< 64 us: 76.65/38.33] [< 128 us: 0.00/19.16] [< 256 us: 28.74/9.58] [< 512 us: 9.58/28.74] [< 1024 us: 9.58/19.16] [< 2048 us: 0.00/57.49] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 107.49% (2472.27 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 38.34/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.56% (1461.91 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 95.82/19.16] [< 32 us: 9.58/9.58] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 78.00% (1793.93 Mhz) -Core 6 C-state residency: 99.20% (C3: 0.00% C6: 0.00% C7: 99.20% ) +Core 6 C-state residency: 89.99% (C3: 0.00% C6: 0.00% C7: 89.99% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 57.50/0.00] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 58.49% (1345.19 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 114.98/9.58] [< 32 us: 19.16/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/28.74] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/28.74] [< 16384 us: 9.58/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 129.92% (2988.23 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.75% (1466.28 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 95.82/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 75.67% (1740.37 Mhz) -Core 7 C-state residency: 99.45% (C3: 0.00% C6: 0.00% C7: 99.45% ) +Core 7 C-state residency: 98.80% (C3: 0.00% C6: 0.00% C7: 98.80% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 59.59% (1370.63 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 143.72/38.33] [< 32 us: 9.58/0.00] [< 64 us: 9.58/19.16] [< 128 us: 0.00/9.58] [< 256 us: 9.58/19.16] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 109.76% (2524.54 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.37% (1480.53 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 124.56/19.16] [< 32 us: 9.58/19.16] [< 64 us: 0.00/9.58] [< 128 us: 0.00/19.16] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 80.88% (1860.25 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.34ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (103.37ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.15W +Intel energy model derived package power (CPUs+GT+SA): 1.51W -LLC flushed residency: 77.9% +LLC flushed residency: 64.5% -System Average frequency as fraction of nominal: 66.51% (1529.80 Mhz) -Package 0 C-state residency: 78.76% (C2: 6.62% C3: 4.89% C6: 0.06% C7: 67.19% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 59.11% (1359.49 Mhz) +Package 0 C-state residency: 65.41% (C2: 5.07% C3: 1.93% C6: 0.00% C7: 58.42% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 12.90% +Cores Active: 33.15% GPU Active: 0.00% -Avg Num of Cores Active: 0.19 +Avg Num of Cores Active: 0.43 -Core 0 C-state residency: 87.17% (C3: 0.00% C6: 0.00% C7: 87.17% ) +Core 0 C-state residency: 80.84% (C3: 0.00% C6: 0.00% C7: 80.84% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 67.09/38.33] [< 32 us: 57.50/9.58] [< 64 us: 57.50/57.50] [< 128 us: 124.59/57.50] [< 256 us: 86.25/38.33] [< 512 us: 47.92/19.17] [< 1024 us: 9.58/28.75] [< 2048 us: 9.58/47.92] [< 4096 us: 9.58/95.84] [< 8192 us: 0.00/67.09] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.94% (1585.71 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 77.39/38.70] [< 32 us: 19.35/0.00] [< 64 us: 9.67/19.35] [< 128 us: 87.06/38.70] [< 256 us: 116.09/38.70] [< 512 us: 19.35/9.67] [< 1024 us: 0.00/38.70] [< 2048 us: 0.00/38.70] [< 4096 us: 9.67/19.35] [< 8192 us: 0.00/96.74] [< 16384 us: 9.67/9.67] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 61.07% (1404.67 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 297.10/9.58] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 0.00/38.33] [< 256 us: 0.00/38.33] [< 512 us: 0.00/28.75] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/76.67] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.78% (1443.96 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 319.23/0.00] [< 32 us: 0.00/9.67] [< 64 us: 0.00/9.67] [< 128 us: 0.00/48.37] [< 256 us: 0.00/19.35] [< 512 us: 0.00/9.67] [< 1024 us: 0.00/58.04] [< 2048 us: 0.00/29.02] [< 4096 us: 0.00/29.02] [< 8192 us: 0.00/87.06] [< 16384 us: 0.00/9.67] [< 32768 us: 0.00/9.67] +CPU Average frequency as fraction of nominal: 59.59% (1370.57 Mhz) -Core 1 C-state residency: 91.19% (C3: 0.09% C6: 0.00% C7: 91.10% ) +Core 1 C-state residency: 94.01% (C3: 0.00% C6: 0.00% C7: 94.01% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 201.26/57.50] [< 32 us: 95.84/0.00] [< 64 us: 47.92/19.17] [< 128 us: 28.75/124.59] [< 256 us: 0.00/19.17] [< 512 us: 19.17/0.00] [< 1024 us: 0.00/38.33] [< 2048 us: 9.58/28.75] [< 4096 us: 0.00/28.75] [< 8192 us: 0.00/47.92] [< 16384 us: 0.00/38.33] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.17% (1475.99 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 212.82/29.02] [< 32 us: 19.35/0.00] [< 64 us: 48.37/19.35] [< 128 us: 48.37/48.37] [< 256 us: 29.02/38.70] [< 512 us: 19.35/9.67] [< 1024 us: 9.67/58.04] [< 2048 us: 9.67/58.04] [< 4096 us: 0.00/48.37] [< 8192 us: 0.00/77.39] [< 16384 us: 0.00/19.35] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 58.41% (1343.47 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 124.59/9.58] [< 32 us: 0.00/9.58] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 65.02% (1495.42 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 154.78/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.67] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.67] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/38.70] [< 2048 us: 0.00/29.02] [< 4096 us: 0.00/19.35] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.35] [< 32768 us: 0.00/29.02] +CPU Average frequency as fraction of nominal: 64.42% (1481.77 Mhz) -Core 2 C-state residency: 90.27% (C3: 0.08% C6: 0.00% C7: 90.19% ) +Core 2 C-state residency: 82.58% (C3: 0.00% C6: 0.00% C7: 82.58% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 268.34/9.58] [< 32 us: 47.92/9.58] [< 64 us: 28.75/38.33] [< 128 us: 47.92/105.42] [< 256 us: 9.58/47.92] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/47.92] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 64.12% (1474.86 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 116.09/0.00] [< 32 us: 9.67/0.00] [< 64 us: 29.02/9.67] [< 128 us: 29.02/29.02] [< 256 us: 9.67/29.02] [< 512 us: 9.67/0.00] [< 1024 us: 0.00/19.35] [< 2048 us: 19.35/38.70] [< 4096 us: 0.00/38.70] [< 8192 us: 0.00/19.35] [< 16384 us: 9.67/48.37] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.94% (1309.51 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 191.67/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/28.75] [< 256 us: 0.00/19.17] [< 512 us: 0.00/19.17] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.33] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.21% (1430.72 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 154.78/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.35] [< 1024 us: 0.00/29.02] [< 2048 us: 0.00/29.02] [< 4096 us: 0.00/19.35] [< 8192 us: 0.00/19.35] [< 16384 us: 0.00/9.67] [< 32768 us: 0.00/19.35] +CPU Average frequency as fraction of nominal: 61.72% (1419.60 Mhz) -Core 3 C-state residency: 98.05% (C3: 0.00% C6: 0.00% C7: 98.05% ) +Core 3 C-state residency: 97.12% (C3: 0.00% C6: 0.00% C7: 97.12% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 172.51/9.58] [< 32 us: 0.00/0.00] [< 64 us: 28.75/9.58] [< 128 us: 19.17/38.33] [< 256 us: 9.58/19.17] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/38.33] [< 2048 us: 0.00/19.17] [< 4096 us: 0.00/19.17] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/19.17] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 58.98% (1356.51 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 116.09/29.02] [< 32 us: 0.00/0.00] [< 64 us: 9.67/9.67] [< 128 us: 38.70/9.67] [< 256 us: 19.35/9.67] [< 512 us: 0.00/0.00] [< 1024 us: 9.67/19.35] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/19.35] [< 8192 us: 0.00/38.70] [< 16384 us: 0.00/29.02] [< 32768 us: 0.00/19.35] +CPU Average frequency as fraction of nominal: 59.52% (1369.05 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 62.56% (1438.87 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 58.04/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.67] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/9.67] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.67] +CPU Average frequency as fraction of nominal: 62.15% (1429.35 Mhz) -Core 4 C-state residency: 99.37% (C3: 0.00% C6: 0.00% C7: 99.37% ) +Core 4 C-state residency: 98.10% (C3: 0.00% C6: 0.00% C7: 98.10% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 60.09% (1382.06 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 77.39/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.67/0.00] [< 128 us: 29.02/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.67/19.35] [< 2048 us: 0.00/29.02] [< 4096 us: 0.00/9.67] [< 8192 us: 0.00/19.35] [< 16384 us: 0.00/29.02] [< 32768 us: 0.00/19.35] +CPU Average frequency as fraction of nominal: 59.86% (1376.78 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 62.41% (1435.42 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 58.04/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.35] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.67] [< 32768 us: 0.00/9.67] +CPU Average frequency as fraction of nominal: 63.36% (1457.24 Mhz) -Core 5 C-state residency: 98.76% (C3: 0.00% C6: 0.00% C7: 98.76% ) +Core 5 C-state residency: 99.15% (C3: 0.00% C6: 0.00% C7: 99.15% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 57.50/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.17] -CPU Average frequency as fraction of nominal: 57.25% (1316.82 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 77.39/0.00] [< 32 us: 19.35/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/29.02] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.67] [< 16384 us: 0.00/19.35] [< 32768 us: 0.00/29.02] +CPU Average frequency as fraction of nominal: 59.53% (1369.28 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.90% (1446.76 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 29.02/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.67] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 63.58% (1462.32 Mhz) -Core 6 C-state residency: 99.58% (C3: 0.00% C6: 0.00% C7: 99.58% ) +Core 6 C-state residency: 99.43% (C3: 0.00% C6: 0.00% C7: 99.43% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 19.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.45% (1459.42 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 38.70/0.00] [< 32 us: 9.67/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.35] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.67] +CPU Average frequency as fraction of nominal: 62.85% (1445.52 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.88% (1446.33 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 38.70/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.67] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.67] +CPU Average frequency as fraction of nominal: 63.24% (1454.47 Mhz) -Core 7 C-state residency: 99.58% (C3: 0.00% C6: 0.00% C7: 99.58% ) +Core 7 C-state residency: 99.50% (C3: 0.00% C6: 0.00% C7: 99.50% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 19.17/0.00] [< 32 us: 9.58/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.51% (1483.83 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 38.70/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.35] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 67.05% (1542.22 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.06% (1473.40 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 29.02/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.67] [< 2048 us: 0.00/9.67] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.09% (1474.07 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.73ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (103.52ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 9.42W +Intel energy model derived package power (CPUs+GT+SA): 1.10W -LLC flushed residency: 27.2% +LLC flushed residency: 79.6% -System Average frequency as fraction of nominal: 132.91% (3056.95 Mhz) -Package 0 C-state residency: 27.77% (C2: 3.18% C3: 1.65% C6: 0.00% C7: 22.95% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 65.04% (1495.89 Mhz) +Package 0 C-state residency: 80.49% (C2: 5.57% C3: 4.18% C6: 0.00% C7: 70.73% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 70.87% +Cores Active: 17.65% GPU Active: 0.00% -Avg Num of Cores Active: 1.02 +Avg Num of Cores Active: 0.28 -Core 0 C-state residency: 61.81% (C3: 0.00% C6: 0.00% C7: 61.81% ) +Core 0 C-state residency: 86.82% (C3: 0.00% C6: 0.00% C7: 86.82% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 472.39/318.14] [< 32 us: 125.33/86.76] [< 64 us: 144.61/163.89] [< 128 us: 96.41/154.25] [< 256 us: 86.76/57.84] [< 512 us: 48.20/48.20] [< 1024 us: 38.56/28.92] [< 2048 us: 0.00/96.41] [< 4096 us: 28.92/67.48] [< 8192 us: 9.64/38.56] [< 16384 us: 9.64/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 139.37% (3205.51 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 38.64/28.98] [< 32 us: 9.66/9.66] [< 64 us: 28.98/48.30] [< 128 us: 115.92/38.64] [< 256 us: 135.24/28.98] [< 512 us: 19.32/9.66] [< 1024 us: 9.66/9.66] [< 2048 us: 0.00/28.98] [< 4096 us: 19.32/67.62] [< 8192 us: 0.00/96.60] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.39% (1572.95 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 992.97/221.73] [< 32 us: 38.56/96.41] [< 64 us: 19.28/115.69] [< 128 us: 9.64/163.89] [< 256 us: 9.64/115.69] [< 512 us: 0.00/86.76] [< 1024 us: 0.00/57.84] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 137.49% (3162.26 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 309.11/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.32] [< 128 us: 0.00/38.64] [< 256 us: 0.00/38.64] [< 512 us: 0.00/19.32] [< 1024 us: 0.00/28.98] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/77.28] [< 8192 us: 0.00/48.30] [< 16384 us: 0.00/19.32] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 60.33% (1387.64 Mhz) -Core 1 C-state residency: 74.15% (C3: 3.45% C6: 0.00% C7: 70.69% ) +Core 1 C-state residency: 92.82% (C3: 0.00% C6: 0.00% C7: 92.82% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 780.88/250.65] [< 32 us: 192.81/57.84] [< 64 us: 96.41/289.22] [< 128 us: 96.41/221.73] [< 256 us: 19.28/115.69] [< 512 us: 96.41/57.84] [< 1024 us: 9.64/86.76] [< 2048 us: 0.00/144.61] [< 4096 us: 0.00/48.20] [< 8192 us: 19.28/28.92] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 118.96% (2736.14 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 96.60/0.00] [< 32 us: 28.98/0.00] [< 64 us: 48.30/9.66] [< 128 us: 48.30/38.64] [< 256 us: 19.32/0.00] [< 512 us: 9.66/38.64] [< 1024 us: 19.32/9.66] [< 2048 us: 0.00/28.98] [< 4096 us: 9.66/48.30] [< 8192 us: 0.00/86.94] [< 16384 us: 0.00/9.66] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 65.96% (1517.02 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 838.73/106.05] [< 32 us: 38.56/48.20] [< 64 us: 9.64/163.89] [< 128 us: 9.64/125.33] [< 256 us: 9.64/86.76] [< 512 us: 0.00/96.41] [< 1024 us: 0.00/57.84] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/57.84] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 133.19% (3063.39 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 135.24/9.66] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.32] [< 128 us: 0.00/9.66] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.66] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/28.98] [< 32768 us: 0.00/28.98] +CPU Average frequency as fraction of nominal: 69.69% (1602.84 Mhz) -Core 2 C-state residency: 69.96% (C3: 1.29% C6: 0.00% C7: 68.66% ) +Core 2 C-state residency: 96.48% (C3: 0.00% C6: 0.00% C7: 96.48% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 1513.56/279.58] [< 32 us: 144.61/877.29] [< 64 us: 134.97/183.17] [< 128 us: 77.12/250.65] [< 256 us: 57.84/163.89] [< 512 us: 77.12/57.84] [< 1024 us: 9.64/86.76] [< 2048 us: 9.64/77.12] [< 4096 us: 0.00/28.92] [< 8192 us: 28.92/38.56] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 137.98% (3173.49 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 164.21/9.66] [< 32 us: 9.66/0.00] [< 64 us: 28.98/9.66] [< 128 us: 9.66/28.98] [< 256 us: 9.66/19.32] [< 512 us: 19.32/19.32] [< 1024 us: 9.66/19.32] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/48.30] [< 8192 us: 0.00/67.62] [< 16384 us: 0.00/28.98] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.23% (1615.39 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 1041.18/144.61] [< 32 us: 9.64/86.76] [< 64 us: 0.00/134.97] [< 128 us: 9.64/144.61] [< 256 us: 0.00/173.53] [< 512 us: 0.00/106.05] [< 1024 us: 0.00/67.48] [< 2048 us: 0.00/96.41] [< 4096 us: 0.00/38.56] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 132.09% (3037.98 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 115.92/0.00] [< 32 us: 0.00/9.66] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.66] [< 256 us: 0.00/9.66] [< 512 us: 0.00/9.66] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/9.66] [< 16384 us: 0.00/19.32] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 70.72% (1626.67 Mhz) -Core 3 C-state residency: 84.48% (C3: 0.04% C6: 0.00% C7: 84.44% ) +Core 3 C-state residency: 97.41% (C3: 0.00% C6: 0.00% C7: 97.41% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 665.20/173.53] [< 32 us: 77.12/9.64] [< 64 us: 38.56/144.61] [< 128 us: 96.41/279.58] [< 256 us: 57.84/96.41] [< 512 us: 38.56/48.20] [< 1024 us: 9.64/77.12] [< 2048 us: 28.92/67.48] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 130.58% (3003.32 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 86.94/0.00] [< 32 us: 0.00/0.00] [< 64 us: 38.64/0.00] [< 128 us: 9.66/9.66] [< 256 us: 0.00/9.66] [< 512 us: 9.66/19.32] [< 1024 us: 9.66/19.32] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/38.64] [< 16384 us: 0.00/28.98] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.34% (1318.91 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 337.42/38.56] [< 32 us: 28.92/0.00] [< 64 us: 9.64/28.92] [< 128 us: 0.00/77.12] [< 256 us: 0.00/57.84] [< 512 us: 0.00/48.20] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 130.10% (2992.36 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 77.28/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/19.32] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.66] [< 32768 us: 0.00/19.32] +CPU Average frequency as fraction of nominal: 69.04% (1587.96 Mhz) -Core 4 C-state residency: 93.84% (C3: 2.03% C6: 0.00% C7: 91.81% ) +Core 4 C-state residency: 95.52% (C3: 0.00% C6: 0.00% C7: 95.52% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 645.91/163.89] [< 32 us: 86.76/86.76] [< 64 us: 0.00/77.12] [< 128 us: 28.92/183.17] [< 256 us: 28.92/28.92] [< 512 us: 28.92/57.84] [< 1024 us: 9.64/38.56] [< 2048 us: 0.00/77.12] [< 4096 us: 0.00/38.56] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 132.71% (3052.28 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 77.28/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.32/9.66] [< 128 us: 9.66/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/19.32] [< 4096 us: 9.66/19.32] [< 8192 us: 0.00/28.98] [< 16384 us: 0.00/19.32] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.74% (1305.11 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 462.74/86.76] [< 32 us: 0.00/48.20] [< 64 us: 0.00/19.28] [< 128 us: 0.00/77.12] [< 256 us: 0.00/48.20] [< 512 us: 0.00/48.20] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/19.28] -CPU Average frequency as fraction of nominal: 116.52% (2680.06 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 67.62/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.66] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.66] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 71.97% (1655.26 Mhz) -Core 5 C-state residency: 96.10% (C3: 0.00% C6: 0.00% C7: 96.10% ) +Core 5 C-state residency: 97.91% (C3: 0.00% C6: 0.00% C7: 97.91% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 337.42/38.56] [< 32 us: 0.00/9.64] [< 64 us: 38.56/57.84] [< 128 us: 48.20/106.05] [< 256 us: 28.92/38.56] [< 512 us: 9.64/19.28] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/48.20] [< 8192 us: 0.00/57.84] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 136.30% (3134.86 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 38.64/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.66/0.00] [< 128 us: 9.66/0.00] [< 256 us: 9.66/0.00] [< 512 us: 9.66/0.00] [< 1024 us: 9.66/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/9.66] [< 16384 us: 0.00/19.32] [< 32768 us: 0.00/28.98] +CPU Average frequency as fraction of nominal: 57.12% (1313.82 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 183.17/28.92] [< 32 us: 9.64/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/28.92] [< 256 us: 0.00/19.28] [< 512 us: 0.00/19.28] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 114.91% (2642.86 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.64/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.66/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.66] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 61.58% (1416.34 Mhz) -Core 6 C-state residency: 96.58% (C3: 0.00% C6: 0.00% C7: 96.58% ) +Core 6 C-state residency: 99.02% (C3: 0.00% C6: 0.00% C7: 99.02% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 260.29/77.12] [< 32 us: 48.20/19.28] [< 64 us: 9.64/19.28] [< 128 us: 19.28/96.41] [< 256 us: 28.92/9.64] [< 512 us: 19.28/0.00] [< 1024 us: 0.00/38.56] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 137.87% (3171.12 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 57.96/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.32/0.00] [< 128 us: 0.00/9.66] [< 256 us: 9.66/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/9.66] [< 16384 us: 0.00/19.32] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 59.43% (1366.98 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 347.06/96.41] [< 32 us: 9.64/57.84] [< 64 us: 0.00/19.28] [< 128 us: 0.00/28.92] [< 256 us: 9.64/57.84] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 138.77% (3191.70 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 67.62/9.66] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.66] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 72.51% (1667.78 Mhz) -Core 7 C-state residency: 95.69% (C3: 0.00% C6: 0.00% C7: 95.69% ) +Core 7 C-state residency: 99.28% (C3: 0.00% C6: 0.00% C7: 99.28% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 260.29/77.12] [< 32 us: 38.56/9.64] [< 64 us: 0.00/57.84] [< 128 us: 48.20/67.48] [< 256 us: 38.56/19.28] [< 512 us: 0.00/19.28] [< 1024 us: 0.00/48.20] [< 2048 us: 9.64/9.64] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/38.56] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/19.28] -CPU Average frequency as fraction of nominal: 115.43% (2654.97 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 38.64/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.32/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/9.66] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 62.03% (1426.58 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 221.73/48.20] [< 32 us: 9.64/9.64] [< 64 us: 0.00/38.56] [< 128 us: 19.28/28.92] [< 256 us: 9.64/38.56] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/19.28] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.92] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 139.61% (3211.14 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 67.62/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.66] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.66] [< 2048 us: 0.00/9.66] [< 4096 us: 0.00/9.66] [< 8192 us: 0.00/9.66] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.66] +CPU Average frequency as fraction of nominal: 72.18% (1660.18 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.52ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (103.73ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 0.78W +Intel energy model derived package power (CPUs+GT+SA): 3.61W -LLC flushed residency: 88% +LLC flushed residency: 61% -System Average frequency as fraction of nominal: 62.96% (1448.10 Mhz) -Package 0 C-state residency: 88.85% (C2: 7.70% C3: 4.74% C6: 0.00% C7: 76.42% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 113.03% (2599.62 Mhz) +Package 0 C-state residency: 61.57% (C2: 4.30% C3: 2.63% C6: 0.00% C7: 54.65% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 9.01% +Cores Active: 37.04% GPU Active: 0.00% -Avg Num of Cores Active: 0.13 +Avg Num of Cores Active: 0.54 -Core 0 C-state residency: 92.40% (C3: 0.00% C6: 0.00% C7: 92.40% ) +Core 0 C-state residency: 78.04% (C3: 0.00% C6: 0.00% C7: 78.04% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 47.84/19.14] [< 32 us: 9.57/0.00] [< 64 us: 47.84/28.70] [< 128 us: 105.25/19.14] [< 256 us: 105.25/19.14] [< 512 us: 19.14/9.57] [< 1024 us: 19.14/0.00] [< 2048 us: 0.00/57.41] [< 4096 us: 0.00/124.38] [< 8192 us: 0.00/66.98] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.07% (1312.59 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 134.96/106.04] [< 32 us: 57.84/28.92] [< 64 us: 86.76/106.04] [< 128 us: 115.68/38.56] [< 256 us: 96.40/9.64] [< 512 us: 38.56/38.56] [< 1024 us: 9.64/28.92] [< 2048 us: 0.00/48.20] [< 4096 us: 0.00/38.56] [< 8192 us: 0.00/115.68] [< 16384 us: 9.64/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 110.00% (2529.91 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 239.20/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.70] [< 128 us: 0.00/38.27] [< 256 us: 0.00/28.70] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/19.14] [< 4096 us: 0.00/19.14] [< 8192 us: 0.00/28.70] [< 16384 us: 0.00/66.98] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 59.21% (1361.88 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 520.56/19.28] [< 32 us: 9.64/38.56] [< 64 us: 0.00/115.68] [< 128 us: 0.00/67.48] [< 256 us: 0.00/28.92] [< 512 us: 0.00/48.20] [< 1024 us: 0.00/38.56] [< 2048 us: 0.00/38.56] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/77.12] [< 16384 us: 0.00/28.92] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 101.70% (2339.20 Mhz) -Core 1 C-state residency: 94.38% (C3: 0.00% C6: 0.00% C7: 94.38% ) +Core 1 C-state residency: 81.71% (C3: 0.01% C6: 0.00% C7: 81.70% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 86.11/19.14] [< 32 us: 9.57/9.57] [< 64 us: 28.70/19.14] [< 128 us: 47.84/9.57] [< 256 us: 28.70/9.57] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.57] [< 4096 us: 9.57/28.70] [< 8192 us: 0.00/38.27] [< 16384 us: 0.00/57.41] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 72.24% (1661.54 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 742.28/154.24] [< 32 us: 96.40/472.36] [< 64 us: 67.48/115.68] [< 128 us: 96.40/86.76] [< 256 us: 38.56/57.84] [< 512 us: 19.28/38.56] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/38.56] [< 4096 us: 0.00/19.28] [< 8192 us: 19.28/48.20] [< 16384 us: 0.00/28.92] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 125.12% (2877.82 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 162.66/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.70] [< 128 us: 0.00/19.14] [< 256 us: 0.00/19.14] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.14] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/28.70] -CPU Average frequency as fraction of nominal: 59.63% (1371.50 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 665.16/57.84] [< 32 us: 9.64/57.84] [< 64 us: 0.00/134.96] [< 128 us: 0.00/163.88] [< 256 us: 0.00/57.84] [< 512 us: 0.00/38.56] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/38.56] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 105.77% (2432.71 Mhz) -Core 2 C-state residency: 98.45% (C3: 0.00% C6: 0.00% C7: 98.45% ) +Core 2 C-state residency: 92.79% (C3: 0.00% C6: 0.00% C7: 92.79% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 114.82/0.00] [< 32 us: 19.14/0.00] [< 64 us: 0.00/19.14] [< 128 us: 28.70/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/19.14] [< 8192 us: 0.00/38.27] [< 16384 us: 0.00/57.41] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.20% (1315.61 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 327.76/86.76] [< 32 us: 67.48/9.64] [< 64 us: 38.56/106.04] [< 128 us: 48.20/125.32] [< 256 us: 48.20/28.92] [< 512 us: 19.28/28.92] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/28.92] [< 4096 us: 9.64/38.56] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/38.56] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 112.14% (2579.30 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 86.11/9.57] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.57] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.27] -CPU Average frequency as fraction of nominal: 60.84% (1399.33 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 424.16/77.12] [< 32 us: 0.00/28.92] [< 64 us: 9.64/48.20] [< 128 us: 0.00/86.76] [< 256 us: 0.00/57.84] [< 512 us: 0.00/38.56] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/19.28] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 120.04% (2760.96 Mhz) -Core 3 C-state residency: 98.78% (C3: 0.00% C6: 0.00% C7: 98.78% ) +Core 3 C-state residency: 95.28% (C3: 2.06% C6: 0.00% C7: 93.22% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 86.11/0.00] [< 32 us: 9.57/0.00] [< 64 us: 9.57/9.57] [< 128 us: 19.14/9.57] [< 256 us: 0.00/9.57] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/38.27] [< 32768 us: 0.00/19.14] -CPU Average frequency as fraction of nominal: 57.44% (1321.14 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 289.20/77.12] [< 32 us: 77.12/0.00] [< 64 us: 9.64/57.84] [< 128 us: 48.20/125.32] [< 256 us: 48.20/28.92] [< 512 us: 0.00/28.92] [< 1024 us: 9.64/19.28] [< 2048 us: 0.00/28.92] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/48.20] [< 16384 us: 0.00/48.20] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 98.58% (2267.26 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 63.24% (1454.43 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 154.24/0.00] [< 32 us: 0.00/9.64] [< 64 us: 0.00/9.64] [< 128 us: 0.00/19.28] [< 256 us: 0.00/19.28] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.92] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 107.97% (2483.37 Mhz) -Core 4 C-state residency: 98.93% (C3: 0.00% C6: 0.00% C7: 98.93% ) +Core 4 C-state residency: 94.27% (C3: 0.00% C6: 0.00% C7: 94.27% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 19.14/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.14/0.00] [< 256 us: 9.57/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/28.70] -CPU Average frequency as fraction of nominal: 57.82% (1329.75 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 269.92/48.20] [< 32 us: 9.64/9.64] [< 64 us: 19.28/77.12] [< 128 us: 19.28/86.76] [< 256 us: 28.92/0.00] [< 512 us: 9.64/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 9.64/19.28] [< 8192 us: 0.00/67.48] [< 16384 us: 0.00/19.28] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 92.80% (2134.49 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 38.27/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 66.17% (1521.88 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 269.92/19.28] [< 32 us: 0.00/28.92] [< 64 us: 0.00/67.48] [< 128 us: 0.00/19.28] [< 256 us: 0.00/19.28] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/28.92] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/28.92] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 111.15% (2556.40 Mhz) -Core 5 C-state residency: 99.10% (C3: 0.00% C6: 0.00% C7: 99.10% ) +Core 5 C-state residency: 96.95% (C3: 0.00% C6: 0.00% C7: 96.95% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 47.84/9.57] [< 32 us: 9.57/0.00] [< 64 us: 9.57/0.00] [< 128 us: 9.57/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/19.14] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 58.76% (1351.43 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 183.16/86.76] [< 32 us: 28.92/9.64] [< 64 us: 19.28/57.84] [< 128 us: 48.20/48.20] [< 256 us: 9.64/0.00] [< 512 us: 19.28/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/19.28] [< 8192 us: 0.00/28.92] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 104.14% (2395.14 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 38.27/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 65.69% (1510.92 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 106.04/0.00] [< 32 us: 0.00/9.64] [< 64 us: 9.64/19.28] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.28] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 123.93% (2850.33 Mhz) -Core 6 C-state residency: 98.92% (C3: 0.00% C6: 0.00% C7: 98.92% ) +Core 6 C-state residency: 98.62% (C3: 0.00% C6: 0.00% C7: 98.62% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 47.84/0.00] [< 32 us: 38.27/0.00] [< 64 us: 9.57/19.14] [< 128 us: 0.00/0.00] [< 256 us: 9.57/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.14] [< 16384 us: 0.00/9.57] [< 32768 us: 0.00/19.14] -CPU Average frequency as fraction of nominal: 58.23% (1339.36 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 144.60/19.28] [< 32 us: 19.28/0.00] [< 64 us: 9.64/9.64] [< 128 us: 9.64/77.12] [< 256 us: 0.00/9.64] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] +CPU Average frequency as fraction of nominal: 125.20% (2879.71 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 28.70/9.57] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 67.61% (1554.95 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 106.04/28.92] [< 32 us: 0.00/9.64] [< 64 us: 0.00/9.64] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.64] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 114.29% (2628.72 Mhz) -Core 7 C-state residency: 99.13% (C3: 0.00% C6: 0.00% C7: 99.13% ) +Core 7 C-state residency: 98.19% (C3: 0.00% C6: 0.00% C7: 98.19% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 47.84/0.00] [< 32 us: 9.57/0.00] [< 64 us: 9.57/0.00] [< 128 us: 9.57/9.57] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.57] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.27] -CPU Average frequency as fraction of nominal: 58.65% (1348.89 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 86.76/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.28/0.00] [< 128 us: 0.00/57.84] [< 256 us: 9.64/28.92] [< 512 us: 19.28/0.00] [< 1024 us: 0.00/19.28] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 129.79% (2985.28 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 28.70/0.00] [< 32 us: 9.57/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.57] [< 2048 us: 0.00/9.57] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.57] -CPU Average frequency as fraction of nominal: 66.18% (1522.12 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 125.32/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.28] [< 128 us: 0.00/28.92] [< 256 us: 0.00/0.00] [< 512 us: 0.00/28.92] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.28] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 116.40% (2677.26 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (104.43ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (102.73ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 0.81W +Intel energy model derived package power (CPUs+GT+SA): 6.94W -LLC flushed residency: 87.6% +LLC flushed residency: 52.7% -System Average frequency as fraction of nominal: 65.32% (1502.43 Mhz) -Package 0 C-state residency: 88.38% (C2: 6.69% C3: 4.64% C6: 0.00% C7: 77.06% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 144.88% (3332.28 Mhz) +Package 0 C-state residency: 53.46% (C2: 5.27% C3: 2.14% C6: 0.00% C7: 46.05% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 9.71% +Cores Active: 39.50% GPU Active: 0.00% -Avg Num of Cores Active: 0.14 +Avg Num of Cores Active: 0.57 -Core 0 C-state residency: 90.71% (C3: 0.00% C6: 0.00% C7: 90.71% ) +Core 0 C-state residency: 76.72% (C3: 0.96% C6: 0.00% C7: 75.76% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 47.88/9.58] [< 32 us: 19.15/9.58] [< 64 us: 9.58/9.58] [< 128 us: 124.49/19.15] [< 256 us: 86.18/9.58] [< 512 us: 19.15/19.15] [< 1024 us: 9.58/19.15] [< 2048 us: 0.00/57.45] [< 4096 us: 9.58/76.61] [< 8192 us: 0.00/86.18] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 66.37% (1526.42 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 486.71/262.82] [< 32 us: 155.75/97.34] [< 64 us: 116.81/146.01] [< 128 us: 165.48/136.28] [< 256 us: 155.75/107.08] [< 512 us: 19.47/58.41] [< 1024 us: 9.73/48.67] [< 2048 us: 9.73/116.81] [< 4096 us: 0.00/77.87] [< 8192 us: 0.00/68.14] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 123.64% (2843.69 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 181.94/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.15] [< 1024 us: 0.00/38.30] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/38.30] [< 8192 us: 0.00/28.73] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/28.73] -CPU Average frequency as fraction of nominal: 60.38% (1388.85 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 924.75/165.48] [< 32 us: 9.73/68.14] [< 64 us: 9.73/175.22] [< 128 us: 19.47/165.48] [< 256 us: 9.73/126.54] [< 512 us: 0.00/48.67] [< 1024 us: 0.00/38.94] [< 2048 us: 0.00/58.41] [< 4096 us: 0.00/48.67] [< 8192 us: 0.00/48.67] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/19.47] +CPU Average frequency as fraction of nominal: 141.82% (3261.96 Mhz) -Core 1 C-state residency: 96.19% (C3: 0.00% C6: 0.00% C7: 96.19% ) +Core 1 C-state residency: 79.63% (C3: 0.00% C6: 0.00% C7: 79.63% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 76.61/38.30] [< 32 us: 9.58/0.00] [< 64 us: 47.88/19.15] [< 128 us: 47.88/9.58] [< 256 us: 47.88/9.58] [< 512 us: 9.58/0.00] [< 1024 us: 9.58/38.30] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/57.45] [< 8192 us: 0.00/28.73] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 65.71% (1511.44 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 963.68/262.82] [< 32 us: 107.08/467.24] [< 64 us: 97.34/107.08] [< 128 us: 19.47/58.41] [< 256 us: 38.94/146.01] [< 512 us: 48.67/29.20] [< 1024 us: 0.00/48.67] [< 2048 us: 9.73/38.94] [< 4096 us: 0.00/38.94] [< 8192 us: 0.00/77.87] [< 16384 us: 9.73/9.73] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 150.98% (3472.54 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 191.52/0.00] [< 32 us: 0.00/9.58] [< 64 us: 9.58/28.73] [< 128 us: 0.00/19.15] [< 256 us: 0.00/28.73] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/38.30] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 64.57% (1485.16 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 554.85/136.28] [< 32 us: 9.73/58.41] [< 64 us: 29.20/77.87] [< 128 us: 9.73/58.41] [< 256 us: 9.73/58.41] [< 512 us: 0.00/19.47] [< 1024 us: 0.00/38.94] [< 2048 us: 0.00/77.87] [< 4096 us: 0.00/38.94] [< 8192 us: 0.00/19.47] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/19.47] +CPU Average frequency as fraction of nominal: 142.68% (3281.62 Mhz) -Core 2 C-state residency: 98.29% (C3: 0.00% C6: 0.00% C7: 98.29% ) +Core 2 C-state residency: 84.32% (C3: 0.16% C6: 0.00% C7: 84.16% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 124.49/19.15] [< 32 us: 19.15/0.00] [< 64 us: 47.88/9.58] [< 128 us: 19.15/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/28.73] [< 2048 us: 0.00/38.30] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.73] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 60.36% (1388.24 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 408.84/194.68] [< 32 us: 136.28/58.41] [< 64 us: 29.20/97.34] [< 128 us: 29.20/107.08] [< 256 us: 38.94/48.67] [< 512 us: 29.20/19.47] [< 1024 us: 9.73/29.20] [< 2048 us: 9.73/29.20] [< 4096 us: 9.73/58.41] [< 8192 us: 9.73/29.20] [< 16384 us: 0.00/38.94] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 152.62% (3510.37 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 114.91/9.58] [< 32 us: 0.00/0.00] [< 64 us: 9.58/9.58] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/28.73] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.15] [< 32768 us: 0.00/28.73] -CPU Average frequency as fraction of nominal: 64.85% (1491.45 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 622.99/175.22] [< 32 us: 9.73/87.61] [< 64 us: 0.00/77.87] [< 128 us: 9.73/29.20] [< 256 us: 9.73/116.81] [< 512 us: 0.00/29.20] [< 1024 us: 0.00/38.94] [< 2048 us: 0.00/19.47] [< 4096 us: 0.00/38.94] [< 8192 us: 0.00/29.20] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 141.82% (3261.88 Mhz) -Core 3 C-state residency: 98.74% (C3: 0.00% C6: 0.00% C7: 98.74% ) +Core 3 C-state residency: 93.46% (C3: 0.00% C6: 0.00% C7: 93.46% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 57.45/0.00] [< 32 us: 9.58/0.00] [< 64 us: 28.73/0.00] [< 128 us: 9.58/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/19.15] [< 8192 us: 0.00/19.15] [< 16384 us: 0.00/28.73] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 66.84% (1537.31 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 457.51/87.61] [< 32 us: 29.20/0.00] [< 64 us: 19.47/107.08] [< 128 us: 38.94/126.54] [< 256 us: 19.47/97.34] [< 512 us: 19.47/19.47] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/48.67] [< 4096 us: 9.73/48.67] [< 8192 us: 0.00/19.47] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/19.47] +CPU Average frequency as fraction of nominal: 141.17% (3247.00 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.87% (1514.95 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 233.62/58.41] [< 32 us: 0.00/19.47] [< 64 us: 9.73/19.47] [< 128 us: 0.00/0.00] [< 256 us: 0.00/29.20] [< 512 us: 0.00/19.47] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/9.73] [< 4096 us: 0.00/9.73] [< 8192 us: 0.00/38.94] [< 16384 us: 0.00/19.47] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 141.59% (3256.62 Mhz) -Core 4 C-state residency: 99.42% (C3: 0.00% C6: 0.00% C7: 99.42% ) +Core 4 C-state residency: 95.09% (C3: 0.00% C6: 0.00% C7: 95.09% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 38.30/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 66.92% (1539.18 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 292.03/97.34] [< 32 us: 38.94/29.20] [< 64 us: 19.47/48.67] [< 128 us: 9.73/48.67] [< 256 us: 38.94/58.41] [< 512 us: 29.20/9.73] [< 1024 us: 0.00/9.73] [< 2048 us: 9.73/38.94] [< 4096 us: 0.00/38.94] [< 8192 us: 0.00/29.20] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 137.20% (3155.71 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 38.30/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 73.36% (1687.35 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 340.70/97.34] [< 32 us: 0.00/19.47] [< 64 us: 9.73/48.67] [< 128 us: 0.00/9.73] [< 256 us: 9.73/48.67] [< 512 us: 0.00/38.94] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/19.47] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/58.41] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 136.38% (3136.69 Mhz) -Core 5 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) +Core 5 C-state residency: 96.88% (C3: 0.00% C6: 0.00% C7: 96.88% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 28.73/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 61.10% (1405.34 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 262.82/48.67] [< 32 us: 19.47/0.00] [< 64 us: 9.73/29.20] [< 128 us: 9.73/58.41] [< 256 us: 0.00/58.41] [< 512 us: 29.20/9.73] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/19.47] [< 4096 us: 0.00/29.20] [< 8192 us: 0.00/38.94] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 121.27% (2789.12 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 69.53% (1599.21 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 116.81/9.73] [< 32 us: 29.20/9.73] [< 64 us: 0.00/19.47] [< 128 us: 9.73/19.47] [< 256 us: 0.00/38.94] [< 512 us: 0.00/9.73] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.47] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.73] +CPU Average frequency as fraction of nominal: 143.11% (3291.58 Mhz) -Core 6 C-state residency: 98.64% (C3: 0.00% C6: 0.00% C7: 98.64% ) +Core 6 C-state residency: 96.90% (C3: 0.00% C6: 0.00% C7: 96.90% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 57.45/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/19.15] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 57.70% (1327.13 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 233.62/116.81] [< 32 us: 77.87/0.00] [< 64 us: 19.47/116.81] [< 128 us: 19.47/19.47] [< 256 us: 48.67/19.47] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/29.20] [< 2048 us: 0.00/9.73] [< 4096 us: 0.00/58.41] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.47] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 148.17% (3407.96 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.15] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 70.28% (1616.49 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 369.90/68.14] [< 32 us: 0.00/38.94] [< 64 us: 9.73/136.28] [< 128 us: 0.00/29.20] [< 256 us: 0.00/48.67] [< 512 us: 0.00/9.73] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/9.73] [< 8192 us: 0.00/9.73] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.73] +CPU Average frequency as fraction of nominal: 137.89% (3171.40 Mhz) -Core 7 C-state residency: 99.40% (C3: 0.00% C6: 0.00% C7: 99.40% ) +Core 7 C-state residency: 91.23% (C3: 0.00% C6: 0.00% C7: 91.23% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 19.15/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] -CPU Average frequency as fraction of nominal: 63.02% (1449.54 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 165.48/9.73] [< 32 us: 0.00/9.73] [< 64 us: 9.73/19.47] [< 128 us: 9.73/58.41] [< 256 us: 0.00/19.47] [< 512 us: 9.73/9.73] [< 1024 us: 9.73/19.47] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/19.47] [< 8192 us: 9.73/9.73] [< 16384 us: 0.00/9.73] [< 32768 us: 0.00/9.73] +CPU Average frequency as fraction of nominal: 151.47% (3483.84 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 47.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.15] -CPU Average frequency as fraction of nominal: 69.39% (1595.86 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 194.68/48.67] [< 32 us: 0.00/9.73] [< 64 us: 0.00/19.47] [< 128 us: 0.00/19.47] [< 256 us: 0.00/19.47] [< 512 us: 0.00/38.94] [< 1024 us: 0.00/9.73] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.73] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.73] +CPU Average frequency as fraction of nominal: 134.23% (3087.38 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.67ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:05 2024 -0500) (104.37ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 0.94W +Intel energy model derived package power (CPUs+GT+SA): 0.93W -LLC flushed residency: 84% +LLC flushed residency: 85.2% -System Average frequency as fraction of nominal: 64.63% (1486.47 Mhz) -Package 0 C-state residency: 84.83% (C2: 7.14% C3: 6.21% C6: 0.00% C7: 71.47% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 61.09% (1405.02 Mhz) +Package 0 C-state residency: 86.15% (C2: 8.63% C3: 4.18% C6: 2.79% C7: 70.56% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 12.90% +Cores Active: 11.59% GPU Active: 0.00% -Avg Num of Cores Active: 0.21 +Avg Num of Cores Active: 0.18 -Core 0 C-state residency: 89.13% (C3: 0.00% C6: 0.00% C7: 89.13% ) +Core 0 C-state residency: 89.46% (C3: 0.00% C6: 0.00% C7: 89.46% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 96.46/48.23] [< 32 us: 28.94/9.65] [< 64 us: 19.29/28.94] [< 128 us: 154.34/67.52] [< 256 us: 125.40/28.94] [< 512 us: 0.00/19.29] [< 1024 us: 9.65/9.65] [< 2048 us: 0.00/48.23] [< 4096 us: 9.65/106.11] [< 8192 us: 0.00/67.52] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 67.72% (1557.54 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 47.91/47.91] [< 32 us: 28.74/0.00] [< 64 us: 47.91/28.74] [< 128 us: 162.88/28.74] [< 256 us: 124.56/9.58] [< 512 us: 0.00/28.74] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/105.39] [< 4096 us: 9.58/86.23] [< 8192 us: 0.00/86.23] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 64.87% (1492.00 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 299.03/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/19.29] [< 128 us: 0.00/38.58] [< 256 us: 0.00/48.23] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/48.23] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 59.64% (1371.76 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 287.44/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/19.16] [< 128 us: 0.00/47.91] [< 256 us: 0.00/9.58] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/28.74] [< 2048 us: 0.00/47.91] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 58.41% (1343.51 Mhz) -Core 1 C-state residency: 96.25% (C3: 0.00% C6: 0.00% C7: 96.25% ) +Core 1 C-state residency: 94.89% (C3: 0.00% C6: 0.00% C7: 94.89% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 135.04/19.29] [< 32 us: 9.65/0.00] [< 64 us: 19.29/19.29] [< 128 us: 86.81/38.58] [< 256 us: 28.94/28.94] [< 512 us: 19.29/28.94] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/57.88] [< 16384 us: 0.00/48.23] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.43% (1320.99 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 105.39/0.00] [< 32 us: 9.58/0.00] [< 64 us: 47.91/9.58] [< 128 us: 47.91/19.16] [< 256 us: 38.33/19.16] [< 512 us: 9.58/0.00] [< 1024 us: 19.16/19.16] [< 2048 us: 0.00/57.49] [< 4096 us: 0.00/67.07] [< 8192 us: 0.00/57.49] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 57.30% (1318.01 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 192.92/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/48.23] [< 256 us: 0.00/19.29] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 62.14% (1429.31 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 153.30/9.58] [< 32 us: 0.00/9.58] [< 64 us: 0.00/9.58] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/28.74] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 60.85% (1399.66 Mhz) -Core 2 C-state residency: 94.99% (C3: 0.00% C6: 0.00% C7: 94.99% ) +Core 2 C-state residency: 97.19% (C3: 0.00% C6: 0.00% C7: 97.19% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 96.46/38.58] [< 32 us: 9.65/0.00] [< 64 us: 28.94/9.65] [< 128 us: 19.29/0.00] [< 256 us: 48.23/0.00] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/19.29] [< 4096 us: 9.65/9.65] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 69.52% (1599.00 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 105.39/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.16/9.58] [< 128 us: 57.49/0.00] [< 256 us: 9.58/19.16] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/38.33] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 56.81% (1306.64 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 154.34/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/19.29] [< 256 us: 0.00/9.65] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 62.58% (1439.40 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 134.14/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.58] [< 128 us: 0.00/9.58] [< 256 us: 0.00/19.16] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/9.58] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 60.52% (1392.06 Mhz) -Core 3 C-state residency: 98.06% (C3: 0.00% C6: 0.00% C7: 98.06% ) +Core 3 C-state residency: 97.89% (C3: 0.00% C6: 0.00% C7: 97.89% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 28.94/0.00] [< 128 us: 9.65/19.29] [< 256 us: 9.65/0.00] [< 512 us: 9.65/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/28.94] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 57.51% (1322.64 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 162.88/9.58] [< 32 us: 0.00/0.00] [< 64 us: 28.74/9.58] [< 128 us: 19.16/9.58] [< 256 us: 19.16/38.33] [< 512 us: 0.00/28.74] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/28.74] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 56.87% (1308.02 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 57.88/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.65] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 71.88% (1653.24 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 86.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/19.16] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 60.76% (1397.40 Mhz) -Core 4 C-state residency: 96.90% (C3: 0.00% C6: 0.00% C7: 96.90% ) +Core 4 C-state residency: 98.54% (C3: 0.00% C6: 0.00% C7: 98.54% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 67.52/19.29] [< 32 us: 9.65/0.00] [< 64 us: 9.65/9.65] [< 128 us: 19.29/0.00] [< 256 us: 19.29/9.65] [< 512 us: 9.65/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 9.65/9.65] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 57.82% (1329.83 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 86.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.58/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 9.58/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/28.74] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 56.98% (1310.54 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 125.40/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/28.94] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 67.87% (1560.98 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 47.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 62.25% (1431.74 Mhz) -Core 5 C-state residency: 98.59% (C3: 0.00% C6: 0.00% C7: 98.59% ) +Core 5 C-state residency: 98.75% (C3: 0.00% C6: 0.00% C7: 98.75% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 67.52/9.65] [< 32 us: 0.00/0.00] [< 64 us: 19.29/0.00] [< 128 us: 28.94/19.29] [< 256 us: 9.65/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/38.58] -CPU Average frequency as fraction of nominal: 57.98% (1333.61 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 57.49/9.58] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 28.74/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.19% (1315.31 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 73.64% (1693.70 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 63.32% (1456.35 Mhz) -Core 6 C-state residency: 98.78% (C3: 0.00% C6: 0.00% C7: 98.78% ) +Core 6 C-state residency: 99.09% (C3: 0.00% C6: 0.00% C7: 99.09% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 19.29/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 9.65/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 58.04% (1334.83 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 47.91/9.58] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 19.16/9.58] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 57.36% (1319.38 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 67.52/9.65] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 71.66% (1648.25 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 47.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 62.68% (1441.62 Mhz) -Core 7 C-state residency: 99.15% (C3: 0.00% C6: 0.00% C7: 99.15% ) +Core 7 C-state residency: 99.46% (C3: 0.00% C6: 0.00% C7: 99.46% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.65/0.00] [< 128 us: 19.29/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 59.81% (1375.57 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 47.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.58] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 61.58% (1416.29 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 67.52/0.00] [< 32 us: 0.00/9.65] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 71.80% (1651.50 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 38.33/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 62.37% (1434.48 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:02 2024 -0500) (103.69ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:06 2024 -0500) (104.36ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 1.16W +Intel energy model derived package power (CPUs+GT+SA): 0.85W -LLC flushed residency: 79.9% +LLC flushed residency: 85.2% -System Average frequency as fraction of nominal: 69.02% (1587.56 Mhz) -Package 0 C-state residency: 80.91% (C2: 7.72% C3: 3.81% C6: 3.13% C7: 66.24% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 68.36% (1572.18 Mhz) +Package 0 C-state residency: 85.95% (C2: 6.60% C3: 4.37% C6: 0.00% C7: 74.98% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 17.28% +Cores Active: 11.83% GPU Active: 0.00% -Avg Num of Cores Active: 0.23 +Avg Num of Cores Active: 0.16 -Core 0 C-state residency: 86.72% (C3: 0.00% C6: 0.00% C7: 86.72% ) +Core 0 C-state residency: 89.15% (C3: 0.00% C6: 0.00% C7: 89.15% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 67.51/19.29] [< 32 us: 9.64/0.00] [< 64 us: 19.29/19.29] [< 128 us: 144.67/28.93] [< 256 us: 77.16/57.87] [< 512 us: 48.22/19.29] [< 1024 us: 9.64/19.29] [< 2048 us: 9.64/48.22] [< 4096 us: 19.29/115.73] [< 8192 us: 0.00/77.16] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 69.43% (1596.92 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 9.58/38.33] [< 32 us: 9.58/0.00] [< 64 us: 19.16/0.00] [< 128 us: 95.82/0.00] [< 256 us: 86.24/0.00] [< 512 us: 38.33/28.75] [< 1024 us: 9.58/0.00] [< 2048 us: 9.58/47.91] [< 4096 us: 9.58/67.08] [< 8192 us: 0.00/86.24] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 66.49% (1529.29 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 327.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/28.93] [< 128 us: 0.00/28.93] [< 256 us: 0.00/48.22] [< 512 us: 0.00/28.93] [< 1024 us: 0.00/48.22] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/28.93] [< 16384 us: 0.00/48.22] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 64.48% (1482.99 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 201.23/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/57.49] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/47.91] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 63.56% (1461.98 Mhz) -Core 1 C-state residency: 91.47% (C3: 0.00% C6: 0.00% C7: 91.47% ) +Core 1 C-state residency: 95.01% (C3: 0.00% C6: 0.00% C7: 95.01% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 135.02/19.29] [< 32 us: 0.00/0.00] [< 64 us: 19.29/19.29] [< 128 us: 57.87/19.29] [< 256 us: 19.29/0.00] [< 512 us: 9.64/0.00] [< 1024 us: 19.29/19.29] [< 2048 us: 0.00/57.87] [< 4096 us: 9.64/57.87] [< 8192 us: 0.00/48.22] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 70.66% (1625.10 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 114.99/9.58] [< 32 us: 38.33/0.00] [< 64 us: 28.75/28.75] [< 128 us: 38.33/9.58] [< 256 us: 19.16/9.58] [< 512 us: 9.58/9.58] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/28.75] [< 4096 us: 0.00/47.91] [< 8192 us: 0.00/47.91] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 75.16% (1728.77 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 154.31/9.64] [< 32 us: 0.00/9.64] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 73.00% (1679.01 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 105.41/19.16] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/28.75] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 64.36% (1480.18 Mhz) -Core 2 C-state residency: 96.74% (C3: 0.00% C6: 0.00% C7: 96.74% ) +Core 2 C-state residency: 98.37% (C3: 0.00% C6: 0.00% C7: 98.37% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 173.60/38.58] [< 32 us: 28.93/0.00] [< 64 us: 28.93/9.64] [< 128 us: 48.22/28.93] [< 256 us: 0.00/28.93] [< 512 us: 19.29/9.64] [< 1024 us: 0.00/38.58] [< 2048 us: 0.00/38.58] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/48.22] [< 16384 us: 0.00/28.93] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 63.83% (1468.01 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 105.41/0.00] [< 32 us: 9.58/0.00] [< 64 us: 28.75/9.58] [< 128 us: 9.58/0.00] [< 256 us: 9.58/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/28.75] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/57.49] [< 8192 us: 0.00/19.16] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 60.60% (1393.75 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 154.31/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.64] [< 128 us: 0.00/9.64] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 70.27% (1616.19 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 86.24/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/9.58] [< 16384 us: 0.00/19.16] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 67.40% (1550.28 Mhz) -Core 3 C-state residency: 98.62% (C3: 0.00% C6: 0.00% C7: 98.62% ) +Core 3 C-state residency: 98.88% (C3: 0.00% C6: 0.00% C7: 98.88% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 115.73/9.64] [< 32 us: 0.00/0.00] [< 64 us: 9.64/9.64] [< 128 us: 19.29/9.64] [< 256 us: 9.64/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/28.93] [< 4096 us: 0.00/9.64] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/28.93] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 58.55% (1346.61 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 95.82/0.00] [< 32 us: 0.00/0.00] [< 64 us: 28.75/0.00] [< 128 us: 0.00/9.58] [< 256 us: 0.00/9.58] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.16] [< 2048 us: 0.00/19.16] [< 4096 us: 0.00/19.16] [< 8192 us: 0.00/28.75] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 64.25% (1477.84 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 28.93/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 89.67% (2062.47 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.01% (1587.26 Mhz) -Core 4 C-state residency: 99.02% (C3: 0.00% C6: 0.00% C7: 99.02% ) +Core 4 C-state residency: 99.31% (C3: 0.00% C6: 0.00% C7: 99.31% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 67.51/0.00] [< 32 us: 9.64/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 9.64/0.00] [< 512 us: 0.00/9.64] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 59.41% (1366.39 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 28.75/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/19.16] +CPU Average frequency as fraction of nominal: 60.00% (1379.89 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 82.80% (1904.33 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 19.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.62% (1624.36 Mhz) -Core 5 C-state residency: 99.26% (C3: 0.00% C6: 0.00% C7: 99.26% ) +Core 5 C-state residency: 99.55% (C3: 0.00% C6: 0.00% C7: 99.55% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 48.22/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.64/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/19.29] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 62.78% (1443.94 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 19.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 70.81% (1628.69 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 82.53% (1898.30 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 19.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.38% (1595.76 Mhz) -Core 6 C-state residency: 99.30% (C3: 0.00% C6: 0.00% C7: 99.30% ) +Core 6 C-state residency: 99.38% (C3: 0.00% C6: 0.00% C7: 99.38% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 28.93/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.64] [< 16384 us: 0.00/9.64] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 64.62% (1486.35 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 9.58/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.58] [< 32768 us: 0.00/9.58] +CPU Average frequency as fraction of nominal: 63.05% (1450.12 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.64] -CPU Average frequency as fraction of nominal: 85.15% (1958.47 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 19.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.76% (1604.55 Mhz) -Core 7 C-state residency: 99.44% (C3: 0.00% C6: 0.00% C7: 99.44% ) +Core 7 C-state residency: 99.55% (C3: 0.00% C6: 0.00% C7: 99.55% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.64/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.28% (1501.36 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 19.16/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.58/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.58% (1600.38 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.64] [< 2048 us: 0.00/9.64] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 87.15% (2004.55 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 28.75/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.58] [< 2048 us: 0.00/9.58] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.38% (1572.64 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:03 2024 -0500) (103.67ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:06 2024 -0500) (103.02ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 2.50W +Intel energy model derived package power (CPUs+GT+SA): 1.29W -LLC flushed residency: 51.9% +LLC flushed residency: 80.8% -System Average frequency as fraction of nominal: 73.05% (1680.13 Mhz) -Package 0 C-state residency: 52.70% (C2: 5.09% C3: 4.26% C6: 0.00% C7: 43.35% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 68.01% (1564.17 Mhz) +Package 0 C-state residency: 81.86% (C2: 7.33% C3: 3.66% C6: 0.00% C7: 70.86% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 45.54% +Cores Active: 15.99% GPU Active: 0.00% -Avg Num of Cores Active: 0.60 +Avg Num of Cores Active: 0.31 -Core 0 C-state residency: 76.06% (C3: 0.00% C6: 0.00% C7: 76.06% ) +Core 0 C-state residency: 85.82% (C3: 0.00% C6: 0.00% C7: 85.82% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 135.04/57.87] [< 32 us: 19.29/0.00] [< 64 us: 96.46/67.52] [< 128 us: 192.91/48.23] [< 256 us: 48.23/9.65] [< 512 us: 19.29/125.39] [< 1024 us: 9.65/28.94] [< 2048 us: 9.65/48.23] [< 4096 us: 9.65/86.81] [< 8192 us: 19.29/77.17] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 81.28% (1869.48 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 38.83/19.41] [< 32 us: 9.71/0.00] [< 64 us: 19.41/38.83] [< 128 us: 155.31/77.66] [< 256 us: 135.90/29.12] [< 512 us: 38.83/29.12] [< 1024 us: 29.12/48.54] [< 2048 us: 9.71/29.12] [< 4096 us: 9.71/58.24] [< 8192 us: 0.00/106.78] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 68.33% (1571.68 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 472.64/19.29] [< 32 us: 0.00/9.65] [< 64 us: 0.00/77.17] [< 128 us: 0.00/57.87] [< 256 us: 0.00/9.65] [< 512 us: 0.00/48.23] [< 1024 us: 0.00/48.23] [< 2048 us: 0.00/57.87] [< 4096 us: 0.00/48.23] [< 8192 us: 0.00/57.87] [< 16384 us: 0.00/38.58] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.27% (1501.32 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 397.99/19.41] [< 32 us: 9.71/0.00] [< 64 us: 0.00/9.71] [< 128 us: 0.00/48.54] [< 256 us: 0.00/77.66] [< 512 us: 0.00/77.66] [< 1024 us: 0.00/48.54] [< 2048 us: 0.00/19.41] [< 4096 us: 0.00/9.71] [< 8192 us: 0.00/58.24] [< 16384 us: 0.00/29.12] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 61.19% (1407.32 Mhz) -Core 1 C-state residency: 87.63% (C3: 0.00% C6: 0.00% C7: 87.63% ) +Core 1 C-state residency: 91.03% (C3: 0.00% C6: 0.00% C7: 91.03% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 163.98/38.58] [< 32 us: 28.94/0.00] [< 64 us: 57.87/38.58] [< 128 us: 154.33/38.58] [< 256 us: 9.65/28.94] [< 512 us: 0.00/67.52] [< 1024 us: 9.65/19.29] [< 2048 us: 0.00/67.52] [< 4096 us: 0.00/57.87] [< 8192 us: 9.65/57.87] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 59.08% (1358.73 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 165.02/29.12] [< 32 us: 48.54/0.00] [< 64 us: 19.41/48.54] [< 128 us: 106.78/87.36] [< 256 us: 38.83/67.95] [< 512 us: 38.83/29.12] [< 1024 us: 19.41/9.71] [< 2048 us: 9.71/29.12] [< 4096 us: 0.00/38.83] [< 8192 us: 0.00/97.07] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 63.65% (1463.84 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 337.60/9.65] [< 32 us: 0.00/19.29] [< 64 us: 0.00/19.29] [< 128 us: 0.00/38.58] [< 256 us: 0.00/9.65] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/77.17] [< 4096 us: 0.00/57.87] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 68.62% (1578.36 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 427.11/19.41] [< 32 us: 9.71/9.71] [< 64 us: 0.00/87.36] [< 128 us: 0.00/97.07] [< 256 us: 0.00/67.95] [< 512 us: 0.00/48.54] [< 1024 us: 0.00/19.41] [< 2048 us: 0.00/9.71] [< 4096 us: 0.00/9.71] [< 8192 us: 0.00/19.41] [< 16384 us: 0.00/38.83] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 69.68% (1602.75 Mhz) -Core 2 C-state residency: 77.17% (C3: 0.00% C6: 0.00% C7: 77.17% ) +Core 2 C-state residency: 93.90% (C3: 0.00% C6: 0.00% C7: 93.90% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 135.04/67.52] [< 32 us: 38.58/0.00] [< 64 us: 86.81/9.65] [< 128 us: 77.17/28.94] [< 256 us: 19.29/28.94] [< 512 us: 0.00/86.81] [< 1024 us: 9.65/9.65] [< 2048 us: 0.00/57.87] [< 4096 us: 9.65/48.23] [< 8192 us: 0.00/38.58] [< 16384 us: 9.65/19.29] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 73.29% (1685.64 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 203.85/38.83] [< 32 us: 9.71/0.00] [< 64 us: 87.36/19.41] [< 128 us: 9.71/58.24] [< 256 us: 19.41/67.95] [< 512 us: 38.83/0.00] [< 1024 us: 9.71/29.12] [< 2048 us: 0.00/38.83] [< 4096 us: 0.00/38.83] [< 8192 us: 0.00/77.66] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 71.31% (1640.21 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 385.83/0.00] [< 32 us: 0.00/28.94] [< 64 us: 0.00/19.29] [< 128 us: 0.00/19.29] [< 256 us: 0.00/38.58] [< 512 us: 0.00/38.58] [< 1024 us: 0.00/96.46] [< 2048 us: 0.00/48.23] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/38.58] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 66.25% (1523.76 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 320.33/19.41] [< 32 us: 9.71/19.41] [< 64 us: 0.00/29.12] [< 128 us: 0.00/19.41] [< 256 us: 0.00/77.66] [< 512 us: 0.00/48.54] [< 1024 us: 0.00/29.12] [< 2048 us: 0.00/19.41] [< 4096 us: 0.00/9.71] [< 8192 us: 0.00/29.12] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/19.41] +CPU Average frequency as fraction of nominal: 70.72% (1626.45 Mhz) -Core 3 C-state residency: 94.43% (C3: 0.00% C6: 0.00% C7: 94.43% ) +Core 3 C-state residency: 96.71% (C3: 0.02% C6: 0.00% C7: 96.69% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 655.90/9.65] [< 32 us: 86.81/482.28] [< 64 us: 115.75/19.29] [< 128 us: 19.29/28.94] [< 256 us: 9.65/19.29] [< 512 us: 9.65/125.39] [< 1024 us: 0.00/57.87] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/38.58] [< 8192 us: 0.00/48.23] [< 16384 us: 0.00/48.23] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 73.72% (1695.61 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 213.56/19.41] [< 32 us: 29.12/0.00] [< 64 us: 58.24/38.83] [< 128 us: 29.12/67.95] [< 256 us: 29.12/77.66] [< 512 us: 0.00/38.83] [< 1024 us: 0.00/29.12] [< 2048 us: 0.00/29.12] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/29.12] [< 16384 us: 0.00/29.12] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 67.97% (1563.32 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.29] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 68.14% (1567.20 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 67.95/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/9.71] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.71] [< 1024 us: 0.00/19.41] [< 2048 us: 0.00/19.41] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 80.95% (1861.94 Mhz) -Core 4 C-state residency: 98.39% (C3: 0.00% C6: 0.00% C7: 98.39% ) +Core 4 C-state residency: 97.62% (C3: 0.00% C6: 0.00% C7: 97.62% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 135.04/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.65/9.65] [< 128 us: 0.00/0.00] [< 256 us: 19.29/9.65] [< 512 us: 0.00/19.29] [< 1024 us: 0.00/28.94] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/28.94] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/19.29] -CPU Average frequency as fraction of nominal: 59.81% (1375.61 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 106.78/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.71/0.00] [< 128 us: 29.12/48.54] [< 256 us: 0.00/29.12] [< 512 us: 19.41/19.41] [< 1024 us: 0.00/38.83] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.71] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.41] +CPU Average frequency as fraction of nominal: 73.60% (1692.85 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/19.29] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/9.65] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 69.80% (1605.33 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 126.19/9.71] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.71] [< 128 us: 0.00/19.41] [< 256 us: 0.00/19.41] [< 512 us: 0.00/29.12] [< 1024 us: 0.00/19.41] [< 2048 us: 0.00/9.71] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 77.09% (1772.99 Mhz) -Core 5 C-state residency: 98.77% (C3: 0.00% C6: 0.00% C7: 98.77% ) +Core 5 C-state residency: 98.46% (C3: 0.00% C6: 0.00% C7: 98.46% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 9.65/0.00] [< 64 us: 19.29/9.65] [< 128 us: 0.00/0.00] [< 256 us: 0.00/9.65] [< 512 us: 0.00/9.65] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/28.94] [< 32768 us: 0.00/28.94] -CPU Average frequency as fraction of nominal: 62.76% (1443.53 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 97.07/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.71/0.00] [< 128 us: 9.71/29.12] [< 256 us: 0.00/19.41] [< 512 us: 9.71/19.41] [< 1024 us: 0.00/38.83] [< 2048 us: 0.00/0.00] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.71] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 63.67% (1464.34 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 77.17/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/19.29] [< 2048 us: 0.00/19.29] [< 4096 us: 0.00/19.29] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 65.35% (1503.12 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 29.12/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.71] [< 2048 us: 0.00/9.71] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 92.04% (2116.84 Mhz) -Core 6 C-state residency: 99.39% (C3: 0.00% C6: 0.00% C7: 99.39% ) +Core 6 C-state residency: 99.13% (C3: 0.00% C6: 0.00% C7: 99.13% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 48.23/0.00] [< 32 us: 9.65/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.65] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 63.15% (1452.39 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 87.36/9.71] [< 32 us: 19.41/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.41] [< 256 us: 0.00/0.00] [< 512 us: 0.00/19.41] [< 1024 us: 0.00/19.41] [< 2048 us: 0.00/9.71] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.71] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/9.71] +CPU Average frequency as fraction of nominal: 65.55% (1507.64 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.65] -CPU Average frequency as fraction of nominal: 70.33% (1617.55 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 29.12/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/9.71] [< 2048 us: 0.00/19.41] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 88.41% (2033.54 Mhz) -Core 7 C-state residency: 97.61% (C3: 0.00% C6: 0.00% C7: 97.61% ) +Core 7 C-state residency: 99.08% (C3: 0.00% C6: 0.00% C7: 99.08% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 38.58/0.00] [< 32 us: 0.00/0.00] [< 64 us: 106.10/0.00] [< 128 us: 38.58/0.00] [< 256 us: 9.65/0.00] [< 512 us: 0.00/144.68] [< 1024 us: 0.00/9.65] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 57.01% (1311.29 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 48.54/0.00] [< 32 us: 9.71/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/19.41] [< 256 us: 0.00/0.00] [< 512 us: 9.71/9.71] [< 1024 us: 0.00/9.71] [< 2048 us: 0.00/19.41] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 86.28% (1984.55 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 192.91/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/67.52] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/28.94] [< 1024 us: 0.00/67.52] [< 2048 us: 0.00/9.65] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.65] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 62.71% (1442.44 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 48.54/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 0.00/0.00] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.71] [< 1024 us: 0.00/9.71] [< 2048 us: 0.00/9.71] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.71] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 93.34% (2146.76 Mhz) -*** Sampled system activity (Wed Nov 6 15:41:03 2024 -0500) (102.48ms elapsed) *** +*** Sampled system activity (Wed Nov 6 15:51:06 2024 -0500) (104.22ms elapsed) *** **** Processor usage **** -Intel energy model derived package power (CPUs+GT+SA): 10.59W +Intel energy model derived package power (CPUs+GT+SA): 1.58W -LLC flushed residency: 27.4% +LLC flushed residency: 72.9% -System Average frequency as fraction of nominal: 132.95% (3057.91 Mhz) -Package 0 C-state residency: 32.45% (C2: 2.51% C3: 5.20% C6: 0.00% C7: 24.74% C8: 0.00% C9: 0.00% C10: 0.00% ) +System Average frequency as fraction of nominal: 75.26% (1730.89 Mhz) +Package 0 C-state residency: 74.76% (C2: 6.57% C3: 4.91% C6: 0.00% C7: 63.27% C8: 0.00% C9: 0.00% C10: 0.00% ) CPU/GPU Overlap: 0.00% -Cores Active: 66.84% +Cores Active: 20.61% GPU Active: 0.00% -Avg Num of Cores Active: 1.12 +Avg Num of Cores Active: 0.33 -Core 0 C-state residency: 74.00% (C3: 10.71% C6: 0.00% C7: 63.28% ) +Core 0 C-state residency: 87.25% (C3: 0.07% C6: 0.00% C7: 87.18% ) -CPU 0 duty cycles/s: active/idle [< 16 us: 624.52/204.92] [< 32 us: 214.68/58.55] [< 64 us: 146.37/195.16] [< 128 us: 146.37/243.95] [< 256 us: 87.82/224.44] [< 512 us: 29.27/87.82] [< 1024 us: 39.03/87.82] [< 2048 us: 19.52/126.86] [< 4096 us: 9.76/48.79] [< 8192 us: 9.76/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 134.74% (3099.07 Mhz) +CPU 0 duty cycles/s: active/idle [< 16 us: 239.88/105.55] [< 32 us: 47.98/0.00] [< 64 us: 38.38/76.76] [< 128 us: 124.74/134.33] [< 256 us: 182.31/57.57] [< 512 us: 38.38/86.36] [< 1024 us: 9.60/28.79] [< 2048 us: 0.00/38.38] [< 4096 us: 9.60/86.36] [< 8192 us: 0.00/57.57] [< 16384 us: 0.00/19.19] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 74.04% (1702.96 Mhz) -CPU 1 duty cycles/s: active/idle [< 16 us: 1239.29/214.68] [< 32 us: 58.55/97.58] [< 64 us: 9.76/156.13] [< 128 us: 29.27/243.95] [< 256 us: 9.76/214.68] [< 512 us: 9.76/58.55] [< 1024 us: 0.00/97.58] [< 2048 us: 0.00/146.37] [< 4096 us: 0.00/58.55] [< 8192 us: 0.00/48.79] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 145.14% (3338.19 Mhz) +CPU 1 duty cycles/s: active/idle [< 16 us: 498.94/9.60] [< 32 us: 0.00/38.38] [< 64 us: 0.00/47.98] [< 128 us: 9.60/86.36] [< 256 us: 0.00/19.19] [< 512 us: 0.00/76.76] [< 1024 us: 0.00/76.76] [< 2048 us: 0.00/38.38] [< 4096 us: 0.00/47.98] [< 8192 us: 0.00/19.19] [< 16384 us: 0.00/38.38] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 74.84% (1721.21 Mhz) -Core 1 C-state residency: 81.31% (C3: 5.38% C6: 0.00% C7: 75.94% ) +Core 1 C-state residency: 85.80% (C3: 3.61% C6: 0.00% C7: 82.19% ) -CPU 2 duty cycles/s: active/idle [< 16 us: 1297.84/322.02] [< 32 us: 156.13/487.91] [< 64 us: 146.37/204.92] [< 128 us: 68.31/195.16] [< 256 us: 39.03/117.10] [< 512 us: 58.55/136.61] [< 1024 us: 0.00/78.07] [< 2048 us: 9.76/87.82] [< 4096 us: 9.76/97.58] [< 8192 us: 0.00/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 123.70% (2844.99 Mhz) +CPU 2 duty cycles/s: active/idle [< 16 us: 249.47/19.19] [< 32 us: 28.79/0.00] [< 64 us: 19.19/57.57] [< 128 us: 86.36/76.76] [< 256 us: 47.98/67.17] [< 512 us: 19.19/47.98] [< 1024 us: 9.60/38.38] [< 2048 us: 9.60/19.19] [< 4096 us: 9.60/76.76] [< 8192 us: 0.00/38.38] [< 16384 us: 0.00/19.19] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 69.65% (1602.01 Mhz) -CPU 3 duty cycles/s: active/idle [< 16 us: 1190.50/214.68] [< 32 us: 39.03/97.58] [< 64 us: 0.00/322.02] [< 128 us: 9.76/97.58] [< 256 us: 19.52/58.55] [< 512 us: 0.00/87.82] [< 1024 us: 0.00/156.13] [< 2048 us: 0.00/126.86] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/39.03] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 147.30% (3387.89 Mhz) +CPU 3 duty cycles/s: active/idle [< 16 us: 345.42/28.79] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.60] [< 128 us: 0.00/47.98] [< 256 us: 0.00/67.17] [< 512 us: 0.00/28.79] [< 1024 us: 0.00/28.79] [< 2048 us: 0.00/28.79] [< 4096 us: 0.00/28.79] [< 8192 us: 0.00/38.38] [< 16384 us: 0.00/19.19] [< 32768 us: 0.00/19.19] +CPU Average frequency as fraction of nominal: 71.98% (1655.47 Mhz) -Core 2 C-state residency: 69.58% (C3: 0.00% C6: 0.00% C7: 69.58% ) +Core 2 C-state residency: 94.44% (C3: 0.00% C6: 0.00% C7: 94.44% ) -CPU 4 duty cycles/s: active/idle [< 16 us: 497.67/146.37] [< 32 us: 107.34/87.82] [< 64 us: 87.82/97.58] [< 128 us: 68.31/185.41] [< 256 us: 68.31/87.82] [< 512 us: 39.03/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/48.79] [< 4096 us: 9.76/68.31] [< 8192 us: 9.76/48.79] [< 16384 us: 9.76/9.76] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 104.74% (2408.92 Mhz) +CPU 4 duty cycles/s: active/idle [< 16 us: 307.04/95.95] [< 32 us: 19.19/0.00] [< 64 us: 86.36/38.38] [< 128 us: 67.17/86.36] [< 256 us: 38.38/28.79] [< 512 us: 0.00/57.57] [< 1024 us: 19.19/47.98] [< 2048 us: 0.00/38.38] [< 4096 us: 0.00/76.76] [< 8192 us: 0.00/28.79] [< 16384 us: 0.00/28.79] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 82.29% (1892.60 Mhz) -CPU 5 duty cycles/s: active/idle [< 16 us: 975.82/175.65] [< 32 us: 9.76/58.55] [< 64 us: 9.76/107.34] [< 128 us: 0.00/175.65] [< 256 us: 9.76/126.86] [< 512 us: 9.76/68.31] [< 1024 us: 0.00/87.82] [< 2048 us: 0.00/87.82] [< 4096 us: 0.00/68.31] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 147.01% (3381.24 Mhz) +CPU 5 duty cycles/s: active/idle [< 16 us: 383.80/47.98] [< 32 us: 0.00/9.60] [< 64 us: 0.00/47.98] [< 128 us: 9.60/38.38] [< 256 us: 0.00/67.17] [< 512 us: 0.00/38.38] [< 1024 us: 0.00/57.57] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/19.19] [< 8192 us: 0.00/19.19] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/28.79] +CPU Average frequency as fraction of nominal: 67.29% (1547.62 Mhz) -Core 3 C-state residency: 84.42% (C3: 0.00% C6: 0.00% C7: 84.42% ) +Core 3 C-state residency: 94.50% (C3: 4.43% C6: 0.00% C7: 90.07% ) -CPU 6 duty cycles/s: active/idle [< 16 us: 429.36/97.58] [< 32 us: 87.82/9.76] [< 64 us: 58.55/68.31] [< 128 us: 58.55/126.86] [< 256 us: 9.76/97.58] [< 512 us: 39.03/58.55] [< 1024 us: 0.00/68.31] [< 2048 us: 0.00/68.31] [< 4096 us: 0.00/58.55] [< 8192 us: 19.52/29.27] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 143.49% (3300.16 Mhz) +CPU 6 duty cycles/s: active/idle [< 16 us: 211.09/76.76] [< 32 us: 28.79/0.00] [< 64 us: 28.79/19.19] [< 128 us: 28.79/57.57] [< 256 us: 0.00/19.19] [< 512 us: 9.60/28.79] [< 1024 us: 0.00/9.60] [< 2048 us: 0.00/19.19] [< 4096 us: 9.60/19.19] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/28.79] [< 32768 us: 0.00/19.19] +CPU Average frequency as fraction of nominal: 83.87% (1928.94 Mhz) -CPU 7 duty cycles/s: active/idle [< 16 us: 263.47/9.76] [< 32 us: 0.00/19.52] [< 64 us: 9.76/19.52] [< 128 us: 0.00/19.52] [< 256 us: 9.76/39.03] [< 512 us: 9.76/48.79] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/29.27] [< 4096 us: 0.00/9.76] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 152.51% (3507.83 Mhz) +CPU 7 duty cycles/s: active/idle [< 16 us: 201.50/9.60] [< 32 us: 0.00/9.60] [< 64 us: 0.00/28.79] [< 128 us: 0.00/19.19] [< 256 us: 0.00/9.60] [< 512 us: 0.00/19.19] [< 1024 us: 0.00/38.38] [< 2048 us: 0.00/28.79] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.19] +CPU Average frequency as fraction of nominal: 73.89% (1699.37 Mhz) -Core 4 C-state residency: 70.63% (C3: 3.05% C6: 0.00% C7: 67.58% ) +Core 4 C-state residency: 96.82% (C3: 4.16% C6: 0.00% C7: 92.66% ) -CPU 8 duty cycles/s: active/idle [< 16 us: 653.80/243.95] [< 32 us: 263.47/48.79] [< 64 us: 165.89/165.89] [< 128 us: 68.31/146.37] [< 256 us: 29.27/322.02] [< 512 us: 39.03/87.82] [< 1024 us: 19.52/146.37] [< 2048 us: 19.52/48.79] [< 4096 us: 9.76/9.76] [< 8192 us: 0.00/48.79] [< 16384 us: 9.76/0.00] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 148.58% (3417.25 Mhz) +CPU 8 duty cycles/s: active/idle [< 16 us: 124.74/19.19] [< 32 us: 28.79/0.00] [< 64 us: 28.79/9.60] [< 128 us: 47.98/47.98] [< 256 us: 9.60/47.98] [< 512 us: 9.60/28.79] [< 1024 us: 9.60/19.19] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/19.19] [< 16384 us: 0.00/19.19] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 68.30% (1570.93 Mhz) -CPU 9 duty cycles/s: active/idle [< 16 us: 917.27/146.37] [< 32 us: 9.76/78.07] [< 64 us: 9.76/126.86] [< 128 us: 9.76/156.13] [< 256 us: 9.76/78.07] [< 512 us: 0.00/39.03] [< 1024 us: 0.00/136.61] [< 2048 us: 0.00/87.82] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/58.55] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 146.14% (3361.24 Mhz) +CPU 9 duty cycles/s: active/idle [< 16 us: 201.50/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/19.19] [< 128 us: 9.60/38.38] [< 256 us: 0.00/28.79] [< 512 us: 0.00/19.19] [< 1024 us: 0.00/19.19] [< 2048 us: 0.00/19.19] [< 4096 us: 0.00/19.19] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/19.19] +CPU Average frequency as fraction of nominal: 66.92% (1539.26 Mhz) -Core 5 C-state residency: 83.86% (C3: 0.03% C6: 0.00% C7: 83.83% ) +Core 5 C-state residency: 96.16% (C3: 6.97% C6: 0.00% C7: 89.19% ) -CPU 10 duty cycles/s: active/idle [< 16 us: 556.22/107.34] [< 32 us: 19.52/78.07] [< 64 us: 29.27/68.31] [< 128 us: 19.52/146.37] [< 256 us: 9.76/39.03] [< 512 us: 58.55/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/48.79] [< 4096 us: 0.00/68.31] [< 8192 us: 9.76/9.76] [< 16384 us: 0.00/19.52] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 149.83% (3446.04 Mhz) +CPU 10 duty cycles/s: active/idle [< 16 us: 153.52/19.19] [< 32 us: 28.79/0.00] [< 64 us: 0.00/19.19] [< 128 us: 28.79/38.38] [< 256 us: 19.19/38.38] [< 512 us: 9.60/38.38] [< 1024 us: 0.00/28.79] [< 2048 us: 9.60/19.19] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 72.58% (1669.35 Mhz) -CPU 11 duty cycles/s: active/idle [< 16 us: 234.20/19.52] [< 32 us: 19.52/0.00] [< 64 us: 0.00/19.52] [< 128 us: 0.00/58.55] [< 256 us: 0.00/39.03] [< 512 us: 9.76/19.52] [< 1024 us: 0.00/29.27] [< 2048 us: 0.00/19.52] [< 4096 us: 0.00/9.76] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 151.88% (3493.13 Mhz) +CPU 11 duty cycles/s: active/idle [< 16 us: 115.14/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/0.00] [< 128 us: 9.60/28.79] [< 256 us: 0.00/0.00] [< 512 us: 0.00/9.60] [< 1024 us: 0.00/38.38] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/9.60] [< 16384 us: 0.00/9.60] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 83.05% (1910.06 Mhz) -Core 6 C-state residency: 96.23% (C3: 0.00% C6: 0.00% C7: 96.23% ) +Core 6 C-state residency: 97.70% (C3: 0.00% C6: 0.00% C7: 97.70% ) -CPU 12 duty cycles/s: active/idle [< 16 us: 312.26/87.82] [< 32 us: 58.55/0.00] [< 64 us: 29.27/48.79] [< 128 us: 29.27/87.82] [< 256 us: 39.03/19.52] [< 512 us: 9.76/68.31] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/39.03] [< 4096 us: 0.00/48.79] [< 8192 us: 0.00/19.52] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 148.78% (3422.00 Mhz) +CPU 12 duty cycles/s: active/idle [< 16 us: 115.14/9.60] [< 32 us: 0.00/9.60] [< 64 us: 9.60/19.19] [< 128 us: 28.79/9.60] [< 256 us: 0.00/38.38] [< 512 us: 9.60/19.19] [< 1024 us: 9.60/19.19] [< 2048 us: 0.00/28.79] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 83.83% (1928.10 Mhz) -CPU 13 duty cycles/s: active/idle [< 16 us: 341.54/87.82] [< 32 us: 0.00/29.27] [< 64 us: 9.76/9.76] [< 128 us: 0.00/68.31] [< 256 us: 9.76/29.27] [< 512 us: 0.00/0.00] [< 1024 us: 0.00/39.03] [< 2048 us: 0.00/29.27] [< 4096 us: 0.00/19.52] [< 8192 us: 0.00/29.27] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 148.20% (3408.54 Mhz) +CPU 13 duty cycles/s: active/idle [< 16 us: 134.33/0.00] [< 32 us: 0.00/9.60] [< 64 us: 0.00/19.19] [< 128 us: 0.00/19.19] [< 256 us: 0.00/9.60] [< 512 us: 0.00/28.79] [< 1024 us: 0.00/0.00] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 79.00% (1817.01 Mhz) -Core 7 C-state residency: 93.91% (C3: 0.00% C6: 0.00% C7: 93.91% ) +Core 7 C-state residency: 98.22% (C3: 0.00% C6: 0.00% C7: 98.22% ) -CPU 14 duty cycles/s: active/idle [< 16 us: 292.75/136.61] [< 32 us: 29.27/0.00] [< 64 us: 29.27/87.82] [< 128 us: 29.27/48.79] [< 256 us: 39.03/29.27] [< 512 us: 9.76/19.52] [< 1024 us: 0.00/19.52] [< 2048 us: 19.52/29.27] [< 4096 us: 0.00/39.03] [< 8192 us: 0.00/19.52] [< 16384 us: 0.00/9.76] [< 32768 us: 0.00/0.00] -CPU Average frequency as fraction of nominal: 152.37% (3504.58 Mhz) +CPU 14 duty cycles/s: active/idle [< 16 us: 124.74/0.00] [< 32 us: 0.00/0.00] [< 64 us: 9.60/9.60] [< 128 us: 9.60/19.19] [< 256 us: 0.00/19.19] [< 512 us: 0.00/19.19] [< 1024 us: 9.60/19.19] [< 2048 us: 0.00/19.19] [< 4096 us: 0.00/9.60] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/19.19] [< 32768 us: 0.00/0.00] +CPU Average frequency as fraction of nominal: 83.80% (1927.49 Mhz) -CPU 15 duty cycles/s: active/idle [< 16 us: 380.57/78.07] [< 32 us: 9.76/39.03] [< 64 us: 0.00/68.31] [< 128 us: 0.00/87.82] [< 256 us: 19.52/29.27] [< 512 us: 0.00/9.76] [< 1024 us: 0.00/19.52] [< 2048 us: 0.00/19.52] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/39.03] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.76] -CPU Average frequency as fraction of nominal: 152.18% (3500.08 Mhz) +CPU 15 duty cycles/s: active/idle [< 16 us: 124.74/0.00] [< 32 us: 0.00/0.00] [< 64 us: 0.00/9.60] [< 128 us: 0.00/28.79] [< 256 us: 0.00/9.60] [< 512 us: 0.00/28.79] [< 1024 us: 0.00/19.19] [< 2048 us: 0.00/9.60] [< 4096 us: 0.00/0.00] [< 8192 us: 0.00/0.00] [< 16384 us: 0.00/0.00] [< 32768 us: 0.00/9.60] +CPU Average frequency as fraction of nominal: 77.51% (1782.71 Mhz) diff --git a/test/carbon_report.csv b/test/carbon_report.csv index eada118d..b652fcaa 100644 --- a/test/carbon_report.csv +++ b/test/carbon_report.csv @@ -1,9 +1,9 @@ Attribute,Value -timestamp,2024-11-06T15:41:03 +timestamp,2024-11-06T15:51:06 project_name,codecarbon -run_id,7de42608-e864-4267-bcac-db887eedee97 +run_id,427229d2-013a-4e77-8913-69eff642024e experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,4.944858557000089 +duration,4.923058721999951 emissions, emissions_rate, cpu_power, @@ -11,7 +11,7 @@ gpu_power, ram_power,6.0 cpu_energy, gpu_energy, -ram_energy,8.524578333322096e-08 +ram_energy,8.657804333324749e-08 energy_consumed, country_name,Canada country_iso_code,CAN From 4019991b4997e2e46ee401d8292e83180b4b3478 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:52:24 -0500 Subject: [PATCH 019/105] add output folder --- .gitignore | 4 +- src/output/ast.txt | 470 +++++++++++++++++++++++++++++++++++ src/output/ast_lines.txt | 240 ++++++++++++++++++ src/output/carbon_report.csv | 3 + src/output/report.txt | 67 +++++ 5 files changed, 781 insertions(+), 3 deletions(-) create mode 100644 src/output/ast.txt create mode 100644 src/output/ast_lines.txt create mode 100644 src/output/carbon_report.csv create mode 100644 src/output/report.txt diff --git a/.gitignore b/.gitignore index 2a2a6f88..fedc55da 100644 --- a/.gitignore +++ b/.gitignore @@ -293,6 +293,4 @@ __pycache__/ *.py[cod] # Rope -.ropeproject - -output/ \ No newline at end of file +.ropeproject \ No newline at end of file diff --git a/src/output/ast.txt b/src/output/ast.txt new file mode 100644 index 00000000..bbeae637 --- /dev/null +++ b/src/output/ast.txt @@ -0,0 +1,470 @@ +Module( + body=[ + ClassDef( + name='DataProcessor', + body=[ + FunctionDef( + name='__init__', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='data')]), + body=[ + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Store())], + value=Name(id='data', ctx=Load())), + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=List(ctx=Load()))]), + FunctionDef( + name='process_all_data', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Assign( + targets=[ + Name(id='results', ctx=Store())], + value=List(ctx=Load())), + For( + target=Name(id='item', ctx=Store()), + iter=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + body=[ + Try( + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=Call( + func=Attribute( + value=Name(id='self', ctx=Load()), + attr='complex_calculation', + ctx=Load()), + args=[ + Name(id='item', ctx=Load()), + Constant(value=True), + Constant(value=False), + Constant(value='multiply'), + Constant(value=10), + Constant(value=20), + Constant(value=None), + Constant(value='end')])), + Expr( + value=Call( + func=Attribute( + value=Name(id='results', ctx=Load()), + attr='append', + ctx=Load()), + args=[ + Name(id='result', ctx=Load())]))], + handlers=[ + ExceptHandler( + type=Name(id='Exception', ctx=Load()), + name='e', + body=[ + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Constant(value='An error occurred:'), + Name(id='e', ctx=Load())]))])])]), + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Call( + func=Attribute( + value=Call( + func=Attribute( + value=Call( + func=Attribute( + value=Call( + func=Attribute( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + attr='upper', + ctx=Load())), + attr='strip', + ctx=Load())), + attr='replace', + ctx=Load()), + args=[ + Constant(value=' '), + Constant(value='_')]), + attr='lower', + ctx=Load()))])), + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=Call( + func=Name(id='list', ctx=Load()), + args=[ + Call( + func=Name(id='filter', ctx=Load()), + args=[ + Lambda( + args=arguments( + args=[ + arg(arg='x')]), + body=BoolOp( + op=And(), + values=[ + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=None)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=0)]), + Compare( + left=Call( + func=Name(id='len', ctx=Load()), + args=[ + Call( + func=Name(id='str', ctx=Load()), + args=[ + Name(id='x', ctx=Load())])]), + ops=[ + Gt()], + comparators=[ + Constant(value=1)])])), + Name(id='results', ctx=Load())])])), + Return( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Load()))])]), + ClassDef( + name='AdvancedProcessor', + bases=[ + Name(id='DataProcessor', ctx=Load()), + Name(id='object', ctx=Load()), + Name(id='dict', ctx=Load()), + Name(id='list', ctx=Load()), + Name(id='set', ctx=Load()), + Name(id='tuple', ctx=Load())], + body=[ + Pass(), + FunctionDef( + name='check_data', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='item')]), + body=[ + Return( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]), + FunctionDef( + name='complex_comprehension', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=ListComp( + elt=IfExp( + test=Compare( + left=BinOp( + left=Name(id='x', ctx=Load()), + op=Mod(), + right=Constant(value=2)), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=BinOp( + left=Name(id='x', ctx=Load()), + op=Pow(), + right=Constant(value=2)), + orelse=BinOp( + left=Name(id='x', ctx=Load()), + op=Pow(), + right=Constant(value=3))), + generators=[ + comprehension( + target=Name(id='x', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=1), + Constant(value=100)]), + ifs=[ + BoolOp( + op=And(), + values=[ + Compare( + left=BinOp( + left=Name(id='x', ctx=Load()), + op=Mod(), + right=Constant(value=5)), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=50)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=3)])])], + is_async=0)]))]), + FunctionDef( + name='long_chain', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Try( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load())), + Return( + value=Name(id='deep_value', ctx=Load()))], + handlers=[ + ExceptHandler( + type=Name(id='KeyError', ctx=Load()), + body=[ + Return( + value=Constant(value=None))])])]), + FunctionDef( + name='long_scope_chaining', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + For( + target=Name(id='a', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='b', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='c', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='d', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='e', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + If( + test=Compare( + left=BinOp( + left=BinOp( + left=BinOp( + left=BinOp( + left=Name(id='a', ctx=Load()), + op=Add(), + right=Name(id='b', ctx=Load())), + op=Add(), + right=Name(id='c', ctx=Load())), + op=Add(), + right=Name(id='d', ctx=Load())), + op=Add(), + right=Name(id='e', ctx=Load())), + ops=[ + Gt()], + comparators=[ + Constant(value=25)]), + body=[ + Return( + value=Constant(value='Done'))])])])])])])]), + FunctionDef( + name='complex_calculation', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='item'), + arg(arg='flag1'), + arg(arg='flag2'), + arg(arg='operation'), + arg(arg='threshold'), + arg(arg='max_value'), + arg(arg='option'), + arg(arg='final_stage')]), + body=[ + If( + test=Compare( + left=Name(id='operation', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='multiply')]), + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=BinOp( + left=Name(id='item', ctx=Load()), + op=Mult(), + right=Name(id='threshold', ctx=Load())))], + orelse=[ + If( + test=Compare( + left=Name(id='operation', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='add')]), + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=BinOp( + left=Name(id='item', ctx=Load()), + op=Add(), + right=Name(id='max_value', ctx=Load())))], + orelse=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=Name(id='item', ctx=Load()))])]), + Return( + value=Name(id='result', ctx=Load()))])]), + If( + test=Compare( + left=Name(id='__name__', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='__main__')]), + body=[ + Assign( + targets=[ + Name(id='sample_data', ctx=Store())], + value=List( + elts=[ + Constant(value=1), + Constant(value=2), + Constant(value=3), + Constant(value=4), + Constant(value=5)], + ctx=Load())), + Assign( + targets=[ + Name(id='processor', ctx=Store())], + value=Call( + func=Name(id='DataProcessor', ctx=Load()), + args=[ + Name(id='sample_data', ctx=Load())])), + Assign( + targets=[ + Name(id='processed', ctx=Store())], + value=Call( + func=Attribute( + value=Name(id='processor', ctx=Load()), + attr='process_all_data', + ctx=Load()))), + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Constant(value='Processed Data:'), + Name(id='processed', ctx=Load())]))])]) diff --git a/src/output/ast_lines.txt b/src/output/ast_lines.txt new file mode 100644 index 00000000..76343f17 --- /dev/null +++ b/src/output/ast_lines.txt @@ -0,0 +1,240 @@ +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) diff --git a/src/output/carbon_report.csv b/src/output/carbon_report.csv new file mode 100644 index 00000000..fd11fa7f --- /dev/null +++ b/src/output/carbon_report.csv @@ -0,0 +1,3 @@ +timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue +2024-11-06T15:32:34,codecarbon,ab07718b-de1c-496e-91b2-c0ffd4e84ef5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.1535916000138968,2.214386652360756e-08,1.4417368216493612e-07,7.5,0.0,6.730809688568115,3.176875000159877e-07,0,2.429670854124108e-07,5.606545854283984e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 +2024-11-06T15:37:39,codecarbon,515a920a-2566-4af3-92ef-5b930f41ca18,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.15042520000133663,2.1765796594351643e-08,1.4469514811453293e-07,7.5,0.0,6.730809688568115,3.1103791661735157e-07,0,2.400444182185886e-07,5.510823348359402e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 diff --git a/src/output/report.txt b/src/output/report.txt new file mode 100644 index 00000000..a478c274 --- /dev/null +++ b/src/output/report.txt @@ -0,0 +1,67 @@ +[ + [ + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 19, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (85/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 57, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (86/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 74, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + } + ], + { + "C0301": true + } +] From 45788c580c47116f46e37c5a20871bde9ce7d17c Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Wed, 6 Nov 2024 16:00:10 -0500 Subject: [PATCH 020/105] Fixed refactorer classes to include inhertance --- emissions.csv | 20 +++++---- .../complex_list_comprehension_refactorer.py | 5 ++- src/refactorer/large_class_refactorer.py | 2 +- src/refactorer/long_element_chain.py | 6 ++- src/refactorer/long_method_refactorer.py | 4 ++ src/refactorer/long_scope_chaining.py | 9 ++-- test/carbon_report.csv | 42 +++++++++---------- 7 files changed, 49 insertions(+), 39 deletions(-) diff --git a/emissions.csv b/emissions.csv index 95396d62..9f7e1cc5 100644 --- a/emissions.csv +++ b/emissions.csv @@ -1,10 +1,12 @@ timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue -2024-11-06T15:21:23,codecarbon,2ec14d2b-4953-4007-b41d-c7db318b4d4d,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944075577000035,,,,,6.0,,,1.0667413333370253e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:31:43,codecarbon,560d6fac-3aa6-47f5-85ca-0d25d8489762,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.8978115110001,,,,,6.0,,,8.699338333523581e-09,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:33:37,codecarbon,b8f4cef7-225e-4119-89f8-e453b5a9f666,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.9268195259999175,,,,,6.0,,,8.771991000003254e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:35:02,codecarbon,e2d61f7a-9ac9-4089-ae49-c33869d93080,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.936623557999837,,,,,6.0,,,8.79429716667346e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:36:07,codecarbon,532ad45f-7e13-4689-ab66-6292208f6b21,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.927878704000023,,,,,6.0,,,8.450502833322089e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:37:41,codecarbon,d7c396c8-6e78-460a-b888-30e09802ba5b,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944484815000124,,,,,6.0,,,8.56689950001055e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:40:04,codecarbon,cb6477c2-f7d1-4b05-82d2-30c0431852e1,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.977463085000181,,,,,6.0,,,8.772543833363975e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:41:03,codecarbon,7de42608-e864-4267-bcac-db887eedee97,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944858557000089,,,,,6.0,,,8.524578333322096e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:51:06,codecarbon,427229d2-013a-4e77-8913-69eff642024e,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.923058721999951,,,,,6.0,,,8.657804333324749e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:21:23,codecarbon,2ec14d2b-4953-4007-b41d-c7db318b4d4d,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944075577000035,,,,,6.0,,,1.0667413333370253e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:31:43,codecarbon,560d6fac-3aa6-47f5-85ca-0d25d8489762,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.8978115110001,,,,,6.0,,,8.699338333523581e-09,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:33:37,codecarbon,b8f4cef7-225e-4119-89f8-e453b5a9f666,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.9268195259999175,,,,,6.0,,,8.771991000003254e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:35:02,codecarbon,e2d61f7a-9ac9-4089-ae49-c33869d93080,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.936623557999837,,,,,6.0,,,8.79429716667346e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:36:07,codecarbon,532ad45f-7e13-4689-ab66-6292208f6b21,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.927878704000023,,,,,6.0,,,8.450502833322089e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:37:41,codecarbon,d7c396c8-6e78-460a-b888-30e09802ba5b,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944484815000124,,,,,6.0,,,8.56689950001055e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:40:04,codecarbon,cb6477c2-f7d1-4b05-82d2-30c0431852e1,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.977463085000181,,,,,6.0,,,8.772543833363975e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:41:03,codecarbon,7de42608-e864-4267-bcac-db887eedee97,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944858557000089,,,,,6.0,,,8.524578333322096e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:51:06,codecarbon,427229d2-013a-4e77-8913-69eff642024e,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.923058721999951,,,,,6.0,,,8.657804333324749e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 +2024-11-06T15:56:18,codecarbon,4a31d592-4072-4287-b943-bd8a31156004,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.0397282080084551,1.9720773238985865e-08,4.963922167037792e-07,42.5,0.0,3.0,4.667036207845538e-07,0.0,3.2601319156431905e-08,4.993049399409857e-07,Canada,CAN,ontario,,,macOS-15.1-arm64-arm-64bit,3.10.0,2.7.2,8,Apple M2,,,-79.9441,43.266,8.0,machine,N,1.0 +2024-11-06T15:59:19,codecarbon,28e822bb-bf1c-4dd3-8688-29a820e468d5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.038788334000855684,1.9307833465060534e-08,4.977742396627449e-07,42.5,0.0,3.0,4.569394466468819e-07,0.0,3.1910382507097286e-08,4.888498291539792e-07,Canada,CAN,ontario,,,macOS-15.1-arm64-arm-64bit,3.10.0,2.7.2,8,Apple M2,,,-79.9441,43.266,8.0,machine,N,1.0 diff --git a/src/refactorer/complex_list_comprehension_refactorer.py b/src/refactorer/complex_list_comprehension_refactorer.py index b4a96586..7bf924b8 100644 --- a/src/refactorer/complex_list_comprehension_refactorer.py +++ b/src/refactorer/complex_list_comprehension_refactorer.py @@ -1,7 +1,8 @@ import ast import astor +from .base_refactorer import BaseRefactorer -class ComplexListComprehensionRefactorer: +class ComplexListComprehensionRefactorer(BaseRefactorer): """ Refactorer for complex list comprehensions to improve readability. """ @@ -12,7 +13,7 @@ def __init__(self, code: str): :param code: The source code to refactor. """ - self.code = code + super().__init__(code) def refactor(self): """ diff --git a/src/refactorer/large_class_refactorer.py b/src/refactorer/large_class_refactorer.py index aff1f32d..c4af6ba3 100644 --- a/src/refactorer/large_class_refactorer.py +++ b/src/refactorer/large_class_refactorer.py @@ -12,7 +12,7 @@ def __init__(self, code: str, method_threshold: int = 5): :param code: The source code of the class to refactor. :param method_threshold: The number of methods above which a class is considered large. """ - self.code = code + super().__init__(code) self.method_threshold = method_threshold def refactor(self): diff --git a/src/refactorer/long_element_chain.py b/src/refactorer/long_element_chain.py index 4096b4a7..6c168afa 100644 --- a/src/refactorer/long_element_chain.py +++ b/src/refactorer/long_element_chain.py @@ -1,4 +1,6 @@ -class LongElementChainRefactorer: +from .base_refactorer import BaseRefactorer + +class LongElementChainRefactorer(BaseRefactorer): """ Refactorer for data objects (dictionary) that have too many deeply nested elements inside. Ex: deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] @@ -11,7 +13,7 @@ def __init__(self, code: str, element_threshold: int = 5): :param code: The source code of the class to refactor. :param method_threshold: The number of nested elements allowed before dictionary has too many deeply nested elements. """ - self.code = code + super().__init__(code) self.element_threshold = element_threshold def refactor(self): diff --git a/src/refactorer/long_method_refactorer.py b/src/refactorer/long_method_refactorer.py index 459a32e4..734afa67 100644 --- a/src/refactorer/long_method_refactorer.py +++ b/src/refactorer/long_method_refactorer.py @@ -4,6 +4,10 @@ class LongMethodRefactorer(BaseRefactorer): """ Refactorer that targets long methods to improve readability. """ + + def __init__(self, code): + super().__init__(code) + def refactor(self): """ diff --git a/src/refactorer/long_scope_chaining.py b/src/refactorer/long_scope_chaining.py index 727b0f7b..39e53316 100644 --- a/src/refactorer/long_scope_chaining.py +++ b/src/refactorer/long_scope_chaining.py @@ -1,8 +1,9 @@ -class LongScopeRefactorer: +from .base_refactorer import BaseRefactorer + +class LongScopeRefactorer(BaseRefactorer): """ Refactorer for methods that have too many deeply nested loops. - """ - + """ def __init__(self, code: str, loop_threshold: int = 5): """ Initializes the refactorer. @@ -10,7 +11,7 @@ def __init__(self, code: str, loop_threshold: int = 5): :param code: The source code of the class to refactor. :param method_threshold: The number of loops allowed before method is considered one with too many nested loops. """ - self.code = code + super().__init__(code) self.loop_threshold = loop_threshold def refactor(self): diff --git a/test/carbon_report.csv b/test/carbon_report.csv index b652fcaa..f8912394 100644 --- a/test/carbon_report.csv +++ b/test/carbon_report.csv @@ -1,33 +1,33 @@ Attribute,Value -timestamp,2024-11-06T15:51:06 +timestamp,2024-11-06T15:59:19 project_name,codecarbon -run_id,427229d2-013a-4e77-8913-69eff642024e +run_id,28e822bb-bf1c-4dd3-8688-29a820e468d5 experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,4.923058721999951 -emissions, -emissions_rate, -cpu_power, -gpu_power, -ram_power,6.0 -cpu_energy, -gpu_energy, -ram_energy,8.657804333324749e-08 -energy_consumed, +duration,0.038788334000855684 +emissions,1.9307833465060534e-08 +emissions_rate,4.977742396627449e-07 +cpu_power,42.5 +gpu_power,0.0 +ram_power,3.0 +cpu_energy,4.569394466468819e-07 +gpu_energy,0 +ram_energy,3.1910382507097286e-08 +energy_consumed,4.888498291539792e-07 country_name,Canada country_iso_code,CAN region,ontario cloud_provider, cloud_region, -os,macOS-14.4-x86_64-i386-64bit -python_version,3.10.10 +os,macOS-15.1-arm64-arm-64bit +python_version,3.10.0 codecarbon_version,2.7.2 -cpu_count,16 -cpu_model,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz -gpu_count,1 -gpu_model,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz -longitude,-79.7172 -latitude,43.5639 -ram_total_size,16.0 +cpu_count,8 +cpu_model,Apple M2 +gpu_count, +gpu_model, +longitude,-79.9441 +latitude,43.266 +ram_total_size,8.0 tracking_mode,machine on_cloud,N pue,1.0 From e05b3d5e9649f7ee7639b140ea7f2eb5468c0acc Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Wed, 6 Nov 2024 16:00:31 -0500 Subject: [PATCH 021/105] added custom energy measure logic for apple silicon chips(other platforms pending) --- src/measurement/custom_energy_measure.py | 62 ++++++++++++++++++++++++ src/measurement/measurement_utils.py | 41 ++++++++++++++++ test/high_energy_code_example.py | 22 +++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/measurement/custom_energy_measure.py create mode 100644 test/high_energy_code_example.py diff --git a/src/measurement/custom_energy_measure.py b/src/measurement/custom_energy_measure.py new file mode 100644 index 00000000..212fcd2f --- /dev/null +++ b/src/measurement/custom_energy_measure.py @@ -0,0 +1,62 @@ +import resource + +from measurement_utils import (start_process, calculate_ram_power, + start_pm_process, stop_pm_process, get_cpu_power_from_pm_logs) +import time + + +class CustomEnergyMeasure: + """ + Handles custom CPU and RAM energy measurements for executing a Python script. + Currently only works for Apple Silicon Chips with sudo access(password prompt in terminal) + Next step includes device detection for calculating on multiple platforms + """ + + def __init__(self, script_path: str): + self.script_path = script_path + self.results = {"cpu": 0.0, "ram": 0.0} + self.code_process_time = 0 + + def measure_cpu_power(self): + # start powermetrics as a child process + powermetrics_process = start_pm_process() + # allow time to enter password for sudo rights in mac + time.sleep(5) + try: + start_time = time.time() + # execute the provided code as another child process and wait to finish + code_process = start_process(["python3", self.script_path]) + code_process_pid = code_process.pid + code_process.wait() + end_time = time.time() + self.code_process_time = end_time - start_time + # Parse powermetrics log to extract CPU power data for this PID + finally: + stop_pm_process(powermetrics_process) + self.results["cpu"] = get_cpu_power_from_pm_logs("custom_energy_output.txt", code_process_pid) + + def measure_ram_power(self): + # execute provided code as a child process, this time without simultaneous powermetrics process + # code needs to rerun to use resource.getrusage() for a single child + # might look into another library that does not require this + code_process = start_process(["python3", self.script_path]) + code_process.wait() + + # get peak memory usage in bytes for this process + peak_memory_b = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss + + # calculate RAM power based on peak memory(3W/8GB ratio) + self.results["ram"] = calculate_ram_power(peak_memory_b) + + def calculate_energy_from_power(self): + # Return total energy consumed + total_power = self.results["cpu"] + self.results["ram"] # in watts + return total_power * self.code_process_time + + +if __name__ == "__main__": + custom_measure = CustomEnergyMeasure("/capstone--source-code-optimizer/test/high_energy_code_example.py") + custom_measure.measure_cpu_power() + custom_measure.measure_ram_power() + #can be saved as a report later + print(custom_measure.calculate_energy_from_power()) diff --git a/src/measurement/measurement_utils.py b/src/measurement/measurement_utils.py index e69de29b..292698c9 100644 --- a/src/measurement/measurement_utils.py +++ b/src/measurement/measurement_utils.py @@ -0,0 +1,41 @@ +import resource +import subprocess +import time +import re + + +def start_process(command): + return subprocess.Popen(command) + +def calculate_ram_power(memory_b): + memory_gb = memory_b / (1024 ** 3) + return memory_gb * 3 / 8 # 3W/8GB ratio + + +def start_pm_process(log_path="custom_energy_output.txt"): + powermetrics_process = subprocess.Popen( + ["sudo", "powermetrics", "--samplers", "tasks,cpu_power", "--show-process-gpu", "-i", "5000"], + stdout=open(log_path, "w"), + stderr=subprocess.PIPE + ) + return powermetrics_process + + +def stop_pm_process(powermetrics_process): + powermetrics_process.terminate() + +def get_cpu_power_from_pm_logs(log_path, pid): + cpu_share, total_cpu_power = None, None # in ms/s and mW respectively + with open(log_path, 'r') as file: + lines = file.readlines() + for line in lines: + if str(pid) in line: + cpu_share = float(line.split()[2]) + elif "CPU Power:" in line: + total_cpu_power = float(line.split()[2]) + if cpu_share and total_cpu_power: + break + if cpu_share and total_cpu_power: + cpu_power = (cpu_share / 1000) * (total_cpu_power / 1000) + return cpu_power + return None diff --git a/test/high_energy_code_example.py b/test/high_energy_code_example.py new file mode 100644 index 00000000..04cc9573 --- /dev/null +++ b/test/high_energy_code_example.py @@ -0,0 +1,22 @@ +import numpy as np +import time + + +def heavy_computation(): + # Start a large matrix multiplication task to consume CPU + print("Starting heavy computation...") + size = 1000 + matrix_a = np.random.rand(size, size) + matrix_b = np.random.rand(size, size) + + start_time = time.time() + result = np.dot(matrix_a, matrix_b) + end_time = time.time() + + print(f"Heavy computation finished in {end_time - start_time:.2f} seconds") + + +# Run the heavy computation in a loop for a longer duration +for _ in range(5): + heavy_computation() + time.sleep(1) # Add a small delay to observe periodic CPU load From 561b88fc54b481237f84447ef0d7cfc3e8be029c Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:12:45 -0500 Subject: [PATCH 022/105] allow run from main --- emissions.csv | 12 ---------- src/main.py | 14 +++++++---- src/measurement/code_carbon_meter.py | 6 ++--- src/output/initial_carbon_report.csv | 33 ++++++++++++++++++++++++++ src/refactorer/long_base_class_list.py | 14 +++++++++++ 5 files changed, 60 insertions(+), 19 deletions(-) delete mode 100644 emissions.csv create mode 100644 src/output/initial_carbon_report.csv create mode 100644 src/refactorer/long_base_class_list.py diff --git a/emissions.csv b/emissions.csv deleted file mode 100644 index 9f7e1cc5..00000000 --- a/emissions.csv +++ /dev/null @@ -1,12 +0,0 @@ -timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue -2024-11-06T15:21:23,codecarbon,2ec14d2b-4953-4007-b41d-c7db318b4d4d,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944075577000035,,,,,6.0,,,1.0667413333370253e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:31:43,codecarbon,560d6fac-3aa6-47f5-85ca-0d25d8489762,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.8978115110001,,,,,6.0,,,8.699338333523581e-09,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:33:37,codecarbon,b8f4cef7-225e-4119-89f8-e453b5a9f666,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.9268195259999175,,,,,6.0,,,8.771991000003254e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:35:02,codecarbon,e2d61f7a-9ac9-4089-ae49-c33869d93080,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.936623557999837,,,,,6.0,,,8.79429716667346e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:36:07,codecarbon,532ad45f-7e13-4689-ab66-6292208f6b21,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.927878704000023,,,,,6.0,,,8.450502833322089e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:37:41,codecarbon,d7c396c8-6e78-460a-b888-30e09802ba5b,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944484815000124,,,,,6.0,,,8.56689950001055e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:40:04,codecarbon,cb6477c2-f7d1-4b05-82d2-30c0431852e1,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.977463085000181,,,,,6.0,,,8.772543833363975e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:41:03,codecarbon,7de42608-e864-4267-bcac-db887eedee97,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.944858557000089,,,,,6.0,,,8.524578333322096e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:51:06,codecarbon,427229d2-013a-4e77-8913-69eff642024e,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,4.923058721999951,,,,,6.0,,,8.657804333324749e-08,,Canada,CAN,ontario,,,macOS-14.4-x86_64-i386-64bit,3.10.10,2.7.2,16,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,1.0,Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz,-79.7172,43.5639,16.0,machine,N,1.0 -2024-11-06T15:56:18,codecarbon,4a31d592-4072-4287-b943-bd8a31156004,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.0397282080084551,1.9720773238985865e-08,4.963922167037792e-07,42.5,0.0,3.0,4.667036207845538e-07,0.0,3.2601319156431905e-08,4.993049399409857e-07,Canada,CAN,ontario,,,macOS-15.1-arm64-arm-64bit,3.10.0,2.7.2,8,Apple M2,,,-79.9441,43.266,8.0,machine,N,1.0 -2024-11-06T15:59:19,codecarbon,28e822bb-bf1c-4dd3-8688-29a820e468d5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.038788334000855684,1.9307833465060534e-08,4.977742396627449e-07,42.5,0.0,3.0,4.569394466468819e-07,0.0,3.1910382507097286e-08,4.888498291539792e-07,Canada,CAN,ontario,,,macOS-15.1-arm64-arm-64bit,3.10.0,2.7.2,8,Apple M2,,,-79.9441,43.266,8.0,machine,N,1.0 diff --git a/src/main.py b/src/main.py index 94c5ca2c..c3696a46 100644 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,7 @@ import os from analyzers.pylint_analyzer import PylintAnalyzer +from measurement.code_carbon_meter import CarbonAnalyzer from utils.factory import RefactorerFactory from utils.code_smells import CodeSmells from utils import ast_parser @@ -16,9 +17,14 @@ def main(): """ # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug - FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") + TEST_FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") + INITIAL_REPORT_FILE_PATH = os.path.join(dirname, "output/initial_carbon_report.csv") + + carbon_analyzer = CarbonAnalyzer(TEST_FILE_PATH) + carbon_analyzer.run_and_measure() + carbon_analyzer.save_report(INITIAL_REPORT_FILE_PATH) - analyzer = PylintAnalyzer(FILE_PATH) + analyzer = PylintAnalyzer(TEST_FILE_PATH) report = analyzer.analyze() filtered_report = analyzer.filter_for_all_wanted_code_smells(report["messages"]) @@ -29,7 +35,7 @@ def main(): smell_id = smell["messageId"] if smell_id == CodeSmells.LINE_TOO_LONG.value: - root_node = ast_parser.parse_line(FILE_PATH, smell["line"]) + root_node = ast_parser.parse_line(TEST_FILE_PATH, smell["line"]) if root_node is None: continue @@ -43,7 +49,7 @@ def main(): # smell_id = CodeSmells.LONG_TERN_EXPR print("Refactoring ", smell_id) - refactoring_class = RefactorerFactory.build(smell_id, FILE_PATH) + refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE_PATH) refactoring_class.refactor() diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py index dde111ad..a60ed932 100644 --- a/src/measurement/code_carbon_meter.py +++ b/src/measurement/code_carbon_meter.py @@ -11,7 +11,7 @@ class CarbonAnalyzer: def __init__(self, script_path: str): self.script_path = script_path - self.tracker = EmissionsTracker(allow_multiple_runs=True) + self.tracker = EmissionsTracker(save_to_file=False, allow_multiple_runs=True) def run_and_measure(self): script = Path(self.script_path) @@ -55,6 +55,6 @@ def save_report(self, report_path: str): # Example usage if __name__ == "__main__": - analyzer = CarbonAnalyzer("test/inefficent_code_example.py") + analyzer = CarbonAnalyzer("src/output/inefficent_code_example.py") analyzer.run_and_measure() - analyzer.save_report("test/carbon_report.csv") + analyzer.save_report("src/output/test/carbon_report.csv") diff --git a/src/output/initial_carbon_report.csv b/src/output/initial_carbon_report.csv new file mode 100644 index 00000000..7f3c8538 --- /dev/null +++ b/src/output/initial_carbon_report.csv @@ -0,0 +1,33 @@ +Attribute,Value +timestamp,2024-11-06T16:12:15 +project_name,codecarbon +run_id,17675603-c8ac-45c4-ae28-5b9fafa264d2 +experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 +duration,0.1571239999611862 +emissions,2.2439585954258806e-08 +emissions_rate,1.4281450293909256e-07 +cpu_power,7.5 +gpu_power,0.0 +ram_power,6.730809688568115 +cpu_energy,3.2567562496600047e-07 +gpu_energy,0 +ram_energy,2.4246620098645654e-07 +energy_consumed,5.68141825952457e-07 +country_name,Canada +country_iso_code,CAN +region,ontario +cloud_provider, +cloud_region, +os,Windows-11-10.0.22631-SP0 +python_version,3.13.0 +codecarbon_version,2.7.2 +cpu_count,8 +cpu_model,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx +gpu_count, +gpu_model, +longitude,-79.9441 +latitude,43.266 +ram_total_size,17.94882583618164 +tracking_mode,machine +on_cloud,N +pue,1.0 diff --git a/src/refactorer/long_base_class_list.py b/src/refactorer/long_base_class_list.py new file mode 100644 index 00000000..fdd15297 --- /dev/null +++ b/src/refactorer/long_base_class_list.py @@ -0,0 +1,14 @@ +from .base_refactorer import BaseRefactorer + +class LongBaseClassListRefactorer(BaseRefactorer): + """ + Refactorer that targets long base class lists to improve performance. + """ + + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass From 495d453be65af2356db1c65a5afeea2e6641be83 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:21:00 -0500 Subject: [PATCH 023/105] Revised POC - started adding base structure --- src1/analyzers/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src1/analyzers/__init__.py diff --git a/src1/analyzers/__init__.py b/src1/analyzers/__init__.py new file mode 100644 index 00000000..e69de29b From 65fb622e8ab7d3c373d2c858ab0debec2d3b5141 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:22:13 -0500 Subject: [PATCH 024/105] Revised POC - Added base_analyzer.py --- src1/analyzers/base_analyzer.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src1/analyzers/base_analyzer.py diff --git a/src1/analyzers/base_analyzer.py b/src1/analyzers/base_analyzer.py new file mode 100644 index 00000000..c2f9f199 --- /dev/null +++ b/src1/analyzers/base_analyzer.py @@ -0,0 +1,36 @@ +import os + +class Analyzer: + """ + Base class for different types of analyzers. + """ + def __init__(self, file_path): + """ + Initializes the analyzer with a file path. + + :param file_path: Path to the file to be analyzed. + """ + self.file_path = file_path + self.report_data = [] + + def validate_file(self): + """ + Checks if the file path exists and is a file. + + :return: Boolean indicating file validity. + """ + return os.path.isfile(self.file_path) + + def analyze(self): + """ + Abstract method to be implemented by subclasses to perform analysis. + """ + raise NotImplementedError("Subclasses must implement this method.") + + def get_all_detected_smells(self): + """ + Retrieves all detected smells from the report data. + + :return: List of all detected code smells. + """ + return self.report_data From df6bff52bbd5c7653b359026702b21dc696deb57 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:24:35 -0500 Subject: [PATCH 025/105] Revised POC - Added pylint_analyzer.py + utils folder with configuration --- src1/analyzers/pylint_analyzer.py | 69 +++++++++++++++++++++++++++++++ src1/utils/__init__.py | 0 src1/utils/analyzers_config.py | 25 +++++++++++ 3 files changed, 94 insertions(+) create mode 100644 src1/analyzers/pylint_analyzer.py create mode 100644 src1/utils/__init__.py create mode 100644 src1/utils/analyzers_config.py diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py new file mode 100644 index 00000000..2f4eef49 --- /dev/null +++ b/src1/analyzers/pylint_analyzer.py @@ -0,0 +1,69 @@ +import json +from pylint.lint import Run +from pylint.reporters.json_reporter import JSONReporter +from io import StringIO +from .base_analyzer import Analyzer +from utils.analyzers_config import PylintSmell, EXTRA_PYLINT_OPTIONS + +class PylintAnalyzer(Analyzer): + def __init__(self, file_path): + super().__init__(file_path) + + def build_pylint_options(self): + """ + Constructs the list of pylint options for analysis, including extra options from config. + + :return: List of pylint options for analysis. + """ + return [self.file_path] + EXTRA_PYLINT_OPTIONS + + def analyze(self): + """ + Executes pylint on the specified file and captures the output in JSON format. + """ + if not self.validate_file(): + print(f"File not found: {self.file_path}") + return + + print(f"Running pylint analysis on {self.file_path}") + + # Capture pylint output in a JSON format buffer + with StringIO() as buffer: + reporter = JSONReporter(buffer) + pylint_options = self.build_pylint_options() + + try: + # Run pylint with JSONReporter + Run(pylint_options, reporter=reporter, exit=False) + + # Parse the JSON output + buffer.seek(0) + self.report_data = json.loads(buffer.getvalue()) + print("Pylint JSON analysis completed.") + except json.JSONDecodeError as e: + print("Failed to parse JSON output from pylint:", e) + except Exception as e: + print("An error occurred during pylint analysis:", e) + + def get_smells_by_name(self, smell): + """ + Retrieves smells based on the Smell enum (e.g., Smell.LINE_TOO_LONG). + + :param smell: The Smell enum member to filter by. + :return: List of report entries matching the smell name. + """ + return [ + item for item in self.report_data + if item.get("message-id") == smell.value + ] + + def get_configured_smells(self): + """ + Filters the report data to retrieve only the smells with message IDs specified in the config. + + :return: List of detected code smells based on the configuration. + """ + configured_smells = [] + for smell in PylintSmell: + configured_smells.extend(self.get_smells_by_name(smell)) + return configured_smells diff --git a/src1/utils/__init__.py b/src1/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py new file mode 100644 index 00000000..81313301 --- /dev/null +++ b/src1/utils/analyzers_config.py @@ -0,0 +1,25 @@ +# Any configurations that are done by the analyzers + +from enum import Enum + +class PylintSmell(Enum): + LINE_TOO_LONG = "C0301" # pylint smell + LONG_MESSAGE_CHAIN = "R0914" # pylint smell + LARGE_CLASS = "R0902" # pylint smell + LONG_PARAMETER_LIST = "R0913" # pylint smell + LONG_METHOD = "R0915" # pylint smell + COMPLEX_LIST_COMPREHENSION = "C0200" # pylint smell + INVALID_NAMING_CONVENTIONS = "C0103" # pylint smell + +class CustomSmell(Enum): + LONG_TERN_EXPR = "CUST-1" # custom smell + +AllSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, **{s.name: s.value for s in CustomSmell}}) + +# Extra pylint options +EXTRA_PYLINT_OPTIONS = [ + "--max-line-length=80", + "--max-nested-blocks=3", + "--max-branches=3", + "--max-parents=3" +] From 2b7cad19d3562932f433609bc9634eb964574abf Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:25:46 -0500 Subject: [PATCH 026/105] Revised POC - Added ternary_expression_analyzer.py --- src1/analyzers/ternary_expression_analyzer.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src1/analyzers/ternary_expression_analyzer.py diff --git a/src1/analyzers/ternary_expression_analyzer.py b/src1/analyzers/ternary_expression_analyzer.py new file mode 100644 index 00000000..a341dc52 --- /dev/null +++ b/src1/analyzers/ternary_expression_analyzer.py @@ -0,0 +1,69 @@ +# FULLY CHATGPT - I only wanted to add this in so we have an idea how to detect smells pylint can't + +import ast +from .base_analyzer import Analyzer + +class TernaryExpressionAnalyzer(Analyzer): + def __init__(self, file_path, max_length=50): + super().__init__(file_path) + self.max_length = max_length + + def analyze(self): + """ + Reads the file and analyzes it to detect long ternary expressions. + """ + if not self.validate_file(): + print(f"File not found: {self.file_path}") + return + + print(f"Running ternary expression analysis on {self.file_path}") + + try: + code = self.read_code_from_file() + self.report_data = self.detect_long_ternary_expressions(code) + print("Ternary expression analysis completed.") + except FileNotFoundError: + print(f"File not found: {self.file_path}") + except IOError as e: + print(f"Error reading file {self.file_path}: {e}") + + def read_code_from_file(self): + """ + Reads and returns the code from the specified file path. + + :return: Source code as a string. + """ + with open(self.file_path, "r") as file: + return file.read() + + def detect_long_ternary_expressions(self, code): + """ + Detects ternary expressions in the code that exceed the specified max_length. + + :param code: The source code to analyze. + :return: List of detected long ternary expressions with line numbers and expression length. + """ + tree = ast.parse(code) + long_expressions = [] + + for node in ast.walk(tree): + if isinstance(node, ast.IfExp): # Ternary expression node + expression_source = ast.get_source_segment(code, node) + expression_length = len(expression_source) if expression_source else 0 + if expression_length > self.max_length: + long_expressions.append({ + "line": node.lineno, + "length": expression_length, + "expression": expression_source + }) + + return long_expressions + + def filter_expressions_by_length(self, min_length): + """ + Filters the report data to retrieve only the expressions exceeding a specified length. + + :param min_length: Minimum length of expressions to filter by. + :return: List of detected ternary expressions matching the specified length criteria. + """ + return [expr for expr in self.report_data if expr["length"] >= min_length] From 64222cef6bc952c0e714942b9ea283158b11b0f3 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:26:20 -0500 Subject: [PATCH 027/105] Revised POC - Added main.py for analyzer package --- src1/analyzers/main.py | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src1/analyzers/main.py diff --git a/src1/analyzers/main.py b/src1/analyzers/main.py new file mode 100644 index 00000000..d42e5b07 --- /dev/null +++ b/src1/analyzers/main.py @@ -0,0 +1,97 @@ +""" +A simple main.py to demonstrate the usage of various functions in the analyzer classes. +This script runs different analyzers and outputs results as JSON files in the `main_output` +folder. This helps to understand how the analyzers work and allows viewing the details of +detected code smells and configured refactorable smells. + +Each output JSON file provides insight into the raw data returned by PyLint and custom analyzers, +which is useful for debugging and verifying functionality. Note: In the final implementation, +we may not output these JSON files, but they are useful for demonstration purposes. + +INSTRUCTIONS TO RUN THIS FILE: +1. Change directory to the `src` folder: cd src +2. Run the script using the following command: python -m analyzers.main +3. Optional: Specify a test file path (absolute path) as an argument to override the default test case +(`inefficient_code_example_1.py`). For example: python -m analyzers.main +""" + +import os +import json +import sys +from analyzers.pylint_analyzer import PylintAnalyzer +from analyzers.ternary_expression_analyzer import TernaryExpressionAnalyzer +from utils.analyzers_config import AllSmells + +# Define the output folder within the analyzers package +OUTPUT_FOLDER = os.path.join(os.path.dirname(__file__), 'code_smells') + +# Ensure the output folder exists +os.makedirs(OUTPUT_FOLDER, exist_ok=True) + +def save_to_file(data, filename): + """ + Saves JSON data to a file in the output folder. + + :param data: Data to be saved. + :param filename: Name of the file to save data to. + """ + filepath = os.path.join(OUTPUT_FOLDER, filename) + with open(filepath, 'w') as file: + json.dump(data, file, sort_keys=True, indent=4) + print(f"Output saved to {filepath}") + +def run_pylint_analysis(file_path): + print("\nStarting pylint analysis...") + + # Create an instance of PylintAnalyzer and run analysis + pylint_analyzer = PylintAnalyzer(file_path) + pylint_analyzer.analyze() + + # Save all detected smells to file + all_smells = pylint_analyzer.get_all_detected_smells() + save_to_file(all_smells, 'pylint_all_smells.json') + + # Example: Save only configured smells to file + configured_smells = pylint_analyzer.get_configured_smells() + save_to_file(configured_smells, 'pylint_configured_smells.json') + + # Example: Save smells specific to "LINE_TOO_LONG" + line_too_long_smells = pylint_analyzer.get_smells_by_name(AllSmells.LINE_TOO_LONG) + save_to_file(line_too_long_smells, 'pylint_line_too_long_smells.json') + + +def run_ternary_expression_analysis(file_path, max_length=50): + print("\nStarting ternary expression analysis...") + + # Create an instance of TernaryExpressionAnalyzer and run analysis + ternary_analyzer = TernaryExpressionAnalyzer(file_path, max_length) + ternary_analyzer.analyze() + + # Save all long ternary expressions to file + long_expressions = ternary_analyzer.get_all_detected_smells() + save_to_file(long_expressions, 'ternary_long_expressions.json') + + # Example: Save filtered expressions based on a custom length threshold + min_length = 70 + filtered_expressions = ternary_analyzer.filter_expressions_by_length(min_length) + save_to_file(filtered_expressions, f'ternary_expressions_min_length_{min_length}.json') + + +def main(): + # Get the file path from command-line arguments if provided, otherwise use the default + default_test_file = os.path.join(os.path.dirname(__file__), "../../src1-tests/ineffcient_code_example_1.py") + test_file = sys.argv[1] if len(sys.argv) > 1 else default_test_file + + # Check if the file exists + if not os.path.isfile(test_file): + print(f"Error: The file '{test_file}' does not exist.") + return + + # Run examples of PylintAnalyzer usage + run_pylint_analysis(test_file) + + # Run examples of TernaryExpressionAnalyzer usage + run_ternary_expression_analysis(test_file, max_length=50) + +if __name__ == "__main__": + main() From 6d062005cde5698d5924f2a81e265b7769c272d1 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:27:27 -0500 Subject: [PATCH 028/105] Revised POC - Added tests folder for src1 --- src1-tests/ineffcient_code_example_1.py | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src1-tests/ineffcient_code_example_1.py diff --git a/src1-tests/ineffcient_code_example_1.py b/src1-tests/ineffcient_code_example_1.py new file mode 100644 index 00000000..afc6a6bd --- /dev/null +++ b/src1-tests/ineffcient_code_example_1.py @@ -0,0 +1,82 @@ +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] + + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except Exception as e: # UEH: Unqualified Exception Handling + print("An error occurred:", e) + + # LMC: Long Message Chain + if isinstance(self.data[0], str): + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) + ) + + return self.processed_data + + # Moved the complex_calculation method here + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result + + +class AdvancedProcessor(DataProcessor): + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return True if item > 10 else False if item < -10 else None if item == 0 else item + + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except (KeyError, IndexError, TypeError): + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) From 92c2754f8d6f737e113f45df69b95a95cd3ac230 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Thu, 7 Nov 2024 04:29:01 -0500 Subject: [PATCH 029/105] Revised POC - Ran analyzer.main and created output files --- .../code_smells/pylint_all_smells.json | 301 ++++++++++++++++++ .../code_smells/pylint_configured_smells.json | 67 ++++ .../pylint_line_too_long_smells.json | 54 ++++ .../ternary_expressions_min_length_70.json | 7 + .../code_smells/ternary_long_expressions.json | 12 + 5 files changed, 441 insertions(+) create mode 100644 src1/analyzers/code_smells/pylint_all_smells.json create mode 100644 src1/analyzers/code_smells/pylint_configured_smells.json create mode 100644 src1/analyzers/code_smells/pylint_line_too_long_smells.json create mode 100644 src1/analyzers/code_smells/ternary_expressions_min_length_70.json create mode 100644 src1/analyzers/code_smells/ternary_long_expressions.json diff --git a/src1/analyzers/code_smells/pylint_all_smells.json b/src1/analyzers/code_smells/pylint_all_smells.json new file mode 100644 index 00000000..56fdd87b --- /dev/null +++ b/src1/analyzers/code_smells/pylint_all_smells.json @@ -0,0 +1,301 @@ +[ + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 26, + "message": "Line too long (83/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 33, + "message": "Line too long (86/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 47, + "message": "Line too long (90/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 61, + "message": "Line too long (85/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 1, + "message": "Missing module docstring", + "message-id": "C0114", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-module-docstring", + "type": "convention" + }, + { + "column": 0, + "endColumn": 19, + "endLine": 2, + "line": 2, + "message": "Missing class docstring", + "message-id": "C0115", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 24, + "endLine": 8, + "line": 8, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.process_all_data", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 19, + "endColumn": 28, + "endLine": 17, + "line": 17, + "message": "Catching too general exception Exception", + "message-id": "W0718", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.process_all_data", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "broad-exception-caught", + "type": "warning" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 32, + "line": 32, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 32, + "line": 32, + "message": "Too many arguments (9/5)", + "message-id": "R0913", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 32, + "line": 32, + "message": "Too many positional arguments (9/5)", + "message-id": "R0917", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "too-many-positional-arguments", + "type": "refactor" + }, + { + "column": 20, + "endColumn": 25, + "endLine": 33, + "line": 33, + "message": "Unused argument 'flag1'", + "message-id": "W0613", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 27, + "endColumn": 32, + "endLine": 33, + "line": 33, + "message": "Unused argument 'flag2'", + "message-id": "W0613", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 67, + "endColumn": 73, + "endLine": 33, + "line": 33, + "message": "Unused argument 'option'", + "message-id": "W0613", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 75, + "endColumn": 86, + "endLine": 33, + "line": 33, + "message": "Unused argument 'final_stage'", + "message-id": "W0613", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 0, + "endColumn": 23, + "endLine": 44, + "line": 44, + "message": "Missing class docstring", + "message-id": "C0115", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 46, + "line": 46, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.check_data", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 29, + "endLine": 50, + "line": 50, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.complex_comprehension", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 59, + "line": 59, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.long_chain", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 67, + "line": 67, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 67, + "line": 67, + "message": "Too many branches (6/3)", + "message-id": "R0912", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "too-many-branches", + "type": "refactor" + }, + { + "column": 8, + "endColumn": 45, + "endLine": 74, + "line": 68, + "message": "Too many nested blocks (6/3)", + "message-id": "R1702", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "too-many-nested-blocks", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 67, + "line": 67, + "message": "Either all return statements in a function should return an expression, or none of them should.", + "message-id": "R1710", + "module": "ineffcient_code_example_1", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "inconsistent-return-statements", + "type": "refactor" + } +] \ No newline at end of file diff --git a/src1/analyzers/code_smells/pylint_configured_smells.json b/src1/analyzers/code_smells/pylint_configured_smells.json new file mode 100644 index 00000000..baf46488 --- /dev/null +++ b/src1/analyzers/code_smells/pylint_configured_smells.json @@ -0,0 +1,67 @@ +[ + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 26, + "message": "Line too long (83/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 33, + "message": "Line too long (86/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 47, + "message": "Line too long (90/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 61, + "message": "Line too long (85/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 32, + "line": 32, + "message": "Too many arguments (9/5)", + "message-id": "R0913", + "module": "ineffcient_code_example_1", + "obj": "DataProcessor.complex_calculation", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "too-many-arguments", + "type": "refactor" + } +] \ No newline at end of file diff --git a/src1/analyzers/code_smells/pylint_line_too_long_smells.json b/src1/analyzers/code_smells/pylint_line_too_long_smells.json new file mode 100644 index 00000000..ec3fbe04 --- /dev/null +++ b/src1/analyzers/code_smells/pylint_line_too_long_smells.json @@ -0,0 +1,54 @@ +[ + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 26, + "message": "Line too long (83/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 33, + "message": "Line too long (86/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 47, + "message": "Line too long (90/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 61, + "message": "Line too long (85/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_1", + "obj": "", + "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "line-too-long", + "type": "convention" + } +] \ No newline at end of file diff --git a/src1/analyzers/code_smells/ternary_expressions_min_length_70.json b/src1/analyzers/code_smells/ternary_expressions_min_length_70.json new file mode 100644 index 00000000..69eb4f43 --- /dev/null +++ b/src1/analyzers/code_smells/ternary_expressions_min_length_70.json @@ -0,0 +1,7 @@ +[ + { + "expression": "True if item > 10 else False if item < -10 else None if item == 0 else item", + "length": 75, + "line": 47 + } +] \ No newline at end of file diff --git a/src1/analyzers/code_smells/ternary_long_expressions.json b/src1/analyzers/code_smells/ternary_long_expressions.json new file mode 100644 index 00000000..80bd2eda --- /dev/null +++ b/src1/analyzers/code_smells/ternary_long_expressions.json @@ -0,0 +1,12 @@ +[ + { + "expression": "True if item > 10 else False if item < -10 else None if item == 0 else item", + "length": 75, + "line": 47 + }, + { + "expression": "False if item < -10 else None if item == 0 else item", + "length": 52, + "line": 47 + } +] \ No newline at end of file From 7cc27a68a36005b5cb3074356e321f33e9c1a5f9 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:59:46 -0500 Subject: [PATCH 030/105] created detection for long ternary expressions --- src-combined/README.md | 5 + src-combined/__init__.py | 5 + src-combined/analyzers/__init__.py | 0 src-combined/analyzers/base_analyzer.py | 11 + src-combined/analyzers/pylint_analyzer.py | 127 +++++ src-combined/analyzers/ruff_analyzer.py | 104 ++++ src-combined/main.py | 38 ++ src-combined/measurement/__init__.py | 0 src-combined/measurement/code_carbon_meter.py | 60 +++ .../measurement/custom_energy_measure.py | 62 +++ src-combined/measurement/energy_meter.py | 115 +++++ src-combined/measurement/measurement_utils.py | 41 ++ src-combined/output/ast.txt | 470 ++++++++++++++++++ src-combined/output/ast_lines.txt | 240 +++++++++ src-combined/output/carbon_report.csv | 3 + src-combined/output/initial_carbon_report.csv | 33 ++ src-combined/output/report.txt | 152 ++++++ src-combined/refactorer/__init__.py | 0 src-combined/refactorer/base_refactorer.py | 26 + .../complex_list_comprehension_refactorer.py | 116 +++++ .../refactorer/large_class_refactorer.py | 83 ++++ .../refactorer/long_base_class_list.py | 14 + src-combined/refactorer/long_element_chain.py | 21 + .../long_lambda_function_refactorer.py | 16 + .../long_message_chain_refactorer.py | 17 + .../refactorer/long_method_refactorer.py | 18 + .../refactorer/long_scope_chaining.py | 24 + .../long_ternary_cond_expression.py | 17 + src-combined/testing/__init__.py | 0 src-combined/testing/test_runner.py | 17 + src-combined/testing/test_validator.py | 3 + src-combined/utils/__init__.py | 0 src-combined/utils/analyzers_config.py | 36 ++ src-combined/utils/ast_parser.py | 17 + src-combined/utils/code_smells.py | 22 + src-combined/utils/factory.py | 23 + src-combined/utils/logger.py | 34 ++ src1/__init__.py | 2 + .../code_smells/pylint_all_smells.json | 46 +- .../code_smells/pylint_configured_smells.json | 10 +- .../pylint_line_too_long_smells.json | 8 +- 41 files changed, 2004 insertions(+), 32 deletions(-) create mode 100644 src-combined/README.md create mode 100644 src-combined/__init__.py create mode 100644 src-combined/analyzers/__init__.py create mode 100644 src-combined/analyzers/base_analyzer.py create mode 100644 src-combined/analyzers/pylint_analyzer.py create mode 100644 src-combined/analyzers/ruff_analyzer.py create mode 100644 src-combined/main.py create mode 100644 src-combined/measurement/__init__.py create mode 100644 src-combined/measurement/code_carbon_meter.py create mode 100644 src-combined/measurement/custom_energy_measure.py create mode 100644 src-combined/measurement/energy_meter.py create mode 100644 src-combined/measurement/measurement_utils.py create mode 100644 src-combined/output/ast.txt create mode 100644 src-combined/output/ast_lines.txt create mode 100644 src-combined/output/carbon_report.csv create mode 100644 src-combined/output/initial_carbon_report.csv create mode 100644 src-combined/output/report.txt create mode 100644 src-combined/refactorer/__init__.py create mode 100644 src-combined/refactorer/base_refactorer.py create mode 100644 src-combined/refactorer/complex_list_comprehension_refactorer.py create mode 100644 src-combined/refactorer/large_class_refactorer.py create mode 100644 src-combined/refactorer/long_base_class_list.py create mode 100644 src-combined/refactorer/long_element_chain.py create mode 100644 src-combined/refactorer/long_lambda_function_refactorer.py create mode 100644 src-combined/refactorer/long_message_chain_refactorer.py create mode 100644 src-combined/refactorer/long_method_refactorer.py create mode 100644 src-combined/refactorer/long_scope_chaining.py create mode 100644 src-combined/refactorer/long_ternary_cond_expression.py create mode 100644 src-combined/testing/__init__.py create mode 100644 src-combined/testing/test_runner.py create mode 100644 src-combined/testing/test_validator.py create mode 100644 src-combined/utils/__init__.py create mode 100644 src-combined/utils/analyzers_config.py create mode 100644 src-combined/utils/ast_parser.py create mode 100644 src-combined/utils/code_smells.py create mode 100644 src-combined/utils/factory.py create mode 100644 src-combined/utils/logger.py create mode 100644 src1/__init__.py diff --git a/src-combined/README.md b/src-combined/README.md new file mode 100644 index 00000000..50aa3a2c --- /dev/null +++ b/src-combined/README.md @@ -0,0 +1,5 @@ +# Project Name Source Code + +The folders and files for this project are as follows: + +... diff --git a/src-combined/__init__.py b/src-combined/__init__.py new file mode 100644 index 00000000..56f09c20 --- /dev/null +++ b/src-combined/__init__.py @@ -0,0 +1,5 @@ +from . import analyzers +from . import measurement +from . import refactorer +from . import testing +from . import utils \ No newline at end of file diff --git a/src-combined/analyzers/__init__.py b/src-combined/analyzers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src-combined/analyzers/base_analyzer.py b/src-combined/analyzers/base_analyzer.py new file mode 100644 index 00000000..25840b46 --- /dev/null +++ b/src-combined/analyzers/base_analyzer.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod +import os + + +class BaseAnalyzer(ABC): + def __init__(self, code_path: str): + self.code_path = os.path.abspath(code_path) + + @abstractmethod + def analyze(self): + pass diff --git a/src-combined/analyzers/pylint_analyzer.py b/src-combined/analyzers/pylint_analyzer.py new file mode 100644 index 00000000..3c36d055 --- /dev/null +++ b/src-combined/analyzers/pylint_analyzer.py @@ -0,0 +1,127 @@ +import json +from io import StringIO +import ast +# ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN +# you will need to change imports too +# ====================================================== +# from os.path import dirname, abspath +# import sys + + +# # Sets src as absolute path, everything needs to be relative to src folder +# REFACTOR_DIR = dirname(abspath(__file__)) +# sys.path.append(dirname(REFACTOR_DIR)) + +from pylint.lint import Run +from pylint.reporters.json_reporter import JSON2Reporter + +from analyzers.base_analyzer import BaseAnalyzer + +from utils.analyzers_config import CustomSmell, PylintSmell +from utils.analyzers_config import IntermediateSmells +from utils.ast_parser import parse_line + +class PylintAnalyzer(BaseAnalyzer): + def __init__(self, code_path: str): + super().__init__(code_path) + + def analyze(self): + """ + Runs pylint on the specified Python file and returns the output as a list of dictionaries. + Each dictionary contains information about a code smell or warning identified by pylint. + + :param file_path: The path to the Python file to be analyzed. + :return: A list of dictionaries with pylint messages. + """ + # Capture pylint output into a string stream + output_stream = StringIO() + reporter = JSON2Reporter(output_stream) + + # Run pylint + Run(["--max-line-length=80", "--max-nested-blocks=3", "--max-branches=3", "--max-parents=3", self.code_path], reporter=reporter, exit=False) + + # Retrieve and parse output as JSON + output = output_stream.getvalue() + + try: + pylint_results: list[object] = json.loads(output) + except json.JSONDecodeError: + print("Error: Could not decode pylint output") + pylint_results = [] + + return pylint_results + + def filter_for_all_wanted_code_smells(self, pylint_results: list[object]): + filtered_results: list[object] = [] + + for error in pylint_results: + if error["messageId"] in PylintSmell.list(): + filtered_results.append(error) + + for smell in IntermediateSmells.list(): + temp_smells = self.filter_for_one_code_smell(pylint_results, smell) + + if smell == IntermediateSmells.LINE_TOO_LONG.value: + filtered_results.extend(self.filter_long_lines(temp_smells)) + + with open("src/output/report.txt", "w+") as f: + print(json.dumps(filtered_results, indent=2), file=f) + + return filtered_results + + def filter_for_one_code_smell(self, pylint_results: list[object], code: str): + filtered_results: list[object] = [] + for error in pylint_results: + if error["messageId"] == code: + filtered_results.append(error) + + return filtered_results + + def filter_long_lines(self, long_line_smells: list[object]): + selected_smells: list[object] = [] + for smell in long_line_smells: + root_node = parse_line(self.code_path, smell["line"]) + + if root_node is None: + continue + + for node in ast.walk(root_node): + if isinstance(node, ast.Expr): + for expr in ast.walk(node): + if isinstance(expr, ast.IfExp): # Ternary expression node + smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value + selected_smells.append(smell) + + if isinstance(node, ast.IfExp): # Ternary expression node + smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value + selected_smells.append(smell)\ + + return selected_smells + +# Example usage +# if __name__ == "__main__": + +# FILE_PATH = abspath("test/inefficent_code_example.py") + +# analyzer = PylintAnalyzer(FILE_PATH) + +# # print("THIS IS REPORT for our smells:") +# report = analyzer.analyze() + +# with open("src/output/ast.txt", "w+") as f: +# print(parse_file(FILE_PATH), file=f) + +# filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") + + +# with open(FILE_PATH, "r") as f: +# file_lines = f.readlines() + +# for smell in filtered_results: +# with open("src/output/ast_lines.txt", "a+") as f: +# print("Parsing line ", smell["line"], file=f) +# print(parse_line(file_lines, smell["line"]), end="\n", file=f) + + + + diff --git a/src-combined/analyzers/ruff_analyzer.py b/src-combined/analyzers/ruff_analyzer.py new file mode 100644 index 00000000..c771c2da --- /dev/null +++ b/src-combined/analyzers/ruff_analyzer.py @@ -0,0 +1,104 @@ +import subprocess + +from os.path import abspath, dirname +import sys + +# Sets src as absolute path, everything needs to be relative to src folder +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) + +from analyzers.base_analyzer import BaseAnalyzer + +class RuffAnalyzer(BaseAnalyzer): + def __init__(self, code_path: str): + super().__init__(code_path) + # We are going to use the codes to identify the smells this is a dict of all of them + + def analyze(self): + """ + Runs pylint on the specified Python file and returns the output as a list of dictionaries. + Each dictionary contains information about a code smell or warning identified by pylint. + + :param file_path: The path to the Python file to be analyzed. + :return: A list of dictionaries with pylint messages. + """ + # Base command to run Ruff + command = ["ruff", "check", "--select", "ALL", self.code_path] + + # # Add config file option if specified + # if config_file: + # command.extend(["--config", config_file]) + + try: + # Run the command and capture output + result = subprocess.run(command, text=True, capture_output=True, check=True) + + # Print the output from Ruff + with open("output/ruff.txt", "a+") as f: + f.write(result.stdout) + # print("Ruff output:") + # print(result.stdout) + + except subprocess.CalledProcessError as e: + # If Ruff fails (e.g., lint errors), capture and print error output + print("Ruff encountered issues:") + print(e.stdout) # Ruff's linting output + print(e.stderr) # Any additional error information + sys.exit(1) # Exit with a non-zero status if Ruff fails + + # def filter_for_all_wanted_code_smells(self, pylint_results): + # statistics = {} + # report = [] + # filtered_results = [] + + # for error in pylint_results: + # if error["messageId"] in CodeSmells.list(): + # statistics[error["messageId"]] = True + # filtered_results.append(error) + + # report.append(filtered_results) + # report.append(statistics) + + # with open("src/output/report.txt", "w+") as f: + # print(json.dumps(report, indent=2), file=f) + + # return report + + # def filter_for_one_code_smell(self, pylint_results, code): + # filtered_results = [] + # for error in pylint_results: + # if error["messageId"] == code: + # filtered_results.append(error) + + # return filtered_results + +# Example usage +if __name__ == "__main__": + + FILE_PATH = abspath("test/inefficent_code_example.py") + OUTPUT_FILE = abspath("src/output/ruff.txt") + + analyzer = RuffAnalyzer(FILE_PATH) + + # print("THIS IS REPORT for our smells:") + analyzer.analyze() + + # print(report) + + # with open("src/output/ast.txt", "w+") as f: + # print(parse_file(FILE_PATH), file=f) + + # filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") + + + # with open(FILE_PATH, "r") as f: + # file_lines = f.readlines() + + # for smell in filtered_results: + # with open("src/output/ast_lines.txt", "a+") as f: + # print("Parsing line ", smell["line"], file=f) + # print(parse_line(file_lines, smell["line"]), end="\n", file=f) + + + + diff --git a/src-combined/main.py b/src-combined/main.py new file mode 100644 index 00000000..7a79d364 --- /dev/null +++ b/src-combined/main.py @@ -0,0 +1,38 @@ +import os + +from analyzers.pylint_analyzer import PylintAnalyzer +from measurement.code_carbon_meter import CarbonAnalyzer +from utils.factory import RefactorerFactory + +dirname = os.path.dirname(__file__) + +def main(): + """ + Entry point for the refactoring tool. + - Create an instance of the analyzer. + - Perform code analysis and print the results. + """ + + # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug + TEST_FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") + INITIAL_REPORT_FILE_PATH = os.path.join(dirname, "output/initial_carbon_report.csv") + + carbon_analyzer = CarbonAnalyzer(TEST_FILE_PATH) + carbon_analyzer.run_and_measure() + carbon_analyzer.save_report(INITIAL_REPORT_FILE_PATH) + + analyzer = PylintAnalyzer(TEST_FILE_PATH) + report = analyzer.analyze() + + detected_smells = analyzer.filter_for_all_wanted_code_smells(report["messages"]) + + for smell in detected_smells: + smell_id: str = smell["messageId"] + + print("Refactoring ", smell_id) + refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE_PATH) + refactoring_class.refactor() + + +if __name__ == "__main__": + main() diff --git a/src-combined/measurement/__init__.py b/src-combined/measurement/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src-combined/measurement/code_carbon_meter.py b/src-combined/measurement/code_carbon_meter.py new file mode 100644 index 00000000..a60ed932 --- /dev/null +++ b/src-combined/measurement/code_carbon_meter.py @@ -0,0 +1,60 @@ +import subprocess +import sys +from codecarbon import EmissionsTracker +from pathlib import Path +import pandas as pd +from os.path import dirname, abspath + +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) + +class CarbonAnalyzer: + def __init__(self, script_path: str): + self.script_path = script_path + self.tracker = EmissionsTracker(save_to_file=False, allow_multiple_runs=True) + + def run_and_measure(self): + script = Path(self.script_path) + if not script.exists() or script.suffix != ".py": + raise ValueError("Please provide a valid Python script path.") + self.tracker.start() + try: + subprocess.run([sys.executable, str(script)], check=True) + except subprocess.CalledProcessError as e: + print(f"Error: The script encountered an error: {e}") + finally: + # Stop tracking and get emissions data + emissions = self.tracker.stop() + if emissions is None or pd.isna(emissions): + print("Warning: No valid emissions data collected. Check system compatibility.") + else: + print("Emissions data:", emissions) + + def save_report(self, report_path: str): + """ + Save the emissions report to a CSV file with two columns: attribute and value. + """ + emissions_data = self.tracker.final_emissions_data + if emissions_data: + # Convert EmissionsData object to a dictionary and create rows for each attribute + emissions_dict = emissions_data.__dict__ + attributes = list(emissions_dict.keys()) + values = list(emissions_dict.values()) + + # Create a DataFrame with two columns: 'Attribute' and 'Value' + df = pd.DataFrame({ + "Attribute": attributes, + "Value": values + }) + + # Save the DataFrame to CSV + df.to_csv(report_path, index=False) + print(f"Report saved to {report_path}") + else: + print("No data to save. Ensure CodeCarbon supports your system hardware for emissions tracking.") + +# Example usage +if __name__ == "__main__": + analyzer = CarbonAnalyzer("src/output/inefficent_code_example.py") + analyzer.run_and_measure() + analyzer.save_report("src/output/test/carbon_report.csv") diff --git a/src-combined/measurement/custom_energy_measure.py b/src-combined/measurement/custom_energy_measure.py new file mode 100644 index 00000000..212fcd2f --- /dev/null +++ b/src-combined/measurement/custom_energy_measure.py @@ -0,0 +1,62 @@ +import resource + +from measurement_utils import (start_process, calculate_ram_power, + start_pm_process, stop_pm_process, get_cpu_power_from_pm_logs) +import time + + +class CustomEnergyMeasure: + """ + Handles custom CPU and RAM energy measurements for executing a Python script. + Currently only works for Apple Silicon Chips with sudo access(password prompt in terminal) + Next step includes device detection for calculating on multiple platforms + """ + + def __init__(self, script_path: str): + self.script_path = script_path + self.results = {"cpu": 0.0, "ram": 0.0} + self.code_process_time = 0 + + def measure_cpu_power(self): + # start powermetrics as a child process + powermetrics_process = start_pm_process() + # allow time to enter password for sudo rights in mac + time.sleep(5) + try: + start_time = time.time() + # execute the provided code as another child process and wait to finish + code_process = start_process(["python3", self.script_path]) + code_process_pid = code_process.pid + code_process.wait() + end_time = time.time() + self.code_process_time = end_time - start_time + # Parse powermetrics log to extract CPU power data for this PID + finally: + stop_pm_process(powermetrics_process) + self.results["cpu"] = get_cpu_power_from_pm_logs("custom_energy_output.txt", code_process_pid) + + def measure_ram_power(self): + # execute provided code as a child process, this time without simultaneous powermetrics process + # code needs to rerun to use resource.getrusage() for a single child + # might look into another library that does not require this + code_process = start_process(["python3", self.script_path]) + code_process.wait() + + # get peak memory usage in bytes for this process + peak_memory_b = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss + + # calculate RAM power based on peak memory(3W/8GB ratio) + self.results["ram"] = calculate_ram_power(peak_memory_b) + + def calculate_energy_from_power(self): + # Return total energy consumed + total_power = self.results["cpu"] + self.results["ram"] # in watts + return total_power * self.code_process_time + + +if __name__ == "__main__": + custom_measure = CustomEnergyMeasure("/capstone--source-code-optimizer/test/high_energy_code_example.py") + custom_measure.measure_cpu_power() + custom_measure.measure_ram_power() + #can be saved as a report later + print(custom_measure.calculate_energy_from_power()) diff --git a/src-combined/measurement/energy_meter.py b/src-combined/measurement/energy_meter.py new file mode 100644 index 00000000..38426bf1 --- /dev/null +++ b/src-combined/measurement/energy_meter.py @@ -0,0 +1,115 @@ +import time +from typing import Callable +from pyJoules.device import DeviceFactory +from pyJoules.device.rapl_device import RaplPackageDomain, RaplDramDomain +from pyJoules.device.nvidia_device import NvidiaGPUDomain +from pyJoules.energy_meter import EnergyMeter + +## Required for installation +# pip install pyJoules +# pip install nvidia-ml-py3 + +# TEST TO SEE IF PYJOULE WORKS FOR YOU + + +class EnergyMeterWrapper: + """ + A class to measure the energy consumption of specific code blocks using PyJoules. + """ + + def __init__(self): + """ + Initializes the EnergyMeterWrapper class. + """ + # Create and configure the monitored devices + domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)] + devices = DeviceFactory.create_devices(domains) + self.meter = EnergyMeter(devices) + + def measure_energy(self, func: Callable, *args, **kwargs): + """ + Measures the energy consumed by the specified function during its execution. + + Parameters: + - func (Callable): The function to measure. + - *args: Arguments to pass to the function. + - **kwargs: Keyword arguments to pass to the function. + + Returns: + - tuple: A tuple containing the return value of the function and the energy consumed (in Joules). + """ + self.meter.start(tag="function_execution") # Start measuring energy + + start_time = time.time() # Record start time + + result = func(*args, **kwargs) # Call the specified function + + end_time = time.time() # Record end time + self.meter.stop() # Stop measuring energy + + # Retrieve the energy trace + trace = self.meter.get_trace() + total_energy = sum( + sample.energy for sample in trace + ) # Calculate total energy consumed + + # Log the timing (optional) + print(f"Execution Time: {end_time - start_time:.6f} seconds") + print(f"Energy Consumed: {total_energy:.6f} Joules") + + return ( + result, + total_energy, + ) # Return the result of the function and the energy consumed + + def measure_block(self, code_block: str): + """ + Measures energy consumption for a block of code represented as a string. + + Parameters: + - code_block (str): A string containing the code to execute. + + Returns: + - float: The energy consumed (in Joules). + """ + local_vars = {} + self.meter.start(tag="block_execution") # Start measuring energy + exec(code_block, {}, local_vars) # Execute the code block + self.meter.stop() # Stop measuring energy + + # Retrieve the energy trace + trace = self.meter.get_trace() + total_energy = sum( + sample.energy for sample in trace + ) # Calculate total energy consumed + print(f"Energy Consumed for the block: {total_energy:.6f} Joules") + return total_energy + + def measure_file_energy(self, file_path: str): + """ + Measures the energy consumption of the code in the specified Python file. + + Parameters: + - file_path (str): The path to the Python file. + + Returns: + - float: The energy consumed (in Joules). + """ + try: + with open(file_path, "r") as file: + code = file.read() # Read the content of the file + + # Execute the code block and measure energy consumption + return self.measure_block(code) + + except Exception as e: + print(f"An error occurred while measuring energy for the file: {e}") + return None # Return None in case of an error + + +# Example usage +if __name__ == "__main__": + meter = EnergyMeterWrapper() + energy_used = meter.measure_file_energy("../test/inefficent_code_example.py") + if energy_used is not None: + print(f"Total Energy Consumed: {energy_used:.6f} Joules") diff --git a/src-combined/measurement/measurement_utils.py b/src-combined/measurement/measurement_utils.py new file mode 100644 index 00000000..292698c9 --- /dev/null +++ b/src-combined/measurement/measurement_utils.py @@ -0,0 +1,41 @@ +import resource +import subprocess +import time +import re + + +def start_process(command): + return subprocess.Popen(command) + +def calculate_ram_power(memory_b): + memory_gb = memory_b / (1024 ** 3) + return memory_gb * 3 / 8 # 3W/8GB ratio + + +def start_pm_process(log_path="custom_energy_output.txt"): + powermetrics_process = subprocess.Popen( + ["sudo", "powermetrics", "--samplers", "tasks,cpu_power", "--show-process-gpu", "-i", "5000"], + stdout=open(log_path, "w"), + stderr=subprocess.PIPE + ) + return powermetrics_process + + +def stop_pm_process(powermetrics_process): + powermetrics_process.terminate() + +def get_cpu_power_from_pm_logs(log_path, pid): + cpu_share, total_cpu_power = None, None # in ms/s and mW respectively + with open(log_path, 'r') as file: + lines = file.readlines() + for line in lines: + if str(pid) in line: + cpu_share = float(line.split()[2]) + elif "CPU Power:" in line: + total_cpu_power = float(line.split()[2]) + if cpu_share and total_cpu_power: + break + if cpu_share and total_cpu_power: + cpu_power = (cpu_share / 1000) * (total_cpu_power / 1000) + return cpu_power + return None diff --git a/src-combined/output/ast.txt b/src-combined/output/ast.txt new file mode 100644 index 00000000..bbeae637 --- /dev/null +++ b/src-combined/output/ast.txt @@ -0,0 +1,470 @@ +Module( + body=[ + ClassDef( + name='DataProcessor', + body=[ + FunctionDef( + name='__init__', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='data')]), + body=[ + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Store())], + value=Name(id='data', ctx=Load())), + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=List(ctx=Load()))]), + FunctionDef( + name='process_all_data', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Assign( + targets=[ + Name(id='results', ctx=Store())], + value=List(ctx=Load())), + For( + target=Name(id='item', ctx=Store()), + iter=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + body=[ + Try( + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=Call( + func=Attribute( + value=Name(id='self', ctx=Load()), + attr='complex_calculation', + ctx=Load()), + args=[ + Name(id='item', ctx=Load()), + Constant(value=True), + Constant(value=False), + Constant(value='multiply'), + Constant(value=10), + Constant(value=20), + Constant(value=None), + Constant(value='end')])), + Expr( + value=Call( + func=Attribute( + value=Name(id='results', ctx=Load()), + attr='append', + ctx=Load()), + args=[ + Name(id='result', ctx=Load())]))], + handlers=[ + ExceptHandler( + type=Name(id='Exception', ctx=Load()), + name='e', + body=[ + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Constant(value='An error occurred:'), + Name(id='e', ctx=Load())]))])])]), + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Call( + func=Attribute( + value=Call( + func=Attribute( + value=Call( + func=Attribute( + value=Call( + func=Attribute( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + attr='upper', + ctx=Load())), + attr='strip', + ctx=Load())), + attr='replace', + ctx=Load()), + args=[ + Constant(value=' '), + Constant(value='_')]), + attr='lower', + ctx=Load()))])), + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=Call( + func=Name(id='list', ctx=Load()), + args=[ + Call( + func=Name(id='filter', ctx=Load()), + args=[ + Lambda( + args=arguments( + args=[ + arg(arg='x')]), + body=BoolOp( + op=And(), + values=[ + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=None)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=0)]), + Compare( + left=Call( + func=Name(id='len', ctx=Load()), + args=[ + Call( + func=Name(id='str', ctx=Load()), + args=[ + Name(id='x', ctx=Load())])]), + ops=[ + Gt()], + comparators=[ + Constant(value=1)])])), + Name(id='results', ctx=Load())])])), + Return( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Load()))])]), + ClassDef( + name='AdvancedProcessor', + bases=[ + Name(id='DataProcessor', ctx=Load()), + Name(id='object', ctx=Load()), + Name(id='dict', ctx=Load()), + Name(id='list', ctx=Load()), + Name(id='set', ctx=Load()), + Name(id='tuple', ctx=Load())], + body=[ + Pass(), + FunctionDef( + name='check_data', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='item')]), + body=[ + Return( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]), + FunctionDef( + name='complex_comprehension', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Assign( + targets=[ + Attribute( + value=Name(id='self', ctx=Load()), + attr='processed_data', + ctx=Store())], + value=ListComp( + elt=IfExp( + test=Compare( + left=BinOp( + left=Name(id='x', ctx=Load()), + op=Mod(), + right=Constant(value=2)), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=BinOp( + left=Name(id='x', ctx=Load()), + op=Pow(), + right=Constant(value=2)), + orelse=BinOp( + left=Name(id='x', ctx=Load()), + op=Pow(), + right=Constant(value=3))), + generators=[ + comprehension( + target=Name(id='x', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=1), + Constant(value=100)]), + ifs=[ + BoolOp( + op=And(), + values=[ + Compare( + left=BinOp( + left=Name(id='x', ctx=Load()), + op=Mod(), + right=Constant(value=5)), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + NotEq()], + comparators=[ + Constant(value=50)]), + Compare( + left=Name(id='x', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=3)])])], + is_async=0)]))]), + FunctionDef( + name='long_chain', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + Try( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load())), + Return( + value=Name(id='deep_value', ctx=Load()))], + handlers=[ + ExceptHandler( + type=Name(id='KeyError', ctx=Load()), + body=[ + Return( + value=Constant(value=None))])])]), + FunctionDef( + name='long_scope_chaining', + args=arguments( + args=[ + arg(arg='self')]), + body=[ + For( + target=Name(id='a', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='b', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='c', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='d', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + For( + target=Name(id='e', ctx=Store()), + iter=Call( + func=Name(id='range', ctx=Load()), + args=[ + Constant(value=10)]), + body=[ + If( + test=Compare( + left=BinOp( + left=BinOp( + left=BinOp( + left=BinOp( + left=Name(id='a', ctx=Load()), + op=Add(), + right=Name(id='b', ctx=Load())), + op=Add(), + right=Name(id='c', ctx=Load())), + op=Add(), + right=Name(id='d', ctx=Load())), + op=Add(), + right=Name(id='e', ctx=Load())), + ops=[ + Gt()], + comparators=[ + Constant(value=25)]), + body=[ + Return( + value=Constant(value='Done'))])])])])])])]), + FunctionDef( + name='complex_calculation', + args=arguments( + args=[ + arg(arg='self'), + arg(arg='item'), + arg(arg='flag1'), + arg(arg='flag2'), + arg(arg='operation'), + arg(arg='threshold'), + arg(arg='max_value'), + arg(arg='option'), + arg(arg='final_stage')]), + body=[ + If( + test=Compare( + left=Name(id='operation', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='multiply')]), + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=BinOp( + left=Name(id='item', ctx=Load()), + op=Mult(), + right=Name(id='threshold', ctx=Load())))], + orelse=[ + If( + test=Compare( + left=Name(id='operation', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='add')]), + body=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=BinOp( + left=Name(id='item', ctx=Load()), + op=Add(), + right=Name(id='max_value', ctx=Load())))], + orelse=[ + Assign( + targets=[ + Name(id='result', ctx=Store())], + value=Name(id='item', ctx=Load()))])]), + Return( + value=Name(id='result', ctx=Load()))])]), + If( + test=Compare( + left=Name(id='__name__', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value='__main__')]), + body=[ + Assign( + targets=[ + Name(id='sample_data', ctx=Store())], + value=List( + elts=[ + Constant(value=1), + Constant(value=2), + Constant(value=3), + Constant(value=4), + Constant(value=5)], + ctx=Load())), + Assign( + targets=[ + Name(id='processor', ctx=Store())], + value=Call( + func=Name(id='DataProcessor', ctx=Load()), + args=[ + Name(id='sample_data', ctx=Load())])), + Assign( + targets=[ + Name(id='processed', ctx=Store())], + value=Call( + func=Attribute( + value=Name(id='processor', ctx=Load()), + attr='process_all_data', + ctx=Load()))), + Expr( + value=Call( + func=Name(id='print', ctx=Load()), + args=[ + Constant(value='Processed Data:'), + Name(id='processed', ctx=Load())]))])]) diff --git a/src-combined/output/ast_lines.txt b/src-combined/output/ast_lines.txt new file mode 100644 index 00000000..76343f17 --- /dev/null +++ b/src-combined/output/ast_lines.txt @@ -0,0 +1,240 @@ +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) +Parsing line 19 +Not Valid Smell +Parsing line 41 +Module( + body=[ + Expr( + value=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Gt()], + comparators=[ + Constant(value=10)]), + body=Constant(value=True), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Lt()], + comparators=[ + UnaryOp( + op=USub(), + operand=Constant(value=10))]), + body=Constant(value=False), + orelse=IfExp( + test=Compare( + left=Name(id='item', ctx=Load()), + ops=[ + Eq()], + comparators=[ + Constant(value=0)]), + body=Constant(value=None), + orelse=Name(id='item', ctx=Load())))))]) +Parsing line 57 +Module( + body=[ + Assign( + targets=[ + Name(id='deep_value', ctx=Store())], + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Subscript( + value=Attribute( + value=Name(id='self', ctx=Load()), + attr='data', + ctx=Load()), + slice=Constant(value=0), + ctx=Load()), + slice=Constant(value=1), + ctx=Load()), + slice=Constant(value='details'), + ctx=Load()), + slice=Constant(value='info'), + ctx=Load()), + slice=Constant(value='more_info'), + ctx=Load()), + slice=Constant(value=2), + ctx=Load()), + slice=Constant(value='target'), + ctx=Load()))]) +Parsing line 74 +Module( + body=[ + Expr( + value=Tuple( + elts=[ + Name(id='self', ctx=Load()), + Name(id='item', ctx=Load()), + Name(id='flag1', ctx=Load()), + Name(id='flag2', ctx=Load()), + Name(id='operation', ctx=Load()), + Name(id='threshold', ctx=Load()), + Name(id='max_value', ctx=Load()), + Name(id='option', ctx=Load()), + Name(id='final_stage', ctx=Load())], + ctx=Load()))]) diff --git a/src-combined/output/carbon_report.csv b/src-combined/output/carbon_report.csv new file mode 100644 index 00000000..fd11fa7f --- /dev/null +++ b/src-combined/output/carbon_report.csv @@ -0,0 +1,3 @@ +timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue +2024-11-06T15:32:34,codecarbon,ab07718b-de1c-496e-91b2-c0ffd4e84ef5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.1535916000138968,2.214386652360756e-08,1.4417368216493612e-07,7.5,0.0,6.730809688568115,3.176875000159877e-07,0,2.429670854124108e-07,5.606545854283984e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 +2024-11-06T15:37:39,codecarbon,515a920a-2566-4af3-92ef-5b930f41ca18,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.15042520000133663,2.1765796594351643e-08,1.4469514811453293e-07,7.5,0.0,6.730809688568115,3.1103791661735157e-07,0,2.400444182185886e-07,5.510823348359402e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 diff --git a/src-combined/output/initial_carbon_report.csv b/src-combined/output/initial_carbon_report.csv new file mode 100644 index 00000000..f9ed7451 --- /dev/null +++ b/src-combined/output/initial_carbon_report.csv @@ -0,0 +1,33 @@ +Attribute,Value +timestamp,2024-11-07T11:29:20 +project_name,codecarbon +run_id,2d6d643f-acbc-49b4-8627-e46fe95bdf92 +experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 +duration,0.14742779999505728 +emissions,2.0976451367814492e-08 +emissions_rate,1.4228287587902522e-07 +cpu_power,7.5 +gpu_power,0.0 +ram_power,6.730809688568115 +cpu_energy,3.0441354174399747e-07 +gpu_energy,0 +ram_energy,2.2668357414780443e-07 +energy_consumed,5.310971158918019e-07 +country_name,Canada +country_iso_code,CAN +region,ontario +cloud_provider, +cloud_region, +os,Windows-11-10.0.22631-SP0 +python_version,3.13.0 +codecarbon_version,2.7.2 +cpu_count,8 +cpu_model,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx +gpu_count, +gpu_model, +longitude,-79.9441 +latitude,43.266 +ram_total_size,17.94882583618164 +tracking_mode,machine +on_cloud,N +pue,1.0 diff --git a/src-combined/output/report.txt b/src-combined/output/report.txt new file mode 100644 index 00000000..2c1a3c0b --- /dev/null +++ b/src-combined/output/report.txt @@ -0,0 +1,152 @@ +[ + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 19, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (85/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 57, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (86/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 74, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" + } +] diff --git a/src-combined/refactorer/__init__.py b/src-combined/refactorer/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src-combined/refactorer/base_refactorer.py b/src-combined/refactorer/base_refactorer.py new file mode 100644 index 00000000..3450ad9f --- /dev/null +++ b/src-combined/refactorer/base_refactorer.py @@ -0,0 +1,26 @@ +# src/refactorer/base_refactorer.py + +from abc import ABC, abstractmethod + + +class BaseRefactorer(ABC): + """ + Abstract base class for refactorers. + Subclasses should implement the `refactor` method. + """ + @abstractmethod + def __init__(self, code): + """ + Initialize the refactorer with the code to refactor. + + :param code: The code that needs refactoring + """ + self.code = code + + @abstractmethod + def refactor(code_smell_error, input_code): + """ + Perform the refactoring process. + Must be implemented by subclasses. + """ + pass diff --git a/src-combined/refactorer/complex_list_comprehension_refactorer.py b/src-combined/refactorer/complex_list_comprehension_refactorer.py new file mode 100644 index 00000000..7bf924b8 --- /dev/null +++ b/src-combined/refactorer/complex_list_comprehension_refactorer.py @@ -0,0 +1,116 @@ +import ast +import astor +from .base_refactorer import BaseRefactorer + +class ComplexListComprehensionRefactorer(BaseRefactorer): + """ + Refactorer for complex list comprehensions to improve readability. + """ + + def __init__(self, code: str): + """ + Initializes the refactorer. + + :param code: The source code to refactor. + """ + super().__init__(code) + + def refactor(self): + """ + Refactor the code by transforming complex list comprehensions into for-loops. + + :return: The refactored code. + """ + # Parse the code to get the AST + tree = ast.parse(self.code) + + # Walk through the AST and refactor complex list comprehensions + for node in ast.walk(tree): + if isinstance(node, ast.ListComp): + # Check if the list comprehension is complex + if self.is_complex(node): + # Create a for-loop equivalent + for_loop = self.create_for_loop(node) + # Replace the list comprehension with the for-loop in the AST + self.replace_node(node, for_loop) + + # Convert the AST back to code + return self.ast_to_code(tree) + + def create_for_loop(self, list_comp: ast.ListComp) -> ast.For: + """ + Create a for-loop that represents the list comprehension. + + :param list_comp: The ListComp node to convert. + :return: An ast.For node representing the for-loop. + """ + # Create the variable to hold results + result_var = ast.Name(id='result', ctx=ast.Store()) + + # Create the for-loop + for_loop = ast.For( + target=ast.Name(id='item', ctx=ast.Store()), + iter=list_comp.generators[0].iter, + body=[ + ast.Expr(value=ast.Call( + func=ast.Name(id='append', ctx=ast.Load()), + args=[self.transform_value(list_comp.elt)], + keywords=[] + )) + ], + orelse=[] + ) + + # Create a list to hold results + result_list = ast.List(elts=[], ctx=ast.Store()) + return ast.With( + context_expr=ast.Name(id='result', ctx=ast.Load()), + body=[for_loop], + lineno=list_comp.lineno, + col_offset=list_comp.col_offset + ) + + def transform_value(self, value_node: ast.AST) -> ast.AST: + """ + Transform the value in the list comprehension into a form usable in a for-loop. + + :param value_node: The value node to transform. + :return: The transformed value node. + """ + return value_node + + def replace_node(self, old_node: ast.AST, new_node: ast.AST): + """ + Replace an old node in the AST with a new node. + + :param old_node: The node to replace. + :param new_node: The node to insert in its place. + """ + parent = self.find_parent(old_node) + if parent: + for index, child in enumerate(ast.iter_child_nodes(parent)): + if child is old_node: + parent.body[index] = new_node + break + + def find_parent(self, node: ast.AST) -> ast.AST: + """ + Find the parent node of a given AST node. + + :param node: The node to find the parent for. + :return: The parent node, or None if not found. + """ + for parent in ast.walk(node): + for child in ast.iter_child_nodes(parent): + if child is node: + return parent + return None + + def ast_to_code(self, tree: ast.AST) -> str: + """ + Convert AST back to source code. + + :param tree: The AST to convert. + :return: The source code as a string. + """ + return astor.to_source(tree) diff --git a/src-combined/refactorer/large_class_refactorer.py b/src-combined/refactorer/large_class_refactorer.py new file mode 100644 index 00000000..c4af6ba3 --- /dev/null +++ b/src-combined/refactorer/large_class_refactorer.py @@ -0,0 +1,83 @@ +import ast + +class LargeClassRefactorer: + """ + Refactorer for large classes that have too many methods. + """ + + def __init__(self, code: str, method_threshold: int = 5): + """ + Initializes the refactorer. + + :param code: The source code of the class to refactor. + :param method_threshold: The number of methods above which a class is considered large. + """ + super().__init__(code) + self.method_threshold = method_threshold + + def refactor(self): + """ + Refactor the class by splitting it into smaller classes if it exceeds the method threshold. + + :return: The refactored code. + """ + # Parse the code to get the class definition + tree = ast.parse(self.code) + class_definitions = [node for node in tree.body if isinstance(node, ast.ClassDef)] + + refactored_code = [] + + for class_def in class_definitions: + methods = [n for n in class_def.body if isinstance(n, ast.FunctionDef)] + if len(methods) > self.method_threshold: + # If the class is large, split it + new_classes = self.split_class(class_def, methods) + refactored_code.extend(new_classes) + else: + # Keep the class as is + refactored_code.append(class_def) + + # Convert the AST back to code + return self.ast_to_code(refactored_code) + + def split_class(self, class_def, methods): + """ + Split the large class into smaller classes based on methods. + + :param class_def: The class definition node. + :param methods: The list of methods in the class. + :return: A list of new class definitions. + """ + # For demonstration, we'll simply create two classes based on the method count + half_index = len(methods) // 2 + new_class1 = self.create_new_class(class_def.name + "Part1", methods[:half_index]) + new_class2 = self.create_new_class(class_def.name + "Part2", methods[half_index:]) + + return [new_class1, new_class2] + + def create_new_class(self, new_class_name, methods): + """ + Create a new class definition with the specified methods. + + :param new_class_name: Name of the new class. + :param methods: List of methods to include in the new class. + :return: A new class definition node. + """ + # Create the class definition with methods + class_def = ast.ClassDef( + name=new_class_name, + bases=[], + body=methods, + decorator_list=[] + ) + return class_def + + def ast_to_code(self, nodes): + """ + Convert AST nodes back to source code. + + :param nodes: The AST nodes to convert. + :return: The source code as a string. + """ + import astor + return astor.to_source(nodes) diff --git a/src-combined/refactorer/long_base_class_list.py b/src-combined/refactorer/long_base_class_list.py new file mode 100644 index 00000000..fdd15297 --- /dev/null +++ b/src-combined/refactorer/long_base_class_list.py @@ -0,0 +1,14 @@ +from .base_refactorer import BaseRefactorer + +class LongBaseClassListRefactorer(BaseRefactorer): + """ + Refactorer that targets long base class lists to improve performance. + """ + + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass diff --git a/src-combined/refactorer/long_element_chain.py b/src-combined/refactorer/long_element_chain.py new file mode 100644 index 00000000..6c168afa --- /dev/null +++ b/src-combined/refactorer/long_element_chain.py @@ -0,0 +1,21 @@ +from .base_refactorer import BaseRefactorer + +class LongElementChainRefactorer(BaseRefactorer): + """ + Refactorer for data objects (dictionary) that have too many deeply nested elements inside. + Ex: deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + """ + + def __init__(self, code: str, element_threshold: int = 5): + """ + Initializes the refactorer. + + :param code: The source code of the class to refactor. + :param method_threshold: The number of nested elements allowed before dictionary has too many deeply nested elements. + """ + super().__init__(code) + self.element_threshold = element_threshold + + def refactor(self): + + return self.code \ No newline at end of file diff --git a/src-combined/refactorer/long_lambda_function_refactorer.py b/src-combined/refactorer/long_lambda_function_refactorer.py new file mode 100644 index 00000000..421ada60 --- /dev/null +++ b/src-combined/refactorer/long_lambda_function_refactorer.py @@ -0,0 +1,16 @@ +from .base_refactorer import BaseRefactorer + +class LongLambdaFunctionRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + def __init__(self, code): + super().__init__(code) + + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass diff --git a/src-combined/refactorer/long_message_chain_refactorer.py b/src-combined/refactorer/long_message_chain_refactorer.py new file mode 100644 index 00000000..2438910f --- /dev/null +++ b/src-combined/refactorer/long_message_chain_refactorer.py @@ -0,0 +1,17 @@ +from .base_refactorer import BaseRefactorer + +class LongMessageChainRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + + def __init__(self, code): + super().__init__(code) + + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass diff --git a/src-combined/refactorer/long_method_refactorer.py b/src-combined/refactorer/long_method_refactorer.py new file mode 100644 index 00000000..734afa67 --- /dev/null +++ b/src-combined/refactorer/long_method_refactorer.py @@ -0,0 +1,18 @@ +from .base_refactorer import BaseRefactorer + +class LongMethodRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + + def __init__(self, code): + super().__init__(code) + + + def refactor(self): + """ + Refactor long methods into smaller methods. + Implement the logic to detect and refactor long methods. + """ + # Logic to identify long methods goes here + pass diff --git a/src-combined/refactorer/long_scope_chaining.py b/src-combined/refactorer/long_scope_chaining.py new file mode 100644 index 00000000..39e53316 --- /dev/null +++ b/src-combined/refactorer/long_scope_chaining.py @@ -0,0 +1,24 @@ +from .base_refactorer import BaseRefactorer + +class LongScopeRefactorer(BaseRefactorer): + """ + Refactorer for methods that have too many deeply nested loops. + """ + def __init__(self, code: str, loop_threshold: int = 5): + """ + Initializes the refactorer. + + :param code: The source code of the class to refactor. + :param method_threshold: The number of loops allowed before method is considered one with too many nested loops. + """ + super().__init__(code) + self.loop_threshold = loop_threshold + + def refactor(self): + """ + Refactor code by ... + + Return: refactored code + """ + + return self.code \ No newline at end of file diff --git a/src-combined/refactorer/long_ternary_cond_expression.py b/src-combined/refactorer/long_ternary_cond_expression.py new file mode 100644 index 00000000..994ccfc3 --- /dev/null +++ b/src-combined/refactorer/long_ternary_cond_expression.py @@ -0,0 +1,17 @@ +from .base_refactorer import BaseRefactorer + +class LTCERefactorer(BaseRefactorer): + """ + Refactorer that targets long ternary conditional expressions (LTCEs) to improve readability. + """ + + def __init__(self, code): + super().__init__(code) + + def refactor(self): + """ + Refactor LTCEs into smaller methods. + Implement the logic to detect and refactor LTCEs. + """ + # Logic to identify LTCEs goes here + pass diff --git a/src-combined/testing/__init__.py b/src-combined/testing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src-combined/testing/test_runner.py b/src-combined/testing/test_runner.py new file mode 100644 index 00000000..84fe92a9 --- /dev/null +++ b/src-combined/testing/test_runner.py @@ -0,0 +1,17 @@ +import unittest +import os +import sys + +# Add the src directory to the path to import modules +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) + +# Discover and run all tests in the 'tests' directory +def run_tests(): + test_loader = unittest.TestLoader() + test_suite = test_loader.discover('tests', pattern='*.py') + + test_runner = unittest.TextTestRunner(verbosity=2) + test_runner.run(test_suite) + +if __name__ == '__main__': + run_tests() diff --git a/src-combined/testing/test_validator.py b/src-combined/testing/test_validator.py new file mode 100644 index 00000000..cbbb29d4 --- /dev/null +++ b/src-combined/testing/test_validator.py @@ -0,0 +1,3 @@ +def validate_output(original, refactored): + # Compare original and refactored output + return original == refactored diff --git a/src-combined/utils/__init__.py b/src-combined/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src-combined/utils/analyzers_config.py b/src-combined/utils/analyzers_config.py new file mode 100644 index 00000000..12b875bf --- /dev/null +++ b/src-combined/utils/analyzers_config.py @@ -0,0 +1,36 @@ +# Any configurations that are done by the analyzers +from enum import Enum + +class ExtendedEnum(Enum): + + @classmethod + def list(cls) -> list[str]: + return [c.value for c in cls] + +class PylintSmell(ExtendedEnum): + LONG_MESSAGE_CHAIN = "R0914" # pylint smell + LARGE_CLASS = "R0902" # pylint smell + LONG_PARAMETER_LIST = "R0913" # pylint smell + LONG_METHOD = "R0915" # pylint smell + COMPLEX_LIST_COMPREHENSION = "C0200" # pylint smell + INVALID_NAMING_CONVENTIONS = "C0103" # pylint smell + +class CustomSmell(ExtendedEnum): + LONG_TERN_EXPR = "CUST-1" # custom smell + +# Smells that lead to wanted smells +class IntermediateSmells(ExtendedEnum): + LINE_TOO_LONG = "C0301" # pylint smell + +AllSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, + **{s.name: s.value for s in CustomSmell}}) + +SMELL_CODES = [s.value for s in AllSmells] + +# Extra pylint options +EXTRA_PYLINT_OPTIONS = [ + "--max-line-length=80", + "--max-nested-blocks=3", + "--max-branches=3", + "--max-parents=3" +] diff --git a/src-combined/utils/ast_parser.py b/src-combined/utils/ast_parser.py new file mode 100644 index 00000000..6a7f6fd8 --- /dev/null +++ b/src-combined/utils/ast_parser.py @@ -0,0 +1,17 @@ +import ast + +def parse_line(file: str, line: int): + with open(file, "r") as f: + file_lines = f.readlines() + try: + node = ast.parse(file_lines[line - 1].strip()) + except(SyntaxError) as e: + return None + + return node + +def parse_file(file: str): + with open(file, "r") as f: + source = f.read() + + return ast.parse(source) \ No newline at end of file diff --git a/src-combined/utils/code_smells.py b/src-combined/utils/code_smells.py new file mode 100644 index 00000000..0a9391bd --- /dev/null +++ b/src-combined/utils/code_smells.py @@ -0,0 +1,22 @@ +from enum import Enum + +class ExtendedEnum(Enum): + + @classmethod + def list(cls) -> list[str]: + return [c.value for c in cls] + +class CodeSmells(ExtendedEnum): + # Add codes here + LINE_TOO_LONG = "C0301" + LONG_MESSAGE_CHAIN = "R0914" + LONG_LAMBDA_FUNC = "R0914" + LONG_TERN_EXPR = "CUST-1" + # "R0902": LargeClassRefactorer, # Too many instance attributes + # "R0913": "Long Parameter List", # Too many arguments + # "R0915": "Long Method", # Too many statements + # "C0200": "Complex List Comprehension", # Loop can be simplified + # "C0103": "Invalid Naming Convention", # Non-standard names + + def __str__(self): + return str(self.value) diff --git a/src-combined/utils/factory.py b/src-combined/utils/factory.py new file mode 100644 index 00000000..a60628b4 --- /dev/null +++ b/src-combined/utils/factory.py @@ -0,0 +1,23 @@ +from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer as LLFR +from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer as LMCR +from refactorer.long_ternary_cond_expression import LTCERefactorer as LTCER + +from refactorer.base_refactorer import BaseRefactorer + +from utils.code_smells import CodeSmells + +class RefactorerFactory(): + + @staticmethod + def build(smell_name: str, file_path: str) -> BaseRefactorer: + selected = None + match smell_name: + case CodeSmells.LONG_LAMBDA_FUNC: + selected = LLFR(file_path) + case CodeSmells.LONG_MESSAGE_CHAIN: + selected = LMCR(file_path) + case CodeSmells.LONG_TERN_EXPR: + selected = LTCER(file_path) + case _: + raise ValueError(smell_name) + return selected \ No newline at end of file diff --git a/src-combined/utils/logger.py b/src-combined/utils/logger.py new file mode 100644 index 00000000..711c62b5 --- /dev/null +++ b/src-combined/utils/logger.py @@ -0,0 +1,34 @@ +import logging +import os + +def setup_logger(log_file: str = "app.log", log_level: int = logging.INFO): + """ + Set up the logger configuration. + + Args: + log_file (str): The name of the log file to write logs to. + log_level (int): The logging level (default is INFO). + + Returns: + Logger: Configured logger instance. + """ + # Create log directory if it does not exist + log_directory = os.path.dirname(log_file) + if log_directory and not os.path.exists(log_directory): + os.makedirs(log_directory) + + # Configure the logger + logging.basicConfig( + filename=log_file, + filemode='a', # Append mode + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=log_level, + ) + + logger = logging.getLogger(__name__) + return logger + +# # Example usage +# if __name__ == "__main__": +# logger = setup_logger() # You can customize the log file and level here +# logger.info("Logger is set up and ready to use.") diff --git a/src1/__init__.py b/src1/__init__.py new file mode 100644 index 00000000..d33da8e1 --- /dev/null +++ b/src1/__init__.py @@ -0,0 +1,2 @@ +from . import analyzers +from . import utils \ No newline at end of file diff --git a/src1/analyzers/code_smells/pylint_all_smells.json b/src1/analyzers/code_smells/pylint_all_smells.json index 56fdd87b..a6098500 100644 --- a/src1/analyzers/code_smells/pylint_all_smells.json +++ b/src1/analyzers/code_smells/pylint_all_smells.json @@ -8,7 +8,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -21,7 +21,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -34,7 +34,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -47,7 +47,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -60,7 +60,7 @@ "message-id": "C0114", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-module-docstring", "type": "convention" }, @@ -73,7 +73,7 @@ "message-id": "C0115", "module": "ineffcient_code_example_1", "obj": "DataProcessor", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-class-docstring", "type": "convention" }, @@ -86,7 +86,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "DataProcessor.process_all_data", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -99,7 +99,7 @@ "message-id": "W0718", "module": "ineffcient_code_example_1", "obj": "DataProcessor.process_all_data", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "broad-exception-caught", "type": "warning" }, @@ -112,7 +112,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -125,7 +125,7 @@ "message-id": "R0913", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "too-many-arguments", "type": "refactor" }, @@ -138,7 +138,7 @@ "message-id": "R0917", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "too-many-positional-arguments", "type": "refactor" }, @@ -151,7 +151,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "unused-argument", "type": "warning" }, @@ -164,7 +164,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "unused-argument", "type": "warning" }, @@ -177,7 +177,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "unused-argument", "type": "warning" }, @@ -190,7 +190,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "unused-argument", "type": "warning" }, @@ -203,7 +203,7 @@ "message-id": "C0115", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-class-docstring", "type": "convention" }, @@ -216,7 +216,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.check_data", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -229,7 +229,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.complex_comprehension", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -242,7 +242,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.long_chain", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -255,7 +255,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -268,7 +268,7 @@ "message-id": "R0912", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "too-many-branches", "type": "refactor" }, @@ -281,7 +281,7 @@ "message-id": "R1702", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "too-many-nested-blocks", "type": "refactor" }, @@ -294,7 +294,7 @@ "message-id": "R1710", "module": "ineffcient_code_example_1", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "inconsistent-return-statements", "type": "refactor" } diff --git a/src1/analyzers/code_smells/pylint_configured_smells.json b/src1/analyzers/code_smells/pylint_configured_smells.json index baf46488..f15204fd 100644 --- a/src1/analyzers/code_smells/pylint_configured_smells.json +++ b/src1/analyzers/code_smells/pylint_configured_smells.json @@ -8,7 +8,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -21,7 +21,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -34,7 +34,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -47,7 +47,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -60,7 +60,7 @@ "message-id": "R0913", "module": "ineffcient_code_example_1", "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "too-many-arguments", "type": "refactor" } diff --git a/src1/analyzers/code_smells/pylint_line_too_long_smells.json b/src1/analyzers/code_smells/pylint_line_too_long_smells.json index ec3fbe04..870a4ac6 100644 --- a/src1/analyzers/code_smells/pylint_line_too_long_smells.json +++ b/src1/analyzers/code_smells/pylint_line_too_long_smells.json @@ -8,7 +8,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -21,7 +21,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -34,7 +34,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" }, @@ -47,7 +47,7 @@ "message-id": "C0301", "module": "ineffcient_code_example_1", "obj": "", - "path": "C:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", "symbol": "line-too-long", "type": "convention" } From 35556e19e3b93fa926339d22d8eadd04e357c464 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:14:15 -0500 Subject: [PATCH 031/105] Refactored src folder Co-authored-by: Nivetha Kuruparan --- src-combined/analyzers/base_analyzer.py | 38 +- src-combined/analyzers/pylint_analyzer.py | 80 ++-- src-combined/main.py | 67 ++- src-combined/measurement/code_carbon_meter.py | 6 +- src-combined/output/initial_carbon_report.csv | 16 +- src-combined/output/pylint_all_smells.json | 437 ++++++++++++++++++ .../output/pylint_configured_smells.json | 32 ++ src-combined/utils/analyzers_config.py | 19 +- src-combined/utils/factory.py | 10 +- 9 files changed, 631 insertions(+), 74 deletions(-) create mode 100644 src-combined/output/pylint_all_smells.json create mode 100644 src-combined/output/pylint_configured_smells.json diff --git a/src-combined/analyzers/base_analyzer.py b/src-combined/analyzers/base_analyzer.py index 25840b46..af6a9f34 100644 --- a/src-combined/analyzers/base_analyzer.py +++ b/src-combined/analyzers/base_analyzer.py @@ -1,11 +1,37 @@ -from abc import ABC, abstractmethod +from abc import ABC import os +class Analyzer(ABC): + """ + Base class for different types of analyzers. + """ + def __init__(self, file_path: str): + """ + Initializes the analyzer with a file path. -class BaseAnalyzer(ABC): - def __init__(self, code_path: str): - self.code_path = os.path.abspath(code_path) + :param file_path: Path to the file to be analyzed. + """ + self.file_path = os.path.abspath(file_path) + self.report_data: list[object] = [] + + def validate_file(self): + """ + Checks if the file path exists and is a file. + + :return: Boolean indicating file validity. + """ + return os.path.isfile(self.file_path) - @abstractmethod def analyze(self): - pass + """ + Abstract method to be implemented by subclasses to perform analysis. + """ + raise NotImplementedError("Subclasses must implement this method.") + + def get_all_detected_smells(self): + """ + Retrieves all detected smells from the report data. + + :return: List of all detected code smells. + """ + return self.report_data diff --git a/src-combined/analyzers/pylint_analyzer.py b/src-combined/analyzers/pylint_analyzer.py index 3c36d055..a2c27530 100644 --- a/src-combined/analyzers/pylint_analyzer.py +++ b/src-combined/analyzers/pylint_analyzer.py @@ -1,6 +1,7 @@ import json from io import StringIO import ast +from re import sub # ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN # you will need to change imports too # ====================================================== @@ -15,51 +16,61 @@ from pylint.lint import Run from pylint.reporters.json_reporter import JSON2Reporter -from analyzers.base_analyzer import BaseAnalyzer +from analyzers.base_analyzer import Analyzer -from utils.analyzers_config import CustomSmell, PylintSmell +from utils.analyzers_config import EXTRA_PYLINT_OPTIONS, CustomSmell, PylintSmell from utils.analyzers_config import IntermediateSmells from utils.ast_parser import parse_line -class PylintAnalyzer(BaseAnalyzer): +class PylintAnalyzer(Analyzer): def __init__(self, code_path: str): super().__init__(code_path) + + def build_pylint_options(self): + """ + Constructs the list of pylint options for analysis, including extra options from config. + + :return: List of pylint options for analysis. + """ + return [self.file_path] + EXTRA_PYLINT_OPTIONS def analyze(self): """ - Runs pylint on the specified Python file and returns the output as a list of dictionaries. - Each dictionary contains information about a code smell or warning identified by pylint. - - :param file_path: The path to the Python file to be analyzed. - :return: A list of dictionaries with pylint messages. + Executes pylint on the specified file and captures the output in JSON format. """ - # Capture pylint output into a string stream - output_stream = StringIO() - reporter = JSON2Reporter(output_stream) - - # Run pylint - Run(["--max-line-length=80", "--max-nested-blocks=3", "--max-branches=3", "--max-parents=3", self.code_path], reporter=reporter, exit=False) - - # Retrieve and parse output as JSON - output = output_stream.getvalue() - - try: - pylint_results: list[object] = json.loads(output) - except json.JSONDecodeError: - print("Error: Could not decode pylint output") - pylint_results = [] - - return pylint_results - - def filter_for_all_wanted_code_smells(self, pylint_results: list[object]): + if not self.validate_file(): + print(f"File not found: {self.file_path}") + return + + print(f"Running pylint analysis on {self.file_path}") + + # Capture pylint output in a JSON format buffer + with StringIO() as buffer: + reporter = JSON2Reporter(buffer) + pylint_options = self.build_pylint_options() + + try: + # Run pylint with JSONReporter + Run(pylint_options, reporter=reporter, exit=False) + + # Parse the JSON output + buffer.seek(0) + self.report_data = json.loads(buffer.getvalue()) + print("Pylint JSON analysis completed.") + except json.JSONDecodeError as e: + print("Failed to parse JSON output from pylint:", e) + except Exception as e: + print("An error occurred during pylint analysis:", e) + + def get_configured_smells(self): filtered_results: list[object] = [] - for error in pylint_results: + for error in self.report_data["messages"]: if error["messageId"] in PylintSmell.list(): filtered_results.append(error) for smell in IntermediateSmells.list(): - temp_smells = self.filter_for_one_code_smell(pylint_results, smell) + temp_smells = self.filter_for_one_code_smell(self.report_data["messages"], smell) if smell == IntermediateSmells.LINE_TOO_LONG.value: filtered_results.extend(self.filter_long_lines(temp_smells)) @@ -80,21 +91,16 @@ def filter_for_one_code_smell(self, pylint_results: list[object], code: str): def filter_long_lines(self, long_line_smells: list[object]): selected_smells: list[object] = [] for smell in long_line_smells: - root_node = parse_line(self.code_path, smell["line"]) + root_node = parse_line(self.file_path, smell["line"]) if root_node is None: continue for node in ast.walk(root_node): - if isinstance(node, ast.Expr): - for expr in ast.walk(node): - if isinstance(expr, ast.IfExp): # Ternary expression node - smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value - selected_smells.append(smell) - if isinstance(node, ast.IfExp): # Ternary expression node smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value - selected_smells.append(smell)\ + selected_smells.append(smell) + break return selected_smells diff --git a/src-combined/main.py b/src-combined/main.py index 7a79d364..3a1a6726 100644 --- a/src-combined/main.py +++ b/src-combined/main.py @@ -1,10 +1,47 @@ +import json import os +import sys from analyzers.pylint_analyzer import PylintAnalyzer from measurement.code_carbon_meter import CarbonAnalyzer from utils.factory import RefactorerFactory -dirname = os.path.dirname(__file__) +DIRNAME = os.path.dirname(__file__) + +# Define the output folder within the analyzers package +OUTPUT_FOLDER = os.path.join(DIRNAME, 'output/') + +# Ensure the output folder exists +os.makedirs(OUTPUT_FOLDER, exist_ok=True) + +def save_to_file(data, filename): + """ + Saves JSON data to a file in the output folder. + + :param data: Data to be saved. + :param filename: Name of the file to save data to. + """ + filepath = os.path.join(OUTPUT_FOLDER, filename) + with open(filepath, 'w+') as file: + json.dump(data, file, sort_keys=True, indent=4) + print(f"Output saved to {filepath.removeprefix(DIRNAME)}") + +def run_pylint_analysis(test_file_path): + print("\nStarting pylint analysis...") + + # Create an instance of PylintAnalyzer and run analysis + pylint_analyzer = PylintAnalyzer(test_file_path) + pylint_analyzer.analyze() + + # Save all detected smells to file + all_smells = pylint_analyzer.get_all_detected_smells() + save_to_file(all_smells["messages"], 'pylint_all_smells.json') + + # Example: Save only configured smells to file + configured_smells = pylint_analyzer.get_configured_smells() + save_to_file(configured_smells, 'pylint_configured_smells.json') + + return configured_smells def main(): """ @@ -13,25 +50,33 @@ def main(): - Perform code analysis and print the results. """ - # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug - TEST_FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") - INITIAL_REPORT_FILE_PATH = os.path.join(dirname, "output/initial_carbon_report.csv") + # Get the file path from command-line arguments if provided, otherwise use the default + DEFAULT_TEST_FILE = os.path.join(DIRNAME, "../test/inefficent_code_example.py") + TEST_FILE = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_TEST_FILE - carbon_analyzer = CarbonAnalyzer(TEST_FILE_PATH) + # Check if the test file exists + if not os.path.isfile(TEST_FILE): + print(f"Error: The file '{TEST_FILE}' does not exist.") + return + + INITIAL_REPORT_FILE_PATH = os.path.join(OUTPUT_FOLDER, "initial_carbon_report.csv") + + carbon_analyzer = CarbonAnalyzer(TEST_FILE) carbon_analyzer.run_and_measure() carbon_analyzer.save_report(INITIAL_REPORT_FILE_PATH) - - analyzer = PylintAnalyzer(TEST_FILE_PATH) - report = analyzer.analyze() - detected_smells = analyzer.filter_for_all_wanted_code_smells(report["messages"]) + detected_smells = run_pylint_analysis(TEST_FILE) for smell in detected_smells: smell_id: str = smell["messageId"] print("Refactoring ", smell_id) - refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE_PATH) - refactoring_class.refactor() + refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE) + + if refactoring_class: + refactoring_class.refactor() + else: + raise NotImplementedError("This refactoring has not been implemented yet.") if __name__ == "__main__": diff --git a/src-combined/measurement/code_carbon_meter.py b/src-combined/measurement/code_carbon_meter.py index a60ed932..f96f240b 100644 --- a/src-combined/measurement/code_carbon_meter.py +++ b/src-combined/measurement/code_carbon_meter.py @@ -5,9 +5,6 @@ import pandas as pd from os.path import dirname, abspath -REFACTOR_DIR = dirname(abspath(__file__)) -sys.path.append(dirname(REFACTOR_DIR)) - class CarbonAnalyzer: def __init__(self, script_path: str): self.script_path = script_path @@ -55,6 +52,9 @@ def save_report(self, report_path: str): # Example usage if __name__ == "__main__": + REFACTOR_DIR = dirname(abspath(__file__)) + sys.path.append(dirname(REFACTOR_DIR)) + analyzer = CarbonAnalyzer("src/output/inefficent_code_example.py") analyzer.run_and_measure() analyzer.save_report("src/output/test/carbon_report.csv") diff --git a/src-combined/output/initial_carbon_report.csv b/src-combined/output/initial_carbon_report.csv index f9ed7451..d8679a2d 100644 --- a/src-combined/output/initial_carbon_report.csv +++ b/src-combined/output/initial_carbon_report.csv @@ -1,18 +1,18 @@ Attribute,Value -timestamp,2024-11-07T11:29:20 +timestamp,2024-11-07T14:12:05 project_name,codecarbon -run_id,2d6d643f-acbc-49b4-8627-e46fe95bdf92 +run_id,bf175e4d-2118-497c-a6b8-cbaf00eee02d experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,0.14742779999505728 -emissions,2.0976451367814492e-08 -emissions_rate,1.4228287587902522e-07 +duration,0.1537123000016436 +emissions,2.213841482744185e-08 +emissions_rate,1.4402500533272308e-07 cpu_power,7.5 gpu_power,0.0 ram_power,6.730809688568115 -cpu_energy,3.0441354174399747e-07 +cpu_energy,3.177435416243194e-07 gpu_energy,0 -ram_energy,2.2668357414780443e-07 -energy_consumed,5.310971158918019e-07 +ram_energy,2.427730137789067e-07 +energy_consumed,5.605165554032261e-07 country_name,Canada country_iso_code,CAN region,ontario diff --git a/src-combined/output/pylint_all_smells.json b/src-combined/output/pylint_all_smells.json new file mode 100644 index 00000000..3f3e1cfb --- /dev/null +++ b/src-combined/output/pylint_all_smells.json @@ -0,0 +1,437 @@ +[ + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 19, + "message": "Line too long (87/80)", + "messageId": "C0301", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 41, + "message": "Line too long (87/80)", + "messageId": "C0301", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 57, + "message": "Line too long (85/80)", + "messageId": "C0301", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 74, + "message": "Line too long (86/80)", + "messageId": "C0301", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "HIGH", + "endColumn": null, + "endLine": null, + "line": 1, + "message": "Missing module docstring", + "messageId": "C0114", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-module-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "HIGH", + "endColumn": 19, + "endLine": 2, + "line": 2, + "message": "Missing class docstring", + "messageId": "C0115", + "module": "inefficent_code_example", + "obj": "DataProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 24, + "endLine": 8, + "line": 8, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 16, + "confidence": "INFERENCE", + "endColumn": 25, + "endLine": 18, + "line": 18, + "message": "Catching too general exception Exception", + "messageId": "W0718", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "broad-exception-caught", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 25, + "confidence": "INFERENCE", + "endColumn": 49, + "endLine": 13, + "line": 13, + "message": "Instance of 'DataProcessor' has no 'complex_calculation' member", + "messageId": "E1101", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "no-member", + "type": "error" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 29, + "confidence": "UNDEFINED", + "endColumn": 38, + "endLine": 27, + "line": 27, + "message": "Comparison 'x != None' should be 'x is not None'", + "messageId": "C0121", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data.", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "singleton-comparison", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": 19, + "endLine": 2, + "line": 2, + "message": "Too few public methods (1/2)", + "messageId": "R0903", + "module": "inefficent_code_example", + "obj": "DataProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-few-public-methods", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "HIGH", + "endColumn": 23, + "endLine": 35, + "line": 35, + "message": "Missing class docstring", + "messageId": "C0115", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": 23, + "endLine": 35, + "line": 35, + "message": "Class 'AdvancedProcessor' inherits from object, can be safely removed from bases in python3", + "messageId": "R0205", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "useless-object-inheritance", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": 23, + "endLine": 35, + "line": 35, + "message": "Inconsistent method resolution order for class 'AdvancedProcessor'", + "messageId": "E0240", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "inconsistent-mro", + "type": "error" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "UNDEFINED", + "endColumn": 8, + "endLine": 36, + "line": 36, + "message": "Unnecessary pass statement", + "messageId": "W0107", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "unnecessary-pass", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 18, + "endLine": 39, + "line": 39, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.check_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 29, + "endLine": 45, + "line": 45, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_comprehension", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 18, + "endLine": 54, + "line": 54, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.long_chain", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 27, + "endLine": 63, + "line": 63, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "UNDEFINED", + "endColumn": 27, + "endLine": 63, + "line": 63, + "message": "Too many branches (6/3)", + "messageId": "R0912", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-many-branches", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 8, + "confidence": "UNDEFINED", + "endColumn": 45, + "endLine": 70, + "line": 64, + "message": "Too many nested blocks (6/3)", + "messageId": "R1702", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-many-nested-blocks", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "UNDEFINED", + "endColumn": 27, + "endLine": 63, + "line": 63, + "message": "Either all return statements in a function should return an expression, or none of them should.", + "messageId": "R1710", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "inconsistent-return-statements", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "INFERENCE", + "endColumn": 27, + "endLine": 73, + "line": 73, + "message": "Missing function or method docstring", + "messageId": "C0116", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "UNDEFINED", + "endColumn": 27, + "endLine": 73, + "line": 73, + "message": "Too many arguments (9/5)", + "messageId": "R0913", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "HIGH", + "endColumn": 27, + "endLine": 73, + "line": 73, + "message": "Too many positional arguments (9/5)", + "messageId": "R0917", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-many-positional-arguments", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 20, + "confidence": "INFERENCE", + "endColumn": 25, + "endLine": 74, + "line": 74, + "message": "Unused argument 'flag1'", + "messageId": "W0613", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 27, + "confidence": "INFERENCE", + "endColumn": 32, + "endLine": 74, + "line": 74, + "message": "Unused argument 'flag2'", + "messageId": "W0613", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 67, + "confidence": "INFERENCE", + "endColumn": 73, + "endLine": 74, + "line": 74, + "message": "Unused argument 'option'", + "messageId": "W0613", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 75, + "confidence": "INFERENCE", + "endColumn": 86, + "endLine": 74, + "line": 74, + "message": "Unused argument 'final_stage'", + "messageId": "W0613", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "unused-argument", + "type": "warning" + } +] \ No newline at end of file diff --git a/src-combined/output/pylint_configured_smells.json b/src-combined/output/pylint_configured_smells.json new file mode 100644 index 00000000..256b1a84 --- /dev/null +++ b/src-combined/output/pylint_configured_smells.json @@ -0,0 +1,32 @@ +[ + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 4, + "confidence": "UNDEFINED", + "endColumn": 27, + "endLine": 73, + "line": 73, + "message": "Too many arguments (9/5)", + "messageId": "R0913", + "module": "inefficent_code_example", + "obj": "AdvancedProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "column": 0, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 41, + "message": "Line too long (87/80)", + "messageId": "CUST-1", + "module": "inefficent_code_example", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", + "symbol": "line-too-long", + "type": "convention" + } +] \ No newline at end of file diff --git a/src-combined/utils/analyzers_config.py b/src-combined/utils/analyzers_config.py index 12b875bf..d65c646d 100644 --- a/src-combined/utils/analyzers_config.py +++ b/src-combined/utils/analyzers_config.py @@ -1,12 +1,20 @@ # Any configurations that are done by the analyzers from enum import Enum +from itertools import chain class ExtendedEnum(Enum): @classmethod def list(cls) -> list[str]: return [c.value for c in cls] - + + def __str__(self): + return str(self.value) + +# ============================================= +# IMPORTANT +# ============================================= +# Make sure any new smells are added to the factory in this same directory class PylintSmell(ExtendedEnum): LONG_MESSAGE_CHAIN = "R0914" # pylint smell LARGE_CLASS = "R0902" # pylint smell @@ -22,9 +30,14 @@ class CustomSmell(ExtendedEnum): class IntermediateSmells(ExtendedEnum): LINE_TOO_LONG = "C0301" # pylint smell -AllSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, - **{s.name: s.value for s in CustomSmell}}) +# Enum containing a combination of all relevant smells +class AllSmells(ExtendedEnum): + _ignore_ = 'member cls' + cls = vars() + for member in chain(list(PylintSmell), list(CustomSmell)): + cls[member.name] = member.value +# List of all codes SMELL_CODES = [s.value for s in AllSmells] # Extra pylint options diff --git a/src-combined/utils/factory.py b/src-combined/utils/factory.py index a60628b4..6a915d7b 100644 --- a/src-combined/utils/factory.py +++ b/src-combined/utils/factory.py @@ -4,7 +4,7 @@ from refactorer.base_refactorer import BaseRefactorer -from utils.code_smells import CodeSmells +from utils.analyzers_config import CustomSmell, PylintSmell class RefactorerFactory(): @@ -12,12 +12,10 @@ class RefactorerFactory(): def build(smell_name: str, file_path: str) -> BaseRefactorer: selected = None match smell_name: - case CodeSmells.LONG_LAMBDA_FUNC: - selected = LLFR(file_path) - case CodeSmells.LONG_MESSAGE_CHAIN: + case PylintSmell.LONG_MESSAGE_CHAIN: selected = LMCR(file_path) - case CodeSmells.LONG_TERN_EXPR: + case CustomSmell.LONG_TERN_EXPR: selected = LTCER(file_path) case _: - raise ValueError(smell_name) + selected = None return selected \ No newline at end of file From 583db48a2ba18efc656d13ff5d840e7542c0f541 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:39:51 -0500 Subject: [PATCH 032/105] Revised POC - Modifed tests in src1-tests --- intel_power_gadget_log.csv | 31 ++ src1-tests/ineffcient_code_example_1.py | 99 ++---- src1-tests/ineffcient_code_example_2.py | 82 +++++ src1/__init__.py | 2 - src1/analyzers/__init__.py | 0 src1/analyzers/base_analyzer.py | 36 --- .../code_smells/pylint_all_smells.json | 301 ------------------ .../code_smells/pylint_configured_smells.json | 67 ---- .../pylint_line_too_long_smells.json | 54 ---- .../ternary_expressions_min_length_70.json | 7 - .../code_smells/ternary_long_expressions.json | 12 - src1/analyzers/main.py | 97 ------ src1/analyzers/pylint_analyzer.py | 69 ---- src1/analyzers/ternary_expression_analyzer.py | 69 ---- src1/utils/__init__.py | 0 src1/utils/analyzers_config.py | 25 -- 16 files changed, 138 insertions(+), 813 deletions(-) create mode 100644 intel_power_gadget_log.csv create mode 100644 src1-tests/ineffcient_code_example_2.py delete mode 100644 src1/__init__.py delete mode 100644 src1/analyzers/__init__.py delete mode 100644 src1/analyzers/base_analyzer.py delete mode 100644 src1/analyzers/code_smells/pylint_all_smells.json delete mode 100644 src1/analyzers/code_smells/pylint_configured_smells.json delete mode 100644 src1/analyzers/code_smells/pylint_line_too_long_smells.json delete mode 100644 src1/analyzers/code_smells/ternary_expressions_min_length_70.json delete mode 100644 src1/analyzers/code_smells/ternary_long_expressions.json delete mode 100644 src1/analyzers/main.py delete mode 100644 src1/analyzers/pylint_analyzer.py delete mode 100644 src1/analyzers/ternary_expression_analyzer.py delete mode 100644 src1/utils/__init__.py delete mode 100644 src1/utils/analyzers_config.py diff --git a/intel_power_gadget_log.csv b/intel_power_gadget_log.csv new file mode 100644 index 00000000..a04bbec4 --- /dev/null +++ b/intel_power_gadget_log.csv @@ -0,0 +1,31 @@ +System Time,RDTSC,Elapsed Time (sec), CPU Utilization(%),CPU Frequency_0(MHz),Processor Power_0(Watt),Cumulative Processor Energy_0(Joules),Cumulative Processor Energy_0(mWh),IA Power_0(Watt),Cumulative IA Energy_0(Joules),Cumulative IA Energy_0(mWh),Package Temperature_0(C),Package Hot_0,DRAM Power_0(Watt),Cumulative DRAM Energy_0(Joules),Cumulative DRAM Energy_0(mWh),GT Power_0(Watt),Cumulative GT Energy_0(Joules),Cumulative GT Energy_0(mWh),Package PL1_0(Watt),Package PL2_0(Watt),Package PL4_0(Watt),Platform PsysPL1_0(Watt),Platform PsysPL2_0(Watt),GT Frequency(MHz),GT Utilization(%) +02:50:20:527, 291193296011688, 0.108, 11.000, 4200, 33.104, 3.559, 0.989, 27.944, 3.004, 0.834, 76, 0, 1.413, 0.152, 0.042, 0.064, 0.007, 0.002, 107.000, 107.000, 163.000, 0.000, 0.000, 773, 13.086 +02:50:20:635, 291193576924645, 0.216, 9.000, 800, 24.641, 6.229, 1.730, 19.881, 5.159, 1.433, 67, 0, 1.125, 0.274, 0.076, 0.023, 0.009, 0.003, 107.000, 107.000, 163.000, 0.000, 0.000, 7, 0.000 +02:50:20:744, 291193860019214, 0.325, 4.000, 800, 11.792, 7.517, 2.088, 7.184, 5.943, 1.651, 64, 0, 0.684, 0.348, 0.097, 0.048, 0.015, 0.004, 107.000, 107.000, 163.000, 0.000, 0.000, 16, 0.000 +02:50:20:853, 291194141601618, 0.434, 6.000, 800, 10.289, 8.635, 2.399, 5.716, 6.564, 1.823, 62, 0, 0.727, 0.427, 0.119, 0.033, 0.018, 0.005, 107.000, 107.000, 163.000, 0.000, 0.000, 12, 0.000 +02:50:20:961, 291194421832739, 0.542, 7.000, 4300, 14.041, 10.153, 2.820, 9.482, 7.589, 2.108, 64, 0, 0.777, 0.511, 0.142, 0.034, 0.022, 0.006, 107.000, 107.000, 163.000, 0.000, 0.000, 12, 0.000 +02:50:21:068, 291194700236744, 0.649, 5.000, 4300, 11.539, 11.392, 3.165, 6.964, 8.337, 2.316, 62, 0, 0.733, 0.590, 0.164, 0.025, 0.025, 0.007, 107.000, 107.000, 163.000, 0.000, 0.000, 7, 0.000 +02:50:21:178, 291194985171256, 0.759, 6.000, 4300, 8.379, 12.313, 3.420, 3.835, 8.759, 2.433, 60, 0, 0.722, 0.670, 0.186, 0.013, 0.026, 0.007, 107.000, 107.000, 163.000, 0.000, 0.000, 7, 0.000 +02:50:21:288, 291195268975634, 0.869, 6.000, 800, 12.457, 13.677, 3.799, 7.888, 9.623, 2.673, 61, 0, 0.804, 0.758, 0.210, 0.018, 0.028, 0.008, 107.000, 107.000, 163.000, 0.000, 0.000, 7, 0.000 +02:50:21:397, 291195551604850, 0.978, 4.000, 3600, 9.805, 14.747, 4.096, 5.285, 10.199, 2.833, 60, 0, 0.696, 0.833, 0.232, 0.032, 0.031, 0.009, 107.000, 107.000, 163.000, 0.000, 0.000, 12, 0.000 +02:50:21:506, 291195833298384, 1.086, 15.000, 4200, 24.585, 17.418, 4.838, 20.089, 12.382, 3.439, 76, 0, 1.245, 0.969, 0.269, 0.025, 0.034, 0.009, 107.000, 107.000, 163.000, 0.000, 0.000, 7, 0.000 +02:50:21:515, 291195856417502, 1.095, 58.000, 4300, 48.989, 17.855, 4.960, 43.302, 12.768, 3.547, 78, 0, 1.225, 0.980, 0.272, 0.164, 0.036, 0.010, 107.000, 107.000, 163.000, 0.000, 0.000, 2, 0.000 + +Total Elapsed Time (sec) = 1.095316 +Measured RDTSC Frequency (GHz) = 2.592 + +Cumulative Processor Energy_0 (Joules) = 17.855347 +Cumulative Processor Energy_0 (mWh) = 4.959819 +Average Processor Power_0 (Watt) = 16.301554 + +Cumulative IA Energy_0 (Joules) = 12.768311 +Cumulative IA Energy_0 (mWh) = 3.546753 +Average IA Power_0 (Watt) = 11.657197 + +Cumulative DRAM Energy_0 (Joules) = 0.979736 +Cumulative DRAM Energy_0 (mWh) = 0.272149 +Average DRAM Power_0 (Watt) = 0.894479 + +Cumulative GT Energy_0 (Joules) = 0.035645 +Cumulative GT Energy_0 (mWh) = 0.009901 +Average GT Power_0 (Watt) = 0.032543 diff --git a/src1-tests/ineffcient_code_example_1.py b/src1-tests/ineffcient_code_example_1.py index afc6a6bd..2053b7ed 100644 --- a/src1-tests/ineffcient_code_example_1.py +++ b/src1-tests/ineffcient_code_example_1.py @@ -1,82 +1,33 @@ -# LC: Large Class with too many responsibilities -class DataProcessor: - def __init__(self, data): - self.data = data - self.processed_data = [] +# Should trigger Use A Generator code smells - # LM: Long Method - this method does way too much - def process_all_data(self): - results = [] - for item in self.data: - try: - # LPL: Long Parameter List - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) - results.append(result) - except Exception as e: # UEH: Unqualified Exception Handling - print("An error occurred:", e) +def has_positive(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num > 0 for num in numbers]) - # LMC: Long Message Chain - if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(" ", "_").lower()) +def all_non_negative(numbers): + # List comprehension inside `all()` - triggers R1729 + return all([num >= 0 for num in numbers]) - # LLF: Long Lambda Function - self.processed_data = list( - filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) - ) +def contains_large_strings(strings): + # List comprehension inside `any()` - triggers R1729 + return any([len(s) > 10 for s in strings]) - return self.processed_data +def all_uppercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.isupper() for s in strings]) - # Moved the complex_calculation method here - def complex_calculation( - self, item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": - result = item * threshold - elif operation == "add": - result = item + max_value - else: - result = item - return result +def contains_special_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 5 == 0 and num > 100 for num in numbers]) +def all_lowercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.islower() for s in strings]) -class AdvancedProcessor(DataProcessor): - # LTCE: Long Ternary Conditional Expression - def check_data(self, item): - return True if item > 10 else False if item < -10 else None if item == 0 else item +def any_even_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 2 == 0 for num in numbers]) - # Complex List Comprehension - def complex_comprehension(self): - # CLC: Complex List Comprehension - self.processed_data = [ - x**2 if x % 2 == 0 else x**3 - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] - - # Long Element Chain - def long_chain(self): - try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] - return deep_value - except (KeyError, IndexError, TypeError): - return None - - # Long Scope Chaining (LSC) - def long_scope_chaining(self): - for a in range(10): - for b in range(10): - for c in range(10): - for d in range(10): - for e in range(10): - if a + b + c + d + e > 25: - return "Done" - - -# Main method to execute the code -if __name__ == "__main__": - sample_data = [1, 2, 3, 4, 5] - processor = DataProcessor(sample_data) - processed = processor.process_all_data() - print("Processed Data:", processed) +def all_strings_start_with_a(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.startswith('A') for s in strings]) \ No newline at end of file diff --git a/src1-tests/ineffcient_code_example_2.py b/src1-tests/ineffcient_code_example_2.py new file mode 100644 index 00000000..afc6a6bd --- /dev/null +++ b/src1-tests/ineffcient_code_example_2.py @@ -0,0 +1,82 @@ +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] + + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except Exception as e: # UEH: Unqualified Exception Handling + print("An error occurred:", e) + + # LMC: Long Message Chain + if isinstance(self.data[0], str): + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) + ) + + return self.processed_data + + # Moved the complex_calculation method here + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result + + +class AdvancedProcessor(DataProcessor): + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return True if item > 10 else False if item < -10 else None if item == 0 else item + + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except (KeyError, IndexError, TypeError): + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) diff --git a/src1/__init__.py b/src1/__init__.py deleted file mode 100644 index d33da8e1..00000000 --- a/src1/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from . import analyzers -from . import utils \ No newline at end of file diff --git a/src1/analyzers/__init__.py b/src1/analyzers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src1/analyzers/base_analyzer.py b/src1/analyzers/base_analyzer.py deleted file mode 100644 index c2f9f199..00000000 --- a/src1/analyzers/base_analyzer.py +++ /dev/null @@ -1,36 +0,0 @@ -import os - -class Analyzer: - """ - Base class for different types of analyzers. - """ - def __init__(self, file_path): - """ - Initializes the analyzer with a file path. - - :param file_path: Path to the file to be analyzed. - """ - self.file_path = file_path - self.report_data = [] - - def validate_file(self): - """ - Checks if the file path exists and is a file. - - :return: Boolean indicating file validity. - """ - return os.path.isfile(self.file_path) - - def analyze(self): - """ - Abstract method to be implemented by subclasses to perform analysis. - """ - raise NotImplementedError("Subclasses must implement this method.") - - def get_all_detected_smells(self): - """ - Retrieves all detected smells from the report data. - - :return: List of all detected code smells. - """ - return self.report_data diff --git a/src1/analyzers/code_smells/pylint_all_smells.json b/src1/analyzers/code_smells/pylint_all_smells.json deleted file mode 100644 index a6098500..00000000 --- a/src1/analyzers/code_smells/pylint_all_smells.json +++ /dev/null @@ -1,301 +0,0 @@ -[ - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 26, - "message": "Line too long (83/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 33, - "message": "Line too long (86/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 47, - "message": "Line too long (90/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 61, - "message": "Line too long (85/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 1, - "message": "Missing module docstring", - "message-id": "C0114", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-module-docstring", - "type": "convention" - }, - { - "column": 0, - "endColumn": 19, - "endLine": 2, - "line": 2, - "message": "Missing class docstring", - "message-id": "C0115", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 24, - "endLine": 8, - "line": 8, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.process_all_data", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 19, - "endColumn": 28, - "endLine": 17, - "line": 17, - "message": "Catching too general exception Exception", - "message-id": "W0718", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.process_all_data", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "broad-exception-caught", - "type": "warning" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 32, - "line": 32, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 32, - "line": 32, - "message": "Too many arguments (9/5)", - "message-id": "R0913", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 32, - "line": 32, - "message": "Too many positional arguments (9/5)", - "message-id": "R0917", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "too-many-positional-arguments", - "type": "refactor" - }, - { - "column": 20, - "endColumn": 25, - "endLine": 33, - "line": 33, - "message": "Unused argument 'flag1'", - "message-id": "W0613", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 27, - "endColumn": 32, - "endLine": 33, - "line": 33, - "message": "Unused argument 'flag2'", - "message-id": "W0613", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 67, - "endColumn": 73, - "endLine": 33, - "line": 33, - "message": "Unused argument 'option'", - "message-id": "W0613", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 75, - "endColumn": 86, - "endLine": 33, - "line": 33, - "message": "Unused argument 'final_stage'", - "message-id": "W0613", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 0, - "endColumn": 23, - "endLine": 44, - "line": 44, - "message": "Missing class docstring", - "message-id": "C0115", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 18, - "endLine": 46, - "line": 46, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.check_data", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 29, - "endLine": 50, - "line": 50, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.complex_comprehension", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 18, - "endLine": 59, - "line": 59, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.long_chain", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 67, - "line": 67, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 67, - "line": 67, - "message": "Too many branches (6/3)", - "message-id": "R0912", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "too-many-branches", - "type": "refactor" - }, - { - "column": 8, - "endColumn": 45, - "endLine": 74, - "line": 68, - "message": "Too many nested blocks (6/3)", - "message-id": "R1702", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "too-many-nested-blocks", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 67, - "line": 67, - "message": "Either all return statements in a function should return an expression, or none of them should.", - "message-id": "R1710", - "module": "ineffcient_code_example_1", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "inconsistent-return-statements", - "type": "refactor" - } -] \ No newline at end of file diff --git a/src1/analyzers/code_smells/pylint_configured_smells.json b/src1/analyzers/code_smells/pylint_configured_smells.json deleted file mode 100644 index f15204fd..00000000 --- a/src1/analyzers/code_smells/pylint_configured_smells.json +++ /dev/null @@ -1,67 +0,0 @@ -[ - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 26, - "message": "Line too long (83/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 33, - "message": "Line too long (86/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 47, - "message": "Line too long (90/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 61, - "message": "Line too long (85/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 32, - "line": 32, - "message": "Too many arguments (9/5)", - "message-id": "R0913", - "module": "ineffcient_code_example_1", - "obj": "DataProcessor.complex_calculation", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "too-many-arguments", - "type": "refactor" - } -] \ No newline at end of file diff --git a/src1/analyzers/code_smells/pylint_line_too_long_smells.json b/src1/analyzers/code_smells/pylint_line_too_long_smells.json deleted file mode 100644 index 870a4ac6..00000000 --- a/src1/analyzers/code_smells/pylint_line_too_long_smells.json +++ /dev/null @@ -1,54 +0,0 @@ -[ - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 26, - "message": "Line too long (83/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 33, - "message": "Line too long (86/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 47, - "message": "Line too long (90/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 61, - "message": "Line too long (85/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "C:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", - "symbol": "line-too-long", - "type": "convention" - } -] \ No newline at end of file diff --git a/src1/analyzers/code_smells/ternary_expressions_min_length_70.json b/src1/analyzers/code_smells/ternary_expressions_min_length_70.json deleted file mode 100644 index 69eb4f43..00000000 --- a/src1/analyzers/code_smells/ternary_expressions_min_length_70.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "expression": "True if item > 10 else False if item < -10 else None if item == 0 else item", - "length": 75, - "line": 47 - } -] \ No newline at end of file diff --git a/src1/analyzers/code_smells/ternary_long_expressions.json b/src1/analyzers/code_smells/ternary_long_expressions.json deleted file mode 100644 index 80bd2eda..00000000 --- a/src1/analyzers/code_smells/ternary_long_expressions.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "expression": "True if item > 10 else False if item < -10 else None if item == 0 else item", - "length": 75, - "line": 47 - }, - { - "expression": "False if item < -10 else None if item == 0 else item", - "length": 52, - "line": 47 - } -] \ No newline at end of file diff --git a/src1/analyzers/main.py b/src1/analyzers/main.py deleted file mode 100644 index d42e5b07..00000000 --- a/src1/analyzers/main.py +++ /dev/null @@ -1,97 +0,0 @@ -""" -A simple main.py to demonstrate the usage of various functions in the analyzer classes. -This script runs different analyzers and outputs results as JSON files in the `main_output` -folder. This helps to understand how the analyzers work and allows viewing the details of -detected code smells and configured refactorable smells. - -Each output JSON file provides insight into the raw data returned by PyLint and custom analyzers, -which is useful for debugging and verifying functionality. Note: In the final implementation, -we may not output these JSON files, but they are useful for demonstration purposes. - -INSTRUCTIONS TO RUN THIS FILE: -1. Change directory to the `src` folder: cd src -2. Run the script using the following command: python -m analyzers.main -3. Optional: Specify a test file path (absolute path) as an argument to override the default test case -(`inefficient_code_example_1.py`). For example: python -m analyzers.main -""" - -import os -import json -import sys -from analyzers.pylint_analyzer import PylintAnalyzer -from analyzers.ternary_expression_analyzer import TernaryExpressionAnalyzer -from utils.analyzers_config import AllSmells - -# Define the output folder within the analyzers package -OUTPUT_FOLDER = os.path.join(os.path.dirname(__file__), 'code_smells') - -# Ensure the output folder exists -os.makedirs(OUTPUT_FOLDER, exist_ok=True) - -def save_to_file(data, filename): - """ - Saves JSON data to a file in the output folder. - - :param data: Data to be saved. - :param filename: Name of the file to save data to. - """ - filepath = os.path.join(OUTPUT_FOLDER, filename) - with open(filepath, 'w') as file: - json.dump(data, file, sort_keys=True, indent=4) - print(f"Output saved to {filepath}") - -def run_pylint_analysis(file_path): - print("\nStarting pylint analysis...") - - # Create an instance of PylintAnalyzer and run analysis - pylint_analyzer = PylintAnalyzer(file_path) - pylint_analyzer.analyze() - - # Save all detected smells to file - all_smells = pylint_analyzer.get_all_detected_smells() - save_to_file(all_smells, 'pylint_all_smells.json') - - # Example: Save only configured smells to file - configured_smells = pylint_analyzer.get_configured_smells() - save_to_file(configured_smells, 'pylint_configured_smells.json') - - # Example: Save smells specific to "LINE_TOO_LONG" - line_too_long_smells = pylint_analyzer.get_smells_by_name(AllSmells.LINE_TOO_LONG) - save_to_file(line_too_long_smells, 'pylint_line_too_long_smells.json') - - -def run_ternary_expression_analysis(file_path, max_length=50): - print("\nStarting ternary expression analysis...") - - # Create an instance of TernaryExpressionAnalyzer and run analysis - ternary_analyzer = TernaryExpressionAnalyzer(file_path, max_length) - ternary_analyzer.analyze() - - # Save all long ternary expressions to file - long_expressions = ternary_analyzer.get_all_detected_smells() - save_to_file(long_expressions, 'ternary_long_expressions.json') - - # Example: Save filtered expressions based on a custom length threshold - min_length = 70 - filtered_expressions = ternary_analyzer.filter_expressions_by_length(min_length) - save_to_file(filtered_expressions, f'ternary_expressions_min_length_{min_length}.json') - - -def main(): - # Get the file path from command-line arguments if provided, otherwise use the default - default_test_file = os.path.join(os.path.dirname(__file__), "../../src1-tests/ineffcient_code_example_1.py") - test_file = sys.argv[1] if len(sys.argv) > 1 else default_test_file - - # Check if the file exists - if not os.path.isfile(test_file): - print(f"Error: The file '{test_file}' does not exist.") - return - - # Run examples of PylintAnalyzer usage - run_pylint_analysis(test_file) - - # Run examples of TernaryExpressionAnalyzer usage - run_ternary_expression_analysis(test_file, max_length=50) - -if __name__ == "__main__": - main() diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py deleted file mode 100644 index 2f4eef49..00000000 --- a/src1/analyzers/pylint_analyzer.py +++ /dev/null @@ -1,69 +0,0 @@ -import json -from pylint.lint import Run -from pylint.reporters.json_reporter import JSONReporter -from io import StringIO -from .base_analyzer import Analyzer -from utils.analyzers_config import PylintSmell, EXTRA_PYLINT_OPTIONS - -class PylintAnalyzer(Analyzer): - def __init__(self, file_path): - super().__init__(file_path) - - def build_pylint_options(self): - """ - Constructs the list of pylint options for analysis, including extra options from config. - - :return: List of pylint options for analysis. - """ - return [self.file_path] + EXTRA_PYLINT_OPTIONS - - def analyze(self): - """ - Executes pylint on the specified file and captures the output in JSON format. - """ - if not self.validate_file(): - print(f"File not found: {self.file_path}") - return - - print(f"Running pylint analysis on {self.file_path}") - - # Capture pylint output in a JSON format buffer - with StringIO() as buffer: - reporter = JSONReporter(buffer) - pylint_options = self.build_pylint_options() - - try: - # Run pylint with JSONReporter - Run(pylint_options, reporter=reporter, exit=False) - - # Parse the JSON output - buffer.seek(0) - self.report_data = json.loads(buffer.getvalue()) - print("Pylint JSON analysis completed.") - except json.JSONDecodeError as e: - print("Failed to parse JSON output from pylint:", e) - except Exception as e: - print("An error occurred during pylint analysis:", e) - - def get_smells_by_name(self, smell): - """ - Retrieves smells based on the Smell enum (e.g., Smell.LINE_TOO_LONG). - - :param smell: The Smell enum member to filter by. - :return: List of report entries matching the smell name. - """ - return [ - item for item in self.report_data - if item.get("message-id") == smell.value - ] - - def get_configured_smells(self): - """ - Filters the report data to retrieve only the smells with message IDs specified in the config. - - :return: List of detected code smells based on the configuration. - """ - configured_smells = [] - for smell in PylintSmell: - configured_smells.extend(self.get_smells_by_name(smell)) - return configured_smells diff --git a/src1/analyzers/ternary_expression_analyzer.py b/src1/analyzers/ternary_expression_analyzer.py deleted file mode 100644 index a341dc52..00000000 --- a/src1/analyzers/ternary_expression_analyzer.py +++ /dev/null @@ -1,69 +0,0 @@ -# FULLY CHATGPT - I only wanted to add this in so we have an idea how to detect smells pylint can't - -import ast -from .base_analyzer import Analyzer - -class TernaryExpressionAnalyzer(Analyzer): - def __init__(self, file_path, max_length=50): - super().__init__(file_path) - self.max_length = max_length - - def analyze(self): - """ - Reads the file and analyzes it to detect long ternary expressions. - """ - if not self.validate_file(): - print(f"File not found: {self.file_path}") - return - - print(f"Running ternary expression analysis on {self.file_path}") - - try: - code = self.read_code_from_file() - self.report_data = self.detect_long_ternary_expressions(code) - print("Ternary expression analysis completed.") - except FileNotFoundError: - print(f"File not found: {self.file_path}") - except IOError as e: - print(f"Error reading file {self.file_path}: {e}") - - def read_code_from_file(self): - """ - Reads and returns the code from the specified file path. - - :return: Source code as a string. - """ - with open(self.file_path, "r") as file: - return file.read() - - def detect_long_ternary_expressions(self, code): - """ - Detects ternary expressions in the code that exceed the specified max_length. - - :param code: The source code to analyze. - :return: List of detected long ternary expressions with line numbers and expression length. - """ - tree = ast.parse(code) - long_expressions = [] - - for node in ast.walk(tree): - if isinstance(node, ast.IfExp): # Ternary expression node - expression_source = ast.get_source_segment(code, node) - expression_length = len(expression_source) if expression_source else 0 - if expression_length > self.max_length: - long_expressions.append({ - "line": node.lineno, - "length": expression_length, - "expression": expression_source - }) - - return long_expressions - - def filter_expressions_by_length(self, min_length): - """ - Filters the report data to retrieve only the expressions exceeding a specified length. - - :param min_length: Minimum length of expressions to filter by. - :return: List of detected ternary expressions matching the specified length criteria. - """ - return [expr for expr in self.report_data if expr["length"] >= min_length] diff --git a/src1/utils/__init__.py b/src1/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py deleted file mode 100644 index 81313301..00000000 --- a/src1/utils/analyzers_config.py +++ /dev/null @@ -1,25 +0,0 @@ -# Any configurations that are done by the analyzers - -from enum import Enum - -class PylintSmell(Enum): - LINE_TOO_LONG = "C0301" # pylint smell - LONG_MESSAGE_CHAIN = "R0914" # pylint smell - LARGE_CLASS = "R0902" # pylint smell - LONG_PARAMETER_LIST = "R0913" # pylint smell - LONG_METHOD = "R0915" # pylint smell - COMPLEX_LIST_COMPREHENSION = "C0200" # pylint smell - INVALID_NAMING_CONVENTIONS = "C0103" # pylint smell - -class CustomSmell(Enum): - LONG_TERN_EXPR = "CUST-1" # custom smell - -AllSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, **{s.name: s.value for s in CustomSmell}}) - -# Extra pylint options -EXTRA_PYLINT_OPTIONS = [ - "--max-line-length=80", - "--max-nested-blocks=3", - "--max-branches=3", - "--max-parents=3" -] From c8f09f6ec755e89b69cb184fa82aa909cacec6fb Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:42:37 -0500 Subject: [PATCH 033/105] Revised POC - Readded base structure for src1 --- src1/analyzers/__init__.py | 0 src1/measurements/__init__.py | 0 src1/outputs/__init__.py | 0 src1/refactorers/__init__.py | 0 src1/utils/__init__.py | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src1/analyzers/__init__.py create mode 100644 src1/measurements/__init__.py create mode 100644 src1/outputs/__init__.py create mode 100644 src1/refactorers/__init__.py create mode 100644 src1/utils/__init__.py diff --git a/src1/analyzers/__init__.py b/src1/analyzers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src1/measurements/__init__.py b/src1/measurements/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src1/outputs/__init__.py b/src1/outputs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src1/refactorers/__init__.py b/src1/refactorers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src1/utils/__init__.py b/src1/utils/__init__.py new file mode 100644 index 00000000..e69de29b From 1a87160bbc9ea0eb455482e303c16030c0571d04 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:43:17 -0500 Subject: [PATCH 034/105] Revised POC - Added base_analyzer.py --- src1/analyzers/base_analyzer.py | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src1/analyzers/base_analyzer.py diff --git a/src1/analyzers/base_analyzer.py b/src1/analyzers/base_analyzer.py new file mode 100644 index 00000000..29377637 --- /dev/null +++ b/src1/analyzers/base_analyzer.py @@ -0,0 +1,34 @@ +from abc import ABC, abstractmethod +import os +from utils.logger import Logger + +class Analyzer(ABC): + def __init__(self, file_path, logger): + """ + Base class for analyzers to find code smells of a given file. + + :param file_path: Path to the file to be analyzed. + :param logger: Logger instance to handle log messages. + """ + self.file_path = file_path + self.smells_data = [] + self.logger = logger # Use logger instance + + def validate_file(self): + """ + Validates that the specified file path exists and is a file. + + :return: Boolean indicating the validity of the file path. + """ + is_valid = os.path.isfile(self.file_path) + if not is_valid: + self.logger.log(f"File not found: {self.file_path}") + return is_valid + + @abstractmethod + def analyze_smells(self): + """ + Abstract method to analyze the code smells of the specified file. + Must be implemented by subclasses. + """ + pass From 5c1991804352660b853f36f70c1027183a3cacc8 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:43:33 -0500 Subject: [PATCH 035/105] Revised POC - Added pylint_analyzer.py --- src1/analyzers/pylint_analyzer.py | 88 +++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src1/analyzers/pylint_analyzer.py diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py new file mode 100644 index 00000000..95e953d6 --- /dev/null +++ b/src1/analyzers/pylint_analyzer.py @@ -0,0 +1,88 @@ +import json +import os +from pylint.lint import Run +from pylint.reporters.json_reporter import JSONReporter +from io import StringIO +from .base_analyzer import Analyzer +from .ternary_expression_pylint_analyzer import TernaryExpressionPylintAnalyzer +from utils.analyzers_config import AllPylintSmells, EXTRA_PYLINT_OPTIONS + +class PylintAnalyzer(Analyzer): + def __init__(self, file_path, logger): + """ + Initializes the PylintAnalyzer with a file path and logger, + setting up attributes to collect code smells. + + :param file_path: Path to the file to be analyzed. + :param logger: Logger instance to handle log messages. + """ + super().__init__(file_path, logger) + + def build_pylint_options(self): + """ + Constructs the list of pylint options for analysis, including extra options from config. + + :return: List of pylint options for analysis. + """ + return [self.file_path] + EXTRA_PYLINT_OPTIONS + + def analyze_smells(self): + """ + Executes pylint on the specified file and captures the output in JSON format. + """ + if not self.validate_file(): + return + + self.logger.log(f"Running Pylint analysis on {os.path.basename(self.file_path)}") + + # Capture pylint output in a JSON format buffer + with StringIO() as buffer: + reporter = JSONReporter(buffer) + pylint_options = self.build_pylint_options() + + try: + # Run pylint with JSONReporter + Run(pylint_options, reporter=reporter, exit=False) + + # Parse the JSON output + buffer.seek(0) + self.smells_data = json.loads(buffer.getvalue()) + self.logger.log("Pylint analyzer completed successfully.") + except json.JSONDecodeError as e: + self.logger.log(f"Failed to parse JSON output from pylint: {e}") + except Exception as e: + self.logger.log(f"An error occurred during pylint analysis: {e}") + + self._find_custom_pylint_smells() # Find all custom smells in pylint-detected data + + def _find_custom_pylint_smells(self): + """ + Identifies custom smells, like long ternary expressions, in Pylint-detected data. + Updates self.smells_data with any new custom smells found. + """ + self.logger.log("Examining pylint smells for custom code smells") + ternary_analyzer = TernaryExpressionPylintAnalyzer(self.file_path, self.smells_data) + self.smells_data = ternary_analyzer.detect_long_ternary_expressions() + + def get_smells_by_name(self, smell): + """ + Retrieves smells based on the Smell enum (e.g., Smell.LONG_MESSAGE_CHAIN). + + :param smell: The Smell enum member to filter by. + :return: List of report entries matching the smell name. + """ + return [ + item for item in self.smells_data + if item.get("message-id") == smell.value + ] + + def get_configured_smells(self): + """ + Filters the report data to retrieve only the smells with message IDs specified in the config. + + :return: List of detected code smells based on the configuration. + """ + configured_smells = [] + for smell in AllPylintSmells: + configured_smells.extend(self.get_smells_by_name(smell)) + return configured_smells From 9db267f8ba791b2ff2ff1b6f500f73e9fb904fbe Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:44:02 -0500 Subject: [PATCH 036/105] Revised POC - Added ternary_expression_pylint_analyzer.py --- .../ternary_expression_pylint_analyzer.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src1/analyzers/ternary_expression_pylint_analyzer.py diff --git a/src1/analyzers/ternary_expression_pylint_analyzer.py b/src1/analyzers/ternary_expression_pylint_analyzer.py new file mode 100644 index 00000000..fbca4636 --- /dev/null +++ b/src1/analyzers/ternary_expression_pylint_analyzer.py @@ -0,0 +1,35 @@ +import ast +from utils.ast_parser import parse_line +from utils.analyzers_config import AllPylintSmells + +class TernaryExpressionPylintAnalyzer: + def __init__(self, file_path, smells_data): + """ + Initializes with smells data from PylintAnalyzer to find long ternary + expressions. + + :param file_path: Path to file used by PylintAnalyzer. + :param smells_data: List of smells from PylintAnalyzer. + """ + self.file_path = file_path + self.smells_data = smells_data + + def detect_long_ternary_expressions(self): + """ + Processes long lines to identify ternary expressions. + + :return: List of smells with updated ternary expression detection message IDs. + """ + for smell in self.smells_data: + if smell.get("message-id") == AllPylintSmells.LINE_TOO_LONG.value: + root_node = parse_line(self.file_path, smell["line"]) + + if root_node is None: + continue + + for node in ast.walk(root_node): + if isinstance(node, ast.IfExp): # Ternary expression node + smell["message-id"] = AllPylintSmells.LONG_TERN_EXPR.value + break + + return self.smells_data From dd88936c85167beaaa6fe696f37f4f7814d2522b Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:44:24 -0500 Subject: [PATCH 037/105] Revised POC - Added base_energy_meter.py --- src1/measurements/base_energy_meter.py | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src1/measurements/base_energy_meter.py diff --git a/src1/measurements/base_energy_meter.py b/src1/measurements/base_energy_meter.py new file mode 100644 index 00000000..144aae3a --- /dev/null +++ b/src1/measurements/base_energy_meter.py @@ -0,0 +1,34 @@ +from abc import ABC, abstractmethod +import os +from utils.logger import Logger + +class BaseEnergyMeter(ABC): + def __init__(self, file_path, logger): + """ + Base class for energy meters to measure the emissions of a given file. + + :param file_path: Path to the file to measure energy consumption. + :param logger: Logger instance to handle log messages. + """ + self.file_path = file_path + self.emissions = None + self.logger = logger # Use logger instance + + def validate_file(self): + """ + Validates that the specified file path exists and is a file. + + :return: Boolean indicating the validity of the file path. + """ + is_valid = os.path.isfile(self.file_path) + if not is_valid: + self.logger.log(f"File not found: {self.file_path}") + return is_valid + + @abstractmethod + def measure_energy(self): + """ + Abstract method to measure the energy consumption of the specified file. + Must be implemented by subclasses. + """ + pass From 57f13315668161557b4ad27ad778ce00f62b14f5 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:44:47 -0500 Subject: [PATCH 038/105] Revised POC - Added codecarbon_energy_meter.py --- src1/measurements/codecarbon_energy_meter.py | 68 ++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src1/measurements/codecarbon_energy_meter.py diff --git a/src1/measurements/codecarbon_energy_meter.py b/src1/measurements/codecarbon_energy_meter.py new file mode 100644 index 00000000..b763177c --- /dev/null +++ b/src1/measurements/codecarbon_energy_meter.py @@ -0,0 +1,68 @@ +import json +import os +import subprocess +import pandas as pd +from codecarbon import EmissionsTracker +from measurements.base_energy_meter import BaseEnergyMeter +from tempfile import TemporaryDirectory + +class CodeCarbonEnergyMeter(BaseEnergyMeter): + def __init__(self, file_path, logger): + """ + Initializes the CodeCarbonEnergyMeter with a file path and logger. + + :param file_path: Path to the file to measure energy consumption. + :param logger: Logger instance for logging events. + """ + super().__init__(file_path, logger) + self.emissions_data = None + + def measure_energy(self): + """ + Measures the carbon emissions for the specified file by running it with CodeCarbon. + Logs each step and stores the emissions data if available. + """ + if not self.validate_file(): + return + + self.logger.log(f"Starting CodeCarbon energy measurement on {os.path.basename(self.file_path)}") + + with TemporaryDirectory() as custom_temp_dir: + os.environ['TEMP'] = custom_temp_dir # For Windows + os.environ['TMPDIR'] = custom_temp_dir # For Unix-based systems + + tracker = EmissionsTracker(output_dir=custom_temp_dir) + tracker.start() + + try: + subprocess.run(["python", self.file_path], check=True) + self.logger.log("CodeCarbon measurement completed successfully.") + except subprocess.CalledProcessError as e: + self.logger.log(f"Error executing file '{self.file_path}': {e}") + finally: + self.emissions = tracker.stop() + emissions_file = os.path.join(custom_temp_dir, "emissions.csv") + + if os.path.exists(emissions_file): + self.emissions_data = self.extract_emissions_csv(emissions_file) + else: + self.logger.log("Emissions file was not created due to an error during execution.") + self.emissions_data = None + + def extract_emissions_csv(self, csv_file_path): + """ + Extracts emissions data from a CSV file generated by CodeCarbon. + + :param csv_file_path: Path to the CSV file. + :return: Dictionary containing the last row of emissions data or None if an error occurs. + """ + if os.path.exists(csv_file_path): + try: + df = pd.read_csv(csv_file_path) + return df.to_dict(orient="records")[-1] + except Exception as e: + self.logger.log(f"Error reading file '{csv_file_path}': {e}") + return None + else: + self.logger.log(f"File '{csv_file_path}' does not exist.") + return None From 8ac1d6051c9d2d4bca5ac802573ec35a736c78e6 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:45:26 -0500 Subject: [PATCH 039/105] Revised POC - Added base_refactorer.py --- src1/refactorers/base_refactorer.py | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src1/refactorers/base_refactorer.py diff --git a/src1/refactorers/base_refactorer.py b/src1/refactorers/base_refactorer.py new file mode 100644 index 00000000..5eb1418c --- /dev/null +++ b/src1/refactorers/base_refactorer.py @@ -0,0 +1,51 @@ +# refactorers/base_refactor.py + +from abc import ABC, abstractmethod +import os +from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter + +class BaseRefactorer(ABC): + def __init__(self, file_path, pylint_smell, initial_emission, logger): + """ + Base class for refactoring specific code smells. + + :param file_path: Path to the file to be refactored. + :param pylint_smell: Dictionary containing details of the Pylint smell. + :param initial_emission: Initial emission value before refactoring. + :param logger: Logger instance to handle log messages. + """ + self.file_path = file_path + self.pylint_smell = pylint_smell + self.initial_emission = initial_emission + self.final_emission = None + self.logger = logger # Store the mandatory logger instance + + @abstractmethod + def refactor(self): + """ + Abstract method for refactoring the code smell. + Each subclass should implement this method. + """ + pass + + def measure_energy(self, file_path): + """ + Method for measuring the energy after refactoring. + """ + codecarbon_energy_meter = CodeCarbonEnergyMeter(file_path, self.logger) + codecarbon_energy_meter.measure_energy() # measure emissions + self.final_emission = codecarbon_energy_meter.emissions # get emission + + # Log the measured emissions + self.logger.log(f"Measured emissions for '{os.path.basename(file_path)}': {self.final_emission}") + + def check_energy_improvement(self): + """ + Checks if the refactoring has reduced energy consumption. + + :return: True if the final emission is lower than the initial emission, indicating improvement; + False otherwise. + """ + improved = self.final_emission and (self.final_emission < self.initial_emission) + self.logger.log(f"Initial Emissions: {self.initial_emission} kg CO2. Final Emissions: {self.final_emission} kg CO2.") + return improved From 9792b7d9f4064050ed212618e512a06e895ada77 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:45:50 -0500 Subject: [PATCH 040/105] Revised POC - Added use_a_generator_refactor.py --- src1/refactorers/use_a_generator_refactor.py | 107 +++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src1/refactorers/use_a_generator_refactor.py diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactor.py new file mode 100644 index 00000000..5e3e46b8 --- /dev/null +++ b/src1/refactorers/use_a_generator_refactor.py @@ -0,0 +1,107 @@ +# refactorers/use_a_generator_refactor.py + +import ast +import astor # For converting AST back to source code +import shutil +import os +from .base_refactorer import BaseRefactorer + +class UseAGeneratorRefactor(BaseRefactorer): + def __init__(self, file_path, pylint_smell, initial_emission, logger): + """ + Initializes the UseAGeneratorRefactor with a file path, pylint + smell, initial emission, and logger. + + :param file_path: Path to the file to be refactored. + :param pylint_smell: Dictionary containing details of the Pylint smell. + :param initial_emission: Initial emission value before refactoring. + :param logger: Logger instance to handle log messages. + """ + super().__init__(file_path, pylint_smell, initial_emission, logger) + + def refactor(self): + """ + Refactors an unnecessary list comprehension by converting it to a generator expression. + Modifies the specified instance in the file directly if it results in lower emissions. + """ + line_number = self.pylint_smell['line'] + self.logger.log(f"Applying 'Use a Generator' refactor on '{os.path.basename(self.file_path)}' at line {line_number} for identified code smell.") + + # Load the source code as a list of lines + with open(self.file_path, 'r') as file: + original_lines = file.readlines() + + # Check if the line number is valid within the file + if not (1 <= line_number <= len(original_lines)): + self.logger.log("Specified line number is out of bounds.\n") + return + + # Target the specific line and remove leading whitespace for parsing + line = original_lines[line_number - 1] + stripped_line = line.lstrip() # Strip leading indentation + indentation = line[:len(line) - len(stripped_line)] # Track indentation + + # Parse the line as an AST + line_ast = ast.parse(stripped_line, mode='exec') # Use 'exec' mode for full statements + + # Look for a list comprehension within the AST of this line + modified = False + for node in ast.walk(line_ast): + if isinstance(node, ast.ListComp): + # Convert the list comprehension to a generator expression + generator_expr = ast.GeneratorExp( + elt=node.elt, + generators=node.generators + ) + ast.copy_location(generator_expr, node) + + # Replace the list comprehension node with the generator expression + self._replace_node(line_ast, node, generator_expr) + modified = True + break + + if modified: + # Convert the modified AST back to source code + modified_line = astor.to_source(line_ast).strip() + # Reapply the original indentation + modified_lines = original_lines[:] + modified_lines[line_number - 1] = indentation + modified_line + "\n" + + # Temporarily write the modified content to a temporary file + temp_file_path = f"{self.file_path}.temp" + with open(temp_file_path, 'w') as temp_file: + temp_file.writelines(modified_lines) + + # Measure emissions of the modified code + self.measure_energy(temp_file_path) + + # Check for improvement in emissions + if self.check_energy_improvement(): + # If improved, replace the original file with the modified content + shutil.move(temp_file_path, self.file_path) + self.logger.log(f"Refactored list comprehension to generator expression on line {line_number} and saved.\n") + else: + # Remove the temporary file if no improvement + os.remove(temp_file_path) + self.logger.log("No emission improvement after refactoring. Discarded refactored changes.\n") + else: + self.logger.log("No applicable list comprehension found on the specified line.\n") + + def _replace_node(self, tree, old_node, new_node): + """ + Helper function to replace an old AST node with a new one within a tree. + + :param tree: The AST tree or node containing the node to be replaced. + :param old_node: The node to be replaced. + :param new_node: The new node to replace it with. + """ + for parent in ast.walk(tree): + for field, value in ast.iter_fields(parent): + if isinstance(value, list): + for i, item in enumerate(value): + if item is old_node: + value[i] = new_node + return + elif value is old_node: + setattr(parent, field, new_node) + return From c1474af6a54f01f57538f65ecbb3135d1dec4db1 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:46:21 -0500 Subject: [PATCH 041/105] Revised POC - Added analyzers_config.py --- src1/utils/analyzers_config.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src1/utils/analyzers_config.py diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py new file mode 100644 index 00000000..2f12442e --- /dev/null +++ b/src1/utils/analyzers_config.py @@ -0,0 +1,30 @@ +# Any configurations that are done by the analyzers + +from enum import Enum + +# Enum class for standard Pylint code smells +class PylintSmell(Enum): + LINE_TOO_LONG = "C0301" # Pylint code smell for lines that exceed the max length + LONG_MESSAGE_CHAIN = "R0914" # Pylint code smell for long message chains + LARGE_CLASS = "R0902" # Pylint code smell for classes with too many attributes + LONG_PARAMETER_LIST = "R0913" # Pylint code smell for functions with too many parameters + LONG_METHOD = "R0915" # Pylint code smell for methods that are too long + COMPLEX_LIST_COMPREHENSION = "C0200" # Pylint code smell for complex list comprehensions + INVALID_NAMING_CONVENTIONS = "C0103" # Pylint code smell for naming conventions violations + USE_A_GENERATOR = "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` + + +# Enum class for custom code smells not detected by Pylint +class CustomPylintSmell(Enum): + LONG_TERN_EXPR = "CUST-1" # Custom code smell for long ternary expressions + +# Combined enum for all smells +AllPylintSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, **{s.name: s.value for s in CustomPylintSmell}}) + +# Additional Pylint configuration options for analyzing code +EXTRA_PYLINT_OPTIONS = [ + "--max-line-length=80", # Sets maximum allowed line length + "--max-nested-blocks=3", # Limits maximum nesting of blocks + "--max-branches=3", # Limits maximum branches in a function + "--max-parents=3" # Limits maximum inheritance levels for a class +] From e59185fdd110779ec862f6d90764de5cd68bac31 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:46:40 -0500 Subject: [PATCH 042/105] Revised POC - Added ast_parser.py --- src1/utils/ast_parser.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src1/utils/ast_parser.py diff --git a/src1/utils/ast_parser.py b/src1/utils/ast_parser.py new file mode 100644 index 00000000..2da6f3f0 --- /dev/null +++ b/src1/utils/ast_parser.py @@ -0,0 +1,32 @@ +import ast + +def parse_line(file: str, line: int): + """ + Parses a specific line of code from a file into an AST node. + + :param file: Path to the file to parse. + :param line: Line number to parse (1-based index). + :return: AST node of the line, or None if a SyntaxError occurs. + """ + with open(file, "r") as f: + file_lines = f.readlines() # Read all lines of the file into a list + try: + # Parse the specified line (adjusted for 0-based indexing) into an AST node + node = ast.parse(file_lines[line - 1].strip()) + except(SyntaxError) as e: + # Return None if there is a syntax error in the specified line + return None + + return node # Return the parsed AST node for the line + +def parse_file(file: str): + """ + Parses the entire contents of a file into an AST node. + + :param file: Path to the file to parse. + :return: AST node of the entire file contents. + """ + with open(file, "r") as f: + source = f.read() # Read the full content of the file + + return ast.parse(source) # Parse the entire content as an AST node From 62be7c2cd5d1c77f2564894e1d7bc21a418bf6f1 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:46:52 -0500 Subject: [PATCH 043/105] Revised POC - Added logger.py --- src1/utils/logger.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src1/utils/logger.py diff --git a/src1/utils/logger.py b/src1/utils/logger.py new file mode 100644 index 00000000..22251f93 --- /dev/null +++ b/src1/utils/logger.py @@ -0,0 +1,31 @@ +# utils/logger.py + +import os +from datetime import datetime + +class Logger: + def __init__(self, log_path): + """ + Initializes the Logger with a path to the log file. + + :param log_path: Path to the log file where messages will be stored. + """ + self.log_path = log_path + + # Ensure the log file directory exists and clear any previous content + os.makedirs(os.path.dirname(log_path), exist_ok=True) + open(self.log_path, 'w').close() # Open in write mode to clear the file + + def log(self, message): + """ + Appends a message with a timestamp to the log file. + + :param message: The message to log. + """ + timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + full_message = f"[{timestamp}] {message}\n" + + # Append the message to the log file + with open(self.log_path, 'a') as log_file: + log_file.write(full_message) + print(full_message.strip()) # Optional: also print the message From 4a487fd573128223355a85cf32cc1d9b485bb833 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:47:58 -0500 Subject: [PATCH 044/105] Revised POC - Added outputs_config.py --- src1/utils/outputs_config.py | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src1/utils/outputs_config.py diff --git a/src1/utils/outputs_config.py b/src1/utils/outputs_config.py new file mode 100644 index 00000000..b87a183a --- /dev/null +++ b/src1/utils/outputs_config.py @@ -0,0 +1,61 @@ +# utils/output_config.py + +import json +import os +import shutil +from utils.logger import Logger # Import Logger if used elsewhere + +OUTPUT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../outputs/")) + +def save_json_files(filename, data, logger=None): + """ + Saves JSON data to a file in the output folder. + + :param filename: Name of the file to save data to. + :param data: Data to be saved. + :param logger: Optional logger instance to log messages. + """ + file_path = os.path.join(OUTPUT_DIR, filename) + + # Ensure the output directory exists; if not, create it + if not os.path.exists(OUTPUT_DIR): + os.makedirs(OUTPUT_DIR) + + # Write JSON data to the specified file + with open(file_path, 'w+') as file: + json.dump(data, file, sort_keys=True, indent=4) + + message = f"Output saved to {file_path.removeprefix(os.path.dirname(__file__))}" + if logger: + logger.log(message) + else: + print(message) + + +def copy_file_to_output(source_file_path, new_file_name, logger=None): + """ + Copies the specified file to the output directory with a specified new name. + + :param source_file_path: The path of the file to be copied. + :param new_file_name: The desired name for the copied file in the output directory. + :param logger: Optional logger instance to log messages. + + :return: Path of the copied file in the output directory. + """ + # Ensure the output directory exists; if not, create it + if not os.path.exists(OUTPUT_DIR): + os.makedirs(OUTPUT_DIR) + + # Define the destination path with the new file name + destination_path = os.path.join(OUTPUT_DIR, new_file_name) + + # Copy the file to the destination path with the specified name + shutil.copy(source_file_path, destination_path) + + message = f"File copied to {destination_path.removeprefix(os.path.dirname(__file__))}" + if logger: + logger.log(message) + else: + print(message) + + return destination_path From 0ff8dc13b7036208ed8b67375dc4f0fc24f6a3c6 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:48:18 -0500 Subject: [PATCH 045/105] Revised POC - Added refactorer_factory.py --- src1/utils/refactorer_factory.py | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src1/utils/refactorer_factory.py diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py new file mode 100644 index 00000000..2f82d794 --- /dev/null +++ b/src1/utils/refactorer_factory.py @@ -0,0 +1,38 @@ +# Import specific refactorer classes +from refactorers.use_a_generator_refactor import UseAGeneratorRefactor +from refactorers.base_refactorer import BaseRefactorer + +# Import the configuration for all Pylint smells +from utils.analyzers_config import AllPylintSmells + +class RefactorerFactory(): + """ + Factory class for creating appropriate refactorer instances based on + the specific code smell detected by Pylint. + """ + + @staticmethod + def build_refactorer_class(file_path, smell_messageId, smell_data, initial_emission, logger): + """ + Static method to create and return a refactorer instance based on the provided code smell. + + Parameters: + - file_path (str): The path of the file to be refactored. + - smell_messageId (str): The unique identifier (message ID) of the detected code smell. + - smell_data (dict): Additional data related to the smell, passed to the refactorer. + + Returns: + - BaseRefactorer: An instance of a specific refactorer class if one exists for the smell; + otherwise, None. + """ + + selected = None # Initialize variable to hold the selected refactorer instance + + # Use match statement to select the appropriate refactorer based on smell message ID + match smell_messageId: + case AllPylintSmells.USE_A_GENERATOR.value: + selected = UseAGeneratorRefactor(file_path, smell_data, initial_emission, logger) + case _: + selected = None + + return selected # Return the selected refactorer instance or None if no match was found From 488cb73de68368311784e314513a4d2d7014eed9 Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:48:40 -0500 Subject: [PATCH 046/105] Revised POC - Added main.py --- src1/main.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src1/main.py diff --git a/src1/main.py b/src1/main.py new file mode 100644 index 00000000..40a358bc --- /dev/null +++ b/src1/main.py @@ -0,0 +1,108 @@ +import json +import os + +from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter +from analyzers.pylint_analyzer import PylintAnalyzer +from utils.output_config import save_json_files, copy_file_to_output +from utils.refactorer_factory import RefactorerFactory +from utils.logger import Logger + + +def main(): + # Path to the file to be analyzed + test_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src1-tests/ineffcient_code_example_1.py")) + + # Set up logging + log_file = os.path.join(os.path.dirname(__file__), "outputs/log.txt") + logger = Logger(log_file) + + + + + # Log start of emissions capture + logger.log("#####################################################################################################") + logger.log(" CAPTURE INITIAL EMISSIONS ") + logger.log("#####################################################################################################") + + # Measure energy with CodeCarbonEnergyMeter + codecarbon_energy_meter = CodeCarbonEnergyMeter(test_file, logger) + codecarbon_energy_meter.measure_energy() # Measure emissions + initial_emission = codecarbon_energy_meter.emissions # Get initial emission + initial_emission_data = codecarbon_energy_meter.emissions_data # Get initial emission data + + # Save initial emission data + save_json_files("initial_emissions_data.txt", initial_emission_data, logger) + logger.log(f"Initial Emissions: {initial_emission} kg CO2") + logger.log("#####################################################################################################\n\n") + + + + + # Log start of code smells capture + logger.log("#####################################################################################################") + logger.log(" CAPTURE CODE SMELLS ") + logger.log("#####################################################################################################") + + # Anaylze code smells with PylintAnalyzer + pylint_analyzer = PylintAnalyzer(test_file, logger) + pylint_analyzer.analyze_smells() # analyze all smells + detected_pylint_smells = pylint_analyzer.get_configured_smells() # get all configured smells + + # Save code smells + save_json_files("all_configured_pylint_smells.json", detected_pylint_smells, logger) + logger.log(f"Refactorable code smells: {len(detected_pylint_smells)}") + logger.log("#####################################################################################################\n\n") + + + + + # Log start of refactoring codes + logger.log("#####################################################################################################") + logger.log(" REFACTOR CODE SMELLS ") + logger.log("#####################################################################################################") + + # Refactor code smells + test_file_copy = copy_file_to_output(test_file, "refactored-test-case.py") + emission = initial_emission + + for pylint_smell in detected_pylint_smells: + refactoring_class = RefactorerFactory.build_refactorer_class(test_file_copy, pylint_smell["message-id"], pylint_smell, emission, logger) + + if refactoring_class: + refactoring_class.refactor() + emission = refactoring_class.final_emission + else: + logger.log(f"Refactoring for smell {pylint_smell['symbol']} is not implemented.") + logger.log("#####################################################################################################\n\n") + + + + + # Log start of emissions capture + logger.log("#####################################################################################################") + logger.log(" CAPTURE FINAL EMISSIONS ") + logger.log("#####################################################################################################") + + # Measure energy with CodeCarbonEnergyMeter + codecarbon_energy_meter = CodeCarbonEnergyMeter(test_file, logger) + codecarbon_energy_meter.measure_energy() # Measure emissions + final_emission = codecarbon_energy_meter.emissions # Get final emission + final_emission_data = codecarbon_energy_meter.emissions_data # Get final emission data + + # Save final emission data + save_json_files("final_emissions_data.txt", final_emission_data, logger) + logger.log(f"Final Emissions: {final_emission} kg CO2") + logger.log("#####################################################################################################\n\n") + + + + + # The emissions from codecarbon are so inconsistent that this could be a possibility :( + if final_emission >= initial_emission: + logger.log(f"Final emissions are greater than initial emissions; we are going to fail") + else: + logger.log(f"Saved {initial_emission - final_emission} kg CO2") + + +if __name__ == "__main__": + main() From 73e968eba90a6087ef56537d9d5a09b8181a535f Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Fri, 8 Nov 2024 06:51:28 -0500 Subject: [PATCH 047/105] Revised POC - Added output files --- src1/main.py | 2 +- .../outputs/all_configured_pylint_smells.json | 106 ++++++++++++++++++ src1/outputs/final_emissions_data.txt | 34 ++++++ src1/outputs/initial_emissions_data.txt | 34 ++++++ src1/outputs/log.txt | 94 ++++++++++++++++ src1/outputs/refactored-test-case.py | 33 ++++++ 6 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 src1/outputs/all_configured_pylint_smells.json create mode 100644 src1/outputs/final_emissions_data.txt create mode 100644 src1/outputs/initial_emissions_data.txt create mode 100644 src1/outputs/log.txt create mode 100644 src1/outputs/refactored-test-case.py diff --git a/src1/main.py b/src1/main.py index 40a358bc..3ab6cc68 100644 --- a/src1/main.py +++ b/src1/main.py @@ -3,7 +3,7 @@ from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter from analyzers.pylint_analyzer import PylintAnalyzer -from utils.output_config import save_json_files, copy_file_to_output +from utils.outputs_config import save_json_files, copy_file_to_output from utils.refactorer_factory import RefactorerFactory from utils.logger import Logger diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json new file mode 100644 index 00000000..86f6dbf4 --- /dev/null +++ b/src1/outputs/all_configured_pylint_smells.json @@ -0,0 +1,106 @@ +[ + { + "column": 11, + "endColumn": 44, + "endLine": 5, + "line": 5, + "message": "Use a generator instead 'any(num > 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "has_positive", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 45, + "endLine": 9, + "line": 9, + "message": "Use a generator instead 'all(num >= 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_non_negative", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 46, + "endLine": 13, + "line": 13, + "message": "Use a generator instead 'any(len(s) > 10 for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "contains_large_strings", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 46, + "endLine": 17, + "line": 17, + "message": "Use a generator instead 'all(s.isupper() for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_uppercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 63, + "endLine": 21, + "line": 21, + "message": "Use a generator instead 'any(num % 5 == 0 and num > 100 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "contains_special_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 46, + "endLine": 25, + "line": 25, + "message": "Use a generator instead 'all(s.islower() for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_lowercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 49, + "endLine": 29, + "line": 29, + "message": "Use a generator instead 'any(num % 2 == 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "any_even_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 52, + "endLine": 33, + "line": 33, + "message": "Use a generator instead 'all(s.startswith('A') for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_strings_start_with_a", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" + } +] \ No newline at end of file diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt new file mode 100644 index 00000000..c24ac6cb --- /dev/null +++ b/src1/outputs/final_emissions_data.txt @@ -0,0 +1,34 @@ +{ + "cloud_provider": NaN, + "cloud_region": NaN, + "codecarbon_version": "2.7.2", + "country_iso_code": "CAN", + "country_name": "Canada", + "cpu_count": 12, + "cpu_energy": 3.003186364367139e-07, + "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", + "cpu_power": 23.924, + "duration": 2.316929100023117, + "emissions": 1.3831601079554254e-08, + "emissions_rate": 5.9697990238096845e-09, + "energy_consumed": 3.501985780487408e-07, + "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", + "gpu_count": 1, + "gpu_energy": 0.0, + "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_power": 0.0, + "latitude": 43.2642, + "longitude": -79.9143, + "on_cloud": "N", + "os": "Windows-10-10.0.19045-SP0", + "project_name": "codecarbon", + "pue": 1.0, + "python_version": "3.13.0", + "ram_energy": 4.9879941612026864e-08, + "ram_power": 5.91276741027832, + "ram_total_size": 15.767379760742188, + "region": "ontario", + "run_id": "9acaf59e-0cc7-430f-b237-5b0fc071450a", + "timestamp": "2024-11-08T06:50:50", + "tracking_mode": "machine" +} \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt new file mode 100644 index 00000000..8e37578d --- /dev/null +++ b/src1/outputs/initial_emissions_data.txt @@ -0,0 +1,34 @@ +{ + "cloud_provider": NaN, + "cloud_region": NaN, + "codecarbon_version": "2.7.2", + "country_iso_code": "CAN", + "country_name": "Canada", + "cpu_count": 12, + "cpu_energy": 3.941996726949971e-07, + "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", + "cpu_power": 26.8962, + "duration": 2.388269099988974, + "emissions": 1.7910543037257115e-08, + "emissions_rate": 7.499382308861175e-09, + "energy_consumed": 4.534722095911076e-07, + "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", + "gpu_count": 1, + "gpu_energy": 0.0, + "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_power": 0.0, + "latitude": 43.2642, + "longitude": -79.9143, + "on_cloud": "N", + "os": "Windows-10-10.0.19045-SP0", + "project_name": "codecarbon", + "pue": 1.0, + "python_version": "3.13.0", + "ram_energy": 5.9272536896110475e-08, + "ram_power": 5.91276741027832, + "ram_total_size": 15.767379760742188, + "region": "ontario", + "run_id": "c0408029-2c8c-4653-a6fb-98073ce8b637", + "timestamp": "2024-11-08T06:49:43", + "tracking_mode": "machine" +} \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt new file mode 100644 index 00000000..a8daeefa --- /dev/null +++ b/src1/outputs/log.txt @@ -0,0 +1,94 @@ +[2024-11-08 06:49:35] ##################################################################################################### +[2024-11-08 06:49:35] CAPTURE INITIAL EMISSIONS +[2024-11-08 06:49:35] ##################################################################################################### +[2024-11-08 06:49:35] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-08 06:49:40] CodeCarbon measurement completed successfully. +[2024-11-08 06:49:43] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt +[2024-11-08 06:49:43] Initial Emissions: 1.7910543037257115e-08 kg CO2 +[2024-11-08 06:49:43] ##################################################################################################### + + +[2024-11-08 06:49:43] ##################################################################################################### +[2024-11-08 06:49:43] CAPTURE CODE SMELLS +[2024-11-08 06:49:43] ##################################################################################################### +[2024-11-08 06:49:43] Running Pylint analysis on ineffcient_code_example_1.py +[2024-11-08 06:49:43] Pylint analyzer completed successfully. +[2024-11-08 06:49:43] Examining pylint smells for custom code smells +[2024-11-08 06:49:43] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json +[2024-11-08 06:49:43] Refactorable code smells: 8 +[2024-11-08 06:49:43] ##################################################################################################### + + +[2024-11-08 06:49:43] ##################################################################################################### +[2024-11-08 06:49:43] REFACTOR CODE SMELLS +[2024-11-08 06:49:43] ##################################################################################################### +[2024-11-08 06:49:43] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 5 for identified code smell. +[2024-11-08 06:49:43] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:49:48] CodeCarbon measurement completed successfully. +[2024-11-08 06:49:50] Measured emissions for 'refactored-test-case.py.temp': 4.095266300954314e-08 +[2024-11-08 06:49:50] Initial Emissions: 1.7910543037257115e-08 kg CO2. Final Emissions: 4.095266300954314e-08 kg CO2. +[2024-11-08 06:49:50] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-08 06:49:50] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 9 for identified code smell. +[2024-11-08 06:49:50] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:49:56] CodeCarbon measurement completed successfully. +[2024-11-08 06:49:58] Measured emissions for 'refactored-test-case.py.temp': 4.0307671392924016e-08 +[2024-11-08 06:49:58] Initial Emissions: 4.095266300954314e-08 kg CO2. Final Emissions: 4.0307671392924016e-08 kg CO2. +[2024-11-08 06:49:58] Refactored list comprehension to generator expression on line 9 and saved. + +[2024-11-08 06:49:58] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 13 for identified code smell. +[2024-11-08 06:49:58] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:03] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:05] Measured emissions for 'refactored-test-case.py.temp': 1.9387173249895166e-08 +[2024-11-08 06:50:05] Initial Emissions: 4.0307671392924016e-08 kg CO2. Final Emissions: 1.9387173249895166e-08 kg CO2. +[2024-11-08 06:50:05] Refactored list comprehension to generator expression on line 13 and saved. + +[2024-11-08 06:50:05] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 17 for identified code smell. +[2024-11-08 06:50:05] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:10] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:13] Measured emissions for 'refactored-test-case.py.temp': 2.951190821474716e-08 +[2024-11-08 06:50:13] Initial Emissions: 1.9387173249895166e-08 kg CO2. Final Emissions: 2.951190821474716e-08 kg CO2. +[2024-11-08 06:50:13] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-08 06:50:13] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 21 for identified code smell. +[2024-11-08 06:50:13] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:18] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:20] Measured emissions for 'refactored-test-case.py.temp': 3.45807880672747e-08 +[2024-11-08 06:50:20] Initial Emissions: 2.951190821474716e-08 kg CO2. Final Emissions: 3.45807880672747e-08 kg CO2. +[2024-11-08 06:50:20] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-08 06:50:20] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 25 for identified code smell. +[2024-11-08 06:50:20] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:25] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:28] Measured emissions for 'refactored-test-case.py.temp': 3.4148420368067676e-08 +[2024-11-08 06:50:28] Initial Emissions: 3.45807880672747e-08 kg CO2. Final Emissions: 3.4148420368067676e-08 kg CO2. +[2024-11-08 06:50:28] Refactored list comprehension to generator expression on line 25 and saved. + +[2024-11-08 06:50:28] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 29 for identified code smell. +[2024-11-08 06:50:28] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:33] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:35] Measured emissions for 'refactored-test-case.py.temp': 4.0344935213547e-08 +[2024-11-08 06:50:35] Initial Emissions: 3.4148420368067676e-08 kg CO2. Final Emissions: 4.0344935213547e-08 kg CO2. +[2024-11-08 06:50:35] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-08 06:50:35] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 33 for identified code smell. +[2024-11-08 06:50:35] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-08 06:50:40] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:42] Measured emissions for 'refactored-test-case.py.temp': 1.656956729885559e-08 +[2024-11-08 06:50:42] Initial Emissions: 4.0344935213547e-08 kg CO2. Final Emissions: 1.656956729885559e-08 kg CO2. +[2024-11-08 06:50:42] Refactored list comprehension to generator expression on line 33 and saved. + +[2024-11-08 06:50:42] ##################################################################################################### + + +[2024-11-08 06:50:42] ##################################################################################################### +[2024-11-08 06:50:42] CAPTURE FINAL EMISSIONS +[2024-11-08 06:50:42] ##################################################################################################### +[2024-11-08 06:50:42] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-08 06:50:47] CodeCarbon measurement completed successfully. +[2024-11-08 06:50:50] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt +[2024-11-08 06:50:50] Final Emissions: 1.3831601079554254e-08 kg CO2 +[2024-11-08 06:50:50] ##################################################################################################### + + +[2024-11-08 06:50:50] Saved 4.0789419577028616e-09 kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py new file mode 100644 index 00000000..d351ccc5 --- /dev/null +++ b/src1/outputs/refactored-test-case.py @@ -0,0 +1,33 @@ +# Should trigger Use A Generator code smells + +def has_positive(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num > 0 for num in numbers]) + +def all_non_negative(numbers): + # List comprehension inside `all()` - triggers R1729 + return all(num >= 0 for num in numbers) + +def contains_large_strings(strings): + # List comprehension inside `any()` - triggers R1729 + return any(len(s) > 10 for s in strings) + +def all_uppercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.isupper() for s in strings]) + +def contains_special_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 5 == 0 and num > 100 for num in numbers]) + +def all_lowercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all(s.islower() for s in strings) + +def any_even_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 2 == 0 for num in numbers]) + +def all_strings_start_with_a(strings): + # List comprehension inside `all()` - triggers R1729 + return all(s.startswith('A') for s in strings) From 6c69f162f9d5e5d625ce486ada1d5c4366c0ba8a Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Fri, 8 Nov 2024 10:38:09 -0800 Subject: [PATCH 048/105] Fixed errors when running code carbon for nivs work --- src1/measurements/codecarbon_energy_meter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src1/measurements/codecarbon_energy_meter.py b/src1/measurements/codecarbon_energy_meter.py index b763177c..f2a0a2ef 100644 --- a/src1/measurements/codecarbon_energy_meter.py +++ b/src1/measurements/codecarbon_energy_meter.py @@ -1,5 +1,6 @@ import json import os +import sys import subprocess import pandas as pd from codecarbon import EmissionsTracker @@ -31,11 +32,11 @@ def measure_energy(self): os.environ['TEMP'] = custom_temp_dir # For Windows os.environ['TMPDIR'] = custom_temp_dir # For Unix-based systems - tracker = EmissionsTracker(output_dir=custom_temp_dir) + tracker = EmissionsTracker(output_dir=custom_temp_dir, allow_multiple_runs=True) tracker.start() try: - subprocess.run(["python", self.file_path], check=True) + subprocess.run([sys.executable, self.file_path], check=True) self.logger.log("CodeCarbon measurement completed successfully.") except subprocess.CalledProcessError as e: self.logger.log(f"Error executing file '{self.file_path}': {e}") From 6c94f2635db0f405ef29aa35287fb627930db2b4 Mon Sep 17 00:00:00 2001 From: mya Date: Fri, 8 Nov 2024 23:45:58 -0500 Subject: [PATCH 049/105] Changed refactoring base class --- src1/refactorers/base_refactorer.py | 15 +++++++-------- src1/refactorers/use_a_generator_refactor.py | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src1/refactorers/base_refactorer.py b/src1/refactorers/base_refactorer.py index 5eb1418c..d6604de8 100644 --- a/src1/refactorers/base_refactorer.py +++ b/src1/refactorers/base_refactorer.py @@ -5,26 +5,25 @@ from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter class BaseRefactorer(ABC): - def __init__(self, file_path, pylint_smell, initial_emission, logger): + def __init__(self, logger): """ Base class for refactoring specific code smells. - :param file_path: Path to the file to be refactored. - :param pylint_smell: Dictionary containing details of the Pylint smell. - :param initial_emission: Initial emission value before refactoring. :param logger: Logger instance to handle log messages. """ - self.file_path = file_path - self.pylint_smell = pylint_smell - self.initial_emission = initial_emission + self.final_emission = None self.logger = logger # Store the mandatory logger instance @abstractmethod - def refactor(self): + def refactor(self, file_path, pylint_smell, initial_emission): """ Abstract method for refactoring the code smell. Each subclass should implement this method. + + :param file_path: Path to the file to be refactored. + :param pylint_smell: Dictionary containing details of the Pylint smell. + :param initial_emission: Initial emission value before refactoring. """ pass diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactor.py index 5e3e46b8..86f87441 100644 --- a/src1/refactorers/use_a_generator_refactor.py +++ b/src1/refactorers/use_a_generator_refactor.py @@ -7,7 +7,7 @@ from .base_refactorer import BaseRefactorer class UseAGeneratorRefactor(BaseRefactorer): - def __init__(self, file_path, pylint_smell, initial_emission, logger): + def __init__(self, logger): """ Initializes the UseAGeneratorRefactor with a file path, pylint smell, initial emission, and logger. @@ -17,9 +17,9 @@ def __init__(self, file_path, pylint_smell, initial_emission, logger): :param initial_emission: Initial emission value before refactoring. :param logger: Logger instance to handle log messages. """ - super().__init__(file_path, pylint_smell, initial_emission, logger) + super().__init__( logger) - def refactor(self): + def refactor(self, file_path, pylint_smell, initial_emission): """ Refactors an unnecessary list comprehension by converting it to a generator expression. Modifies the specified instance in the file directly if it results in lower emissions. From 61a517c61612f7a92ba4d44c41ec77547026c71e Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 9 Nov 2024 00:04:55 -0500 Subject: [PATCH 050/105] made restructuring changes --- src-combined/README.md | 5 - src-combined/__init__.py | 5 - src-combined/analyzers/__init__.py | 0 src-combined/analyzers/base_analyzer.py | 37 -- src-combined/analyzers/pylint_analyzer.py | 133 ----- src-combined/analyzers/ruff_analyzer.py | 104 ---- src-combined/main.py | 83 ---- src-combined/measurement/__init__.py | 0 src-combined/measurement/code_carbon_meter.py | 60 --- .../measurement/custom_energy_measure.py | 62 --- src-combined/measurement/energy_meter.py | 115 ----- src-combined/measurement/measurement_utils.py | 41 -- src-combined/output/ast.txt | 470 ------------------ src-combined/output/ast_lines.txt | 240 --------- src-combined/output/carbon_report.csv | 3 - src-combined/output/initial_carbon_report.csv | 33 -- src-combined/output/pylint_all_smells.json | 437 ---------------- .../output/pylint_configured_smells.json | 32 -- src-combined/output/report.txt | 152 ------ src-combined/refactorer/__init__.py | 0 src-combined/refactorer/base_refactorer.py | 26 - .../complex_list_comprehension_refactorer.py | 116 ----- .../refactorer/large_class_refactorer.py | 83 ---- .../refactorer/long_base_class_list.py | 14 - src-combined/refactorer/long_element_chain.py | 21 - .../long_lambda_function_refactorer.py | 16 - .../long_message_chain_refactorer.py | 17 - .../refactorer/long_method_refactorer.py | 18 - .../refactorer/long_scope_chaining.py | 24 - .../long_ternary_cond_expression.py | 17 - src-combined/testing/__init__.py | 0 src-combined/testing/test_runner.py | 17 - src-combined/testing/test_validator.py | 3 - src-combined/utils/__init__.py | 0 src-combined/utils/analyzers_config.py | 49 -- src-combined/utils/ast_parser.py | 17 - src-combined/utils/code_smells.py | 22 - src-combined/utils/factory.py | 21 - src-combined/utils/logger.py | 34 -- src1/analyzers/base_analyzer.py | 6 +- src1/analyzers/pylint_analyzer.py | 81 +-- .../ternary_expression_pylint_analyzer.py | 35 -- src1/main.py | 50 +- src1/measurements/base_energy_meter.py | 2 +- src1/measurements/codecarbon_energy_meter.py | 6 +- .../outputs/all_configured_pylint_smells.json | 16 +- ...e_carbon_ineffcient_code_example_1_log.txt | 2 + .../code_carbon_refactored-test-case_log.txt | 8 + src1/outputs/final_emissions_data.txt | 38 +- src1/outputs/initial_emissions_data.txt | 38 +- src1/outputs/log.txt | 188 +++---- src1/outputs/refactored-test-case.py | 8 +- src1/utils/analyzers_config.py | 31 +- src1/utils/logger.py | 2 +- src1/utils/outputs_config.py | 26 +- src1/utils/refactorer_factory.py | 4 +- test/carbon_report.csv | 33 -- test/inefficent_code_example.py | 90 ---- {test => tests}/README.md | 0 .../input}/ineffcient_code_example_1.py | 0 .../input}/ineffcient_code_example_2.py | 0 .../input/ineffcient_code_example_3.py | 0 {test => tests}/test_analyzer.py | 0 {test => tests}/test_end_to_end.py | 0 {test => tests}/test_energy_measure.py | 0 {test => tests}/test_refactorer.py | 0 66 files changed, 275 insertions(+), 2916 deletions(-) delete mode 100644 src-combined/README.md delete mode 100644 src-combined/__init__.py delete mode 100644 src-combined/analyzers/__init__.py delete mode 100644 src-combined/analyzers/base_analyzer.py delete mode 100644 src-combined/analyzers/pylint_analyzer.py delete mode 100644 src-combined/analyzers/ruff_analyzer.py delete mode 100644 src-combined/main.py delete mode 100644 src-combined/measurement/__init__.py delete mode 100644 src-combined/measurement/code_carbon_meter.py delete mode 100644 src-combined/measurement/custom_energy_measure.py delete mode 100644 src-combined/measurement/energy_meter.py delete mode 100644 src-combined/measurement/measurement_utils.py delete mode 100644 src-combined/output/ast.txt delete mode 100644 src-combined/output/ast_lines.txt delete mode 100644 src-combined/output/carbon_report.csv delete mode 100644 src-combined/output/initial_carbon_report.csv delete mode 100644 src-combined/output/pylint_all_smells.json delete mode 100644 src-combined/output/pylint_configured_smells.json delete mode 100644 src-combined/output/report.txt delete mode 100644 src-combined/refactorer/__init__.py delete mode 100644 src-combined/refactorer/base_refactorer.py delete mode 100644 src-combined/refactorer/complex_list_comprehension_refactorer.py delete mode 100644 src-combined/refactorer/large_class_refactorer.py delete mode 100644 src-combined/refactorer/long_base_class_list.py delete mode 100644 src-combined/refactorer/long_element_chain.py delete mode 100644 src-combined/refactorer/long_lambda_function_refactorer.py delete mode 100644 src-combined/refactorer/long_message_chain_refactorer.py delete mode 100644 src-combined/refactorer/long_method_refactorer.py delete mode 100644 src-combined/refactorer/long_scope_chaining.py delete mode 100644 src-combined/refactorer/long_ternary_cond_expression.py delete mode 100644 src-combined/testing/__init__.py delete mode 100644 src-combined/testing/test_runner.py delete mode 100644 src-combined/testing/test_validator.py delete mode 100644 src-combined/utils/__init__.py delete mode 100644 src-combined/utils/analyzers_config.py delete mode 100644 src-combined/utils/ast_parser.py delete mode 100644 src-combined/utils/code_smells.py delete mode 100644 src-combined/utils/factory.py delete mode 100644 src-combined/utils/logger.py delete mode 100644 src1/analyzers/ternary_expression_pylint_analyzer.py create mode 100644 src1/outputs/code_carbon_ineffcient_code_example_1_log.txt create mode 100644 src1/outputs/code_carbon_refactored-test-case_log.txt delete mode 100644 test/carbon_report.csv delete mode 100644 test/inefficent_code_example.py rename {test => tests}/README.md (100%) rename {src1-tests => tests/input}/ineffcient_code_example_1.py (100%) rename {src1-tests => tests/input}/ineffcient_code_example_2.py (100%) rename test/high_energy_code_example.py => tests/input/ineffcient_code_example_3.py (100%) rename {test => tests}/test_analyzer.py (100%) rename {test => tests}/test_end_to_end.py (100%) rename {test => tests}/test_energy_measure.py (100%) rename {test => tests}/test_refactorer.py (100%) diff --git a/src-combined/README.md b/src-combined/README.md deleted file mode 100644 index 50aa3a2c..00000000 --- a/src-combined/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Project Name Source Code - -The folders and files for this project are as follows: - -... diff --git a/src-combined/__init__.py b/src-combined/__init__.py deleted file mode 100644 index 56f09c20..00000000 --- a/src-combined/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from . import analyzers -from . import measurement -from . import refactorer -from . import testing -from . import utils \ No newline at end of file diff --git a/src-combined/analyzers/__init__.py b/src-combined/analyzers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src-combined/analyzers/base_analyzer.py b/src-combined/analyzers/base_analyzer.py deleted file mode 100644 index af6a9f34..00000000 --- a/src-combined/analyzers/base_analyzer.py +++ /dev/null @@ -1,37 +0,0 @@ -from abc import ABC -import os - -class Analyzer(ABC): - """ - Base class for different types of analyzers. - """ - def __init__(self, file_path: str): - """ - Initializes the analyzer with a file path. - - :param file_path: Path to the file to be analyzed. - """ - self.file_path = os.path.abspath(file_path) - self.report_data: list[object] = [] - - def validate_file(self): - """ - Checks if the file path exists and is a file. - - :return: Boolean indicating file validity. - """ - return os.path.isfile(self.file_path) - - def analyze(self): - """ - Abstract method to be implemented by subclasses to perform analysis. - """ - raise NotImplementedError("Subclasses must implement this method.") - - def get_all_detected_smells(self): - """ - Retrieves all detected smells from the report data. - - :return: List of all detected code smells. - """ - return self.report_data diff --git a/src-combined/analyzers/pylint_analyzer.py b/src-combined/analyzers/pylint_analyzer.py deleted file mode 100644 index a2c27530..00000000 --- a/src-combined/analyzers/pylint_analyzer.py +++ /dev/null @@ -1,133 +0,0 @@ -import json -from io import StringIO -import ast -from re import sub -# ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN -# you will need to change imports too -# ====================================================== -# from os.path import dirname, abspath -# import sys - - -# # Sets src as absolute path, everything needs to be relative to src folder -# REFACTOR_DIR = dirname(abspath(__file__)) -# sys.path.append(dirname(REFACTOR_DIR)) - -from pylint.lint import Run -from pylint.reporters.json_reporter import JSON2Reporter - -from analyzers.base_analyzer import Analyzer - -from utils.analyzers_config import EXTRA_PYLINT_OPTIONS, CustomSmell, PylintSmell -from utils.analyzers_config import IntermediateSmells -from utils.ast_parser import parse_line - -class PylintAnalyzer(Analyzer): - def __init__(self, code_path: str): - super().__init__(code_path) - - def build_pylint_options(self): - """ - Constructs the list of pylint options for analysis, including extra options from config. - - :return: List of pylint options for analysis. - """ - return [self.file_path] + EXTRA_PYLINT_OPTIONS - - def analyze(self): - """ - Executes pylint on the specified file and captures the output in JSON format. - """ - if not self.validate_file(): - print(f"File not found: {self.file_path}") - return - - print(f"Running pylint analysis on {self.file_path}") - - # Capture pylint output in a JSON format buffer - with StringIO() as buffer: - reporter = JSON2Reporter(buffer) - pylint_options = self.build_pylint_options() - - try: - # Run pylint with JSONReporter - Run(pylint_options, reporter=reporter, exit=False) - - # Parse the JSON output - buffer.seek(0) - self.report_data = json.loads(buffer.getvalue()) - print("Pylint JSON analysis completed.") - except json.JSONDecodeError as e: - print("Failed to parse JSON output from pylint:", e) - except Exception as e: - print("An error occurred during pylint analysis:", e) - - def get_configured_smells(self): - filtered_results: list[object] = [] - - for error in self.report_data["messages"]: - if error["messageId"] in PylintSmell.list(): - filtered_results.append(error) - - for smell in IntermediateSmells.list(): - temp_smells = self.filter_for_one_code_smell(self.report_data["messages"], smell) - - if smell == IntermediateSmells.LINE_TOO_LONG.value: - filtered_results.extend(self.filter_long_lines(temp_smells)) - - with open("src/output/report.txt", "w+") as f: - print(json.dumps(filtered_results, indent=2), file=f) - - return filtered_results - - def filter_for_one_code_smell(self, pylint_results: list[object], code: str): - filtered_results: list[object] = [] - for error in pylint_results: - if error["messageId"] == code: - filtered_results.append(error) - - return filtered_results - - def filter_long_lines(self, long_line_smells: list[object]): - selected_smells: list[object] = [] - for smell in long_line_smells: - root_node = parse_line(self.file_path, smell["line"]) - - if root_node is None: - continue - - for node in ast.walk(root_node): - if isinstance(node, ast.IfExp): # Ternary expression node - smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value - selected_smells.append(smell) - break - - return selected_smells - -# Example usage -# if __name__ == "__main__": - -# FILE_PATH = abspath("test/inefficent_code_example.py") - -# analyzer = PylintAnalyzer(FILE_PATH) - -# # print("THIS IS REPORT for our smells:") -# report = analyzer.analyze() - -# with open("src/output/ast.txt", "w+") as f: -# print(parse_file(FILE_PATH), file=f) - -# filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") - - -# with open(FILE_PATH, "r") as f: -# file_lines = f.readlines() - -# for smell in filtered_results: -# with open("src/output/ast_lines.txt", "a+") as f: -# print("Parsing line ", smell["line"], file=f) -# print(parse_line(file_lines, smell["line"]), end="\n", file=f) - - - - diff --git a/src-combined/analyzers/ruff_analyzer.py b/src-combined/analyzers/ruff_analyzer.py deleted file mode 100644 index c771c2da..00000000 --- a/src-combined/analyzers/ruff_analyzer.py +++ /dev/null @@ -1,104 +0,0 @@ -import subprocess - -from os.path import abspath, dirname -import sys - -# Sets src as absolute path, everything needs to be relative to src folder -REFACTOR_DIR = dirname(abspath(__file__)) -sys.path.append(dirname(REFACTOR_DIR)) - -from analyzers.base_analyzer import BaseAnalyzer - -class RuffAnalyzer(BaseAnalyzer): - def __init__(self, code_path: str): - super().__init__(code_path) - # We are going to use the codes to identify the smells this is a dict of all of them - - def analyze(self): - """ - Runs pylint on the specified Python file and returns the output as a list of dictionaries. - Each dictionary contains information about a code smell or warning identified by pylint. - - :param file_path: The path to the Python file to be analyzed. - :return: A list of dictionaries with pylint messages. - """ - # Base command to run Ruff - command = ["ruff", "check", "--select", "ALL", self.code_path] - - # # Add config file option if specified - # if config_file: - # command.extend(["--config", config_file]) - - try: - # Run the command and capture output - result = subprocess.run(command, text=True, capture_output=True, check=True) - - # Print the output from Ruff - with open("output/ruff.txt", "a+") as f: - f.write(result.stdout) - # print("Ruff output:") - # print(result.stdout) - - except subprocess.CalledProcessError as e: - # If Ruff fails (e.g., lint errors), capture and print error output - print("Ruff encountered issues:") - print(e.stdout) # Ruff's linting output - print(e.stderr) # Any additional error information - sys.exit(1) # Exit with a non-zero status if Ruff fails - - # def filter_for_all_wanted_code_smells(self, pylint_results): - # statistics = {} - # report = [] - # filtered_results = [] - - # for error in pylint_results: - # if error["messageId"] in CodeSmells.list(): - # statistics[error["messageId"]] = True - # filtered_results.append(error) - - # report.append(filtered_results) - # report.append(statistics) - - # with open("src/output/report.txt", "w+") as f: - # print(json.dumps(report, indent=2), file=f) - - # return report - - # def filter_for_one_code_smell(self, pylint_results, code): - # filtered_results = [] - # for error in pylint_results: - # if error["messageId"] == code: - # filtered_results.append(error) - - # return filtered_results - -# Example usage -if __name__ == "__main__": - - FILE_PATH = abspath("test/inefficent_code_example.py") - OUTPUT_FILE = abspath("src/output/ruff.txt") - - analyzer = RuffAnalyzer(FILE_PATH) - - # print("THIS IS REPORT for our smells:") - analyzer.analyze() - - # print(report) - - # with open("src/output/ast.txt", "w+") as f: - # print(parse_file(FILE_PATH), file=f) - - # filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") - - - # with open(FILE_PATH, "r") as f: - # file_lines = f.readlines() - - # for smell in filtered_results: - # with open("src/output/ast_lines.txt", "a+") as f: - # print("Parsing line ", smell["line"], file=f) - # print(parse_line(file_lines, smell["line"]), end="\n", file=f) - - - - diff --git a/src-combined/main.py b/src-combined/main.py deleted file mode 100644 index 3a1a6726..00000000 --- a/src-combined/main.py +++ /dev/null @@ -1,83 +0,0 @@ -import json -import os -import sys - -from analyzers.pylint_analyzer import PylintAnalyzer -from measurement.code_carbon_meter import CarbonAnalyzer -from utils.factory import RefactorerFactory - -DIRNAME = os.path.dirname(__file__) - -# Define the output folder within the analyzers package -OUTPUT_FOLDER = os.path.join(DIRNAME, 'output/') - -# Ensure the output folder exists -os.makedirs(OUTPUT_FOLDER, exist_ok=True) - -def save_to_file(data, filename): - """ - Saves JSON data to a file in the output folder. - - :param data: Data to be saved. - :param filename: Name of the file to save data to. - """ - filepath = os.path.join(OUTPUT_FOLDER, filename) - with open(filepath, 'w+') as file: - json.dump(data, file, sort_keys=True, indent=4) - print(f"Output saved to {filepath.removeprefix(DIRNAME)}") - -def run_pylint_analysis(test_file_path): - print("\nStarting pylint analysis...") - - # Create an instance of PylintAnalyzer and run analysis - pylint_analyzer = PylintAnalyzer(test_file_path) - pylint_analyzer.analyze() - - # Save all detected smells to file - all_smells = pylint_analyzer.get_all_detected_smells() - save_to_file(all_smells["messages"], 'pylint_all_smells.json') - - # Example: Save only configured smells to file - configured_smells = pylint_analyzer.get_configured_smells() - save_to_file(configured_smells, 'pylint_configured_smells.json') - - return configured_smells - -def main(): - """ - Entry point for the refactoring tool. - - Create an instance of the analyzer. - - Perform code analysis and print the results. - """ - - # Get the file path from command-line arguments if provided, otherwise use the default - DEFAULT_TEST_FILE = os.path.join(DIRNAME, "../test/inefficent_code_example.py") - TEST_FILE = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_TEST_FILE - - # Check if the test file exists - if not os.path.isfile(TEST_FILE): - print(f"Error: The file '{TEST_FILE}' does not exist.") - return - - INITIAL_REPORT_FILE_PATH = os.path.join(OUTPUT_FOLDER, "initial_carbon_report.csv") - - carbon_analyzer = CarbonAnalyzer(TEST_FILE) - carbon_analyzer.run_and_measure() - carbon_analyzer.save_report(INITIAL_REPORT_FILE_PATH) - - detected_smells = run_pylint_analysis(TEST_FILE) - - for smell in detected_smells: - smell_id: str = smell["messageId"] - - print("Refactoring ", smell_id) - refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE) - - if refactoring_class: - refactoring_class.refactor() - else: - raise NotImplementedError("This refactoring has not been implemented yet.") - - -if __name__ == "__main__": - main() diff --git a/src-combined/measurement/__init__.py b/src-combined/measurement/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src-combined/measurement/code_carbon_meter.py b/src-combined/measurement/code_carbon_meter.py deleted file mode 100644 index f96f240b..00000000 --- a/src-combined/measurement/code_carbon_meter.py +++ /dev/null @@ -1,60 +0,0 @@ -import subprocess -import sys -from codecarbon import EmissionsTracker -from pathlib import Path -import pandas as pd -from os.path import dirname, abspath - -class CarbonAnalyzer: - def __init__(self, script_path: str): - self.script_path = script_path - self.tracker = EmissionsTracker(save_to_file=False, allow_multiple_runs=True) - - def run_and_measure(self): - script = Path(self.script_path) - if not script.exists() or script.suffix != ".py": - raise ValueError("Please provide a valid Python script path.") - self.tracker.start() - try: - subprocess.run([sys.executable, str(script)], check=True) - except subprocess.CalledProcessError as e: - print(f"Error: The script encountered an error: {e}") - finally: - # Stop tracking and get emissions data - emissions = self.tracker.stop() - if emissions is None or pd.isna(emissions): - print("Warning: No valid emissions data collected. Check system compatibility.") - else: - print("Emissions data:", emissions) - - def save_report(self, report_path: str): - """ - Save the emissions report to a CSV file with two columns: attribute and value. - """ - emissions_data = self.tracker.final_emissions_data - if emissions_data: - # Convert EmissionsData object to a dictionary and create rows for each attribute - emissions_dict = emissions_data.__dict__ - attributes = list(emissions_dict.keys()) - values = list(emissions_dict.values()) - - # Create a DataFrame with two columns: 'Attribute' and 'Value' - df = pd.DataFrame({ - "Attribute": attributes, - "Value": values - }) - - # Save the DataFrame to CSV - df.to_csv(report_path, index=False) - print(f"Report saved to {report_path}") - else: - print("No data to save. Ensure CodeCarbon supports your system hardware for emissions tracking.") - -# Example usage -if __name__ == "__main__": - REFACTOR_DIR = dirname(abspath(__file__)) - sys.path.append(dirname(REFACTOR_DIR)) - - analyzer = CarbonAnalyzer("src/output/inefficent_code_example.py") - analyzer.run_and_measure() - analyzer.save_report("src/output/test/carbon_report.csv") diff --git a/src-combined/measurement/custom_energy_measure.py b/src-combined/measurement/custom_energy_measure.py deleted file mode 100644 index 212fcd2f..00000000 --- a/src-combined/measurement/custom_energy_measure.py +++ /dev/null @@ -1,62 +0,0 @@ -import resource - -from measurement_utils import (start_process, calculate_ram_power, - start_pm_process, stop_pm_process, get_cpu_power_from_pm_logs) -import time - - -class CustomEnergyMeasure: - """ - Handles custom CPU and RAM energy measurements for executing a Python script. - Currently only works for Apple Silicon Chips with sudo access(password prompt in terminal) - Next step includes device detection for calculating on multiple platforms - """ - - def __init__(self, script_path: str): - self.script_path = script_path - self.results = {"cpu": 0.0, "ram": 0.0} - self.code_process_time = 0 - - def measure_cpu_power(self): - # start powermetrics as a child process - powermetrics_process = start_pm_process() - # allow time to enter password for sudo rights in mac - time.sleep(5) - try: - start_time = time.time() - # execute the provided code as another child process and wait to finish - code_process = start_process(["python3", self.script_path]) - code_process_pid = code_process.pid - code_process.wait() - end_time = time.time() - self.code_process_time = end_time - start_time - # Parse powermetrics log to extract CPU power data for this PID - finally: - stop_pm_process(powermetrics_process) - self.results["cpu"] = get_cpu_power_from_pm_logs("custom_energy_output.txt", code_process_pid) - - def measure_ram_power(self): - # execute provided code as a child process, this time without simultaneous powermetrics process - # code needs to rerun to use resource.getrusage() for a single child - # might look into another library that does not require this - code_process = start_process(["python3", self.script_path]) - code_process.wait() - - # get peak memory usage in bytes for this process - peak_memory_b = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss - - # calculate RAM power based on peak memory(3W/8GB ratio) - self.results["ram"] = calculate_ram_power(peak_memory_b) - - def calculate_energy_from_power(self): - # Return total energy consumed - total_power = self.results["cpu"] + self.results["ram"] # in watts - return total_power * self.code_process_time - - -if __name__ == "__main__": - custom_measure = CustomEnergyMeasure("/capstone--source-code-optimizer/test/high_energy_code_example.py") - custom_measure.measure_cpu_power() - custom_measure.measure_ram_power() - #can be saved as a report later - print(custom_measure.calculate_energy_from_power()) diff --git a/src-combined/measurement/energy_meter.py b/src-combined/measurement/energy_meter.py deleted file mode 100644 index 38426bf1..00000000 --- a/src-combined/measurement/energy_meter.py +++ /dev/null @@ -1,115 +0,0 @@ -import time -from typing import Callable -from pyJoules.device import DeviceFactory -from pyJoules.device.rapl_device import RaplPackageDomain, RaplDramDomain -from pyJoules.device.nvidia_device import NvidiaGPUDomain -from pyJoules.energy_meter import EnergyMeter - -## Required for installation -# pip install pyJoules -# pip install nvidia-ml-py3 - -# TEST TO SEE IF PYJOULE WORKS FOR YOU - - -class EnergyMeterWrapper: - """ - A class to measure the energy consumption of specific code blocks using PyJoules. - """ - - def __init__(self): - """ - Initializes the EnergyMeterWrapper class. - """ - # Create and configure the monitored devices - domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)] - devices = DeviceFactory.create_devices(domains) - self.meter = EnergyMeter(devices) - - def measure_energy(self, func: Callable, *args, **kwargs): - """ - Measures the energy consumed by the specified function during its execution. - - Parameters: - - func (Callable): The function to measure. - - *args: Arguments to pass to the function. - - **kwargs: Keyword arguments to pass to the function. - - Returns: - - tuple: A tuple containing the return value of the function and the energy consumed (in Joules). - """ - self.meter.start(tag="function_execution") # Start measuring energy - - start_time = time.time() # Record start time - - result = func(*args, **kwargs) # Call the specified function - - end_time = time.time() # Record end time - self.meter.stop() # Stop measuring energy - - # Retrieve the energy trace - trace = self.meter.get_trace() - total_energy = sum( - sample.energy for sample in trace - ) # Calculate total energy consumed - - # Log the timing (optional) - print(f"Execution Time: {end_time - start_time:.6f} seconds") - print(f"Energy Consumed: {total_energy:.6f} Joules") - - return ( - result, - total_energy, - ) # Return the result of the function and the energy consumed - - def measure_block(self, code_block: str): - """ - Measures energy consumption for a block of code represented as a string. - - Parameters: - - code_block (str): A string containing the code to execute. - - Returns: - - float: The energy consumed (in Joules). - """ - local_vars = {} - self.meter.start(tag="block_execution") # Start measuring energy - exec(code_block, {}, local_vars) # Execute the code block - self.meter.stop() # Stop measuring energy - - # Retrieve the energy trace - trace = self.meter.get_trace() - total_energy = sum( - sample.energy for sample in trace - ) # Calculate total energy consumed - print(f"Energy Consumed for the block: {total_energy:.6f} Joules") - return total_energy - - def measure_file_energy(self, file_path: str): - """ - Measures the energy consumption of the code in the specified Python file. - - Parameters: - - file_path (str): The path to the Python file. - - Returns: - - float: The energy consumed (in Joules). - """ - try: - with open(file_path, "r") as file: - code = file.read() # Read the content of the file - - # Execute the code block and measure energy consumption - return self.measure_block(code) - - except Exception as e: - print(f"An error occurred while measuring energy for the file: {e}") - return None # Return None in case of an error - - -# Example usage -if __name__ == "__main__": - meter = EnergyMeterWrapper() - energy_used = meter.measure_file_energy("../test/inefficent_code_example.py") - if energy_used is not None: - print(f"Total Energy Consumed: {energy_used:.6f} Joules") diff --git a/src-combined/measurement/measurement_utils.py b/src-combined/measurement/measurement_utils.py deleted file mode 100644 index 292698c9..00000000 --- a/src-combined/measurement/measurement_utils.py +++ /dev/null @@ -1,41 +0,0 @@ -import resource -import subprocess -import time -import re - - -def start_process(command): - return subprocess.Popen(command) - -def calculate_ram_power(memory_b): - memory_gb = memory_b / (1024 ** 3) - return memory_gb * 3 / 8 # 3W/8GB ratio - - -def start_pm_process(log_path="custom_energy_output.txt"): - powermetrics_process = subprocess.Popen( - ["sudo", "powermetrics", "--samplers", "tasks,cpu_power", "--show-process-gpu", "-i", "5000"], - stdout=open(log_path, "w"), - stderr=subprocess.PIPE - ) - return powermetrics_process - - -def stop_pm_process(powermetrics_process): - powermetrics_process.terminate() - -def get_cpu_power_from_pm_logs(log_path, pid): - cpu_share, total_cpu_power = None, None # in ms/s and mW respectively - with open(log_path, 'r') as file: - lines = file.readlines() - for line in lines: - if str(pid) in line: - cpu_share = float(line.split()[2]) - elif "CPU Power:" in line: - total_cpu_power = float(line.split()[2]) - if cpu_share and total_cpu_power: - break - if cpu_share and total_cpu_power: - cpu_power = (cpu_share / 1000) * (total_cpu_power / 1000) - return cpu_power - return None diff --git a/src-combined/output/ast.txt b/src-combined/output/ast.txt deleted file mode 100644 index bbeae637..00000000 --- a/src-combined/output/ast.txt +++ /dev/null @@ -1,470 +0,0 @@ -Module( - body=[ - ClassDef( - name='DataProcessor', - body=[ - FunctionDef( - name='__init__', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='data')]), - body=[ - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Store())], - value=Name(id='data', ctx=Load())), - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=List(ctx=Load()))]), - FunctionDef( - name='process_all_data', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Assign( - targets=[ - Name(id='results', ctx=Store())], - value=List(ctx=Load())), - For( - target=Name(id='item', ctx=Store()), - iter=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - body=[ - Try( - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=Call( - func=Attribute( - value=Name(id='self', ctx=Load()), - attr='complex_calculation', - ctx=Load()), - args=[ - Name(id='item', ctx=Load()), - Constant(value=True), - Constant(value=False), - Constant(value='multiply'), - Constant(value=10), - Constant(value=20), - Constant(value=None), - Constant(value='end')])), - Expr( - value=Call( - func=Attribute( - value=Name(id='results', ctx=Load()), - attr='append', - ctx=Load()), - args=[ - Name(id='result', ctx=Load())]))], - handlers=[ - ExceptHandler( - type=Name(id='Exception', ctx=Load()), - name='e', - body=[ - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Constant(value='An error occurred:'), - Name(id='e', ctx=Load())]))])])]), - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Call( - func=Attribute( - value=Call( - func=Attribute( - value=Call( - func=Attribute( - value=Call( - func=Attribute( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - attr='upper', - ctx=Load())), - attr='strip', - ctx=Load())), - attr='replace', - ctx=Load()), - args=[ - Constant(value=' '), - Constant(value='_')]), - attr='lower', - ctx=Load()))])), - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=Call( - func=Name(id='list', ctx=Load()), - args=[ - Call( - func=Name(id='filter', ctx=Load()), - args=[ - Lambda( - args=arguments( - args=[ - arg(arg='x')]), - body=BoolOp( - op=And(), - values=[ - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=None)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=0)]), - Compare( - left=Call( - func=Name(id='len', ctx=Load()), - args=[ - Call( - func=Name(id='str', ctx=Load()), - args=[ - Name(id='x', ctx=Load())])]), - ops=[ - Gt()], - comparators=[ - Constant(value=1)])])), - Name(id='results', ctx=Load())])])), - Return( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Load()))])]), - ClassDef( - name='AdvancedProcessor', - bases=[ - Name(id='DataProcessor', ctx=Load()), - Name(id='object', ctx=Load()), - Name(id='dict', ctx=Load()), - Name(id='list', ctx=Load()), - Name(id='set', ctx=Load()), - Name(id='tuple', ctx=Load())], - body=[ - Pass(), - FunctionDef( - name='check_data', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='item')]), - body=[ - Return( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]), - FunctionDef( - name='complex_comprehension', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=ListComp( - elt=IfExp( - test=Compare( - left=BinOp( - left=Name(id='x', ctx=Load()), - op=Mod(), - right=Constant(value=2)), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=BinOp( - left=Name(id='x', ctx=Load()), - op=Pow(), - right=Constant(value=2)), - orelse=BinOp( - left=Name(id='x', ctx=Load()), - op=Pow(), - right=Constant(value=3))), - generators=[ - comprehension( - target=Name(id='x', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=1), - Constant(value=100)]), - ifs=[ - BoolOp( - op=And(), - values=[ - Compare( - left=BinOp( - left=Name(id='x', ctx=Load()), - op=Mod(), - right=Constant(value=5)), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=50)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=3)])])], - is_async=0)]))]), - FunctionDef( - name='long_chain', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Try( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load())), - Return( - value=Name(id='deep_value', ctx=Load()))], - handlers=[ - ExceptHandler( - type=Name(id='KeyError', ctx=Load()), - body=[ - Return( - value=Constant(value=None))])])]), - FunctionDef( - name='long_scope_chaining', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - For( - target=Name(id='a', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='b', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='c', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='d', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='e', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - If( - test=Compare( - left=BinOp( - left=BinOp( - left=BinOp( - left=BinOp( - left=Name(id='a', ctx=Load()), - op=Add(), - right=Name(id='b', ctx=Load())), - op=Add(), - right=Name(id='c', ctx=Load())), - op=Add(), - right=Name(id='d', ctx=Load())), - op=Add(), - right=Name(id='e', ctx=Load())), - ops=[ - Gt()], - comparators=[ - Constant(value=25)]), - body=[ - Return( - value=Constant(value='Done'))])])])])])])]), - FunctionDef( - name='complex_calculation', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='item'), - arg(arg='flag1'), - arg(arg='flag2'), - arg(arg='operation'), - arg(arg='threshold'), - arg(arg='max_value'), - arg(arg='option'), - arg(arg='final_stage')]), - body=[ - If( - test=Compare( - left=Name(id='operation', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='multiply')]), - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=BinOp( - left=Name(id='item', ctx=Load()), - op=Mult(), - right=Name(id='threshold', ctx=Load())))], - orelse=[ - If( - test=Compare( - left=Name(id='operation', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='add')]), - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=BinOp( - left=Name(id='item', ctx=Load()), - op=Add(), - right=Name(id='max_value', ctx=Load())))], - orelse=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=Name(id='item', ctx=Load()))])]), - Return( - value=Name(id='result', ctx=Load()))])]), - If( - test=Compare( - left=Name(id='__name__', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='__main__')]), - body=[ - Assign( - targets=[ - Name(id='sample_data', ctx=Store())], - value=List( - elts=[ - Constant(value=1), - Constant(value=2), - Constant(value=3), - Constant(value=4), - Constant(value=5)], - ctx=Load())), - Assign( - targets=[ - Name(id='processor', ctx=Store())], - value=Call( - func=Name(id='DataProcessor', ctx=Load()), - args=[ - Name(id='sample_data', ctx=Load())])), - Assign( - targets=[ - Name(id='processed', ctx=Store())], - value=Call( - func=Attribute( - value=Name(id='processor', ctx=Load()), - attr='process_all_data', - ctx=Load()))), - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Constant(value='Processed Data:'), - Name(id='processed', ctx=Load())]))])]) diff --git a/src-combined/output/ast_lines.txt b/src-combined/output/ast_lines.txt deleted file mode 100644 index 76343f17..00000000 --- a/src-combined/output/ast_lines.txt +++ /dev/null @@ -1,240 +0,0 @@ -Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) -Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) -Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) diff --git a/src-combined/output/carbon_report.csv b/src-combined/output/carbon_report.csv deleted file mode 100644 index fd11fa7f..00000000 --- a/src-combined/output/carbon_report.csv +++ /dev/null @@ -1,3 +0,0 @@ -timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue -2024-11-06T15:32:34,codecarbon,ab07718b-de1c-496e-91b2-c0ffd4e84ef5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.1535916000138968,2.214386652360756e-08,1.4417368216493612e-07,7.5,0.0,6.730809688568115,3.176875000159877e-07,0,2.429670854124108e-07,5.606545854283984e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 -2024-11-06T15:37:39,codecarbon,515a920a-2566-4af3-92ef-5b930f41ca18,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.15042520000133663,2.1765796594351643e-08,1.4469514811453293e-07,7.5,0.0,6.730809688568115,3.1103791661735157e-07,0,2.400444182185886e-07,5.510823348359402e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 diff --git a/src-combined/output/initial_carbon_report.csv b/src-combined/output/initial_carbon_report.csv deleted file mode 100644 index d8679a2d..00000000 --- a/src-combined/output/initial_carbon_report.csv +++ /dev/null @@ -1,33 +0,0 @@ -Attribute,Value -timestamp,2024-11-07T14:12:05 -project_name,codecarbon -run_id,bf175e4d-2118-497c-a6b8-cbaf00eee02d -experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,0.1537123000016436 -emissions,2.213841482744185e-08 -emissions_rate,1.4402500533272308e-07 -cpu_power,7.5 -gpu_power,0.0 -ram_power,6.730809688568115 -cpu_energy,3.177435416243194e-07 -gpu_energy,0 -ram_energy,2.427730137789067e-07 -energy_consumed,5.605165554032261e-07 -country_name,Canada -country_iso_code,CAN -region,ontario -cloud_provider, -cloud_region, -os,Windows-11-10.0.22631-SP0 -python_version,3.13.0 -codecarbon_version,2.7.2 -cpu_count,8 -cpu_model,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx -gpu_count, -gpu_model, -longitude,-79.9441 -latitude,43.266 -ram_total_size,17.94882583618164 -tracking_mode,machine -on_cloud,N -pue,1.0 diff --git a/src-combined/output/pylint_all_smells.json b/src-combined/output/pylint_all_smells.json deleted file mode 100644 index 3f3e1cfb..00000000 --- a/src-combined/output/pylint_all_smells.json +++ /dev/null @@ -1,437 +0,0 @@ -[ - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 19, - "message": "Line too long (87/80)", - "messageId": "C0301", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 41, - "message": "Line too long (87/80)", - "messageId": "C0301", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 57, - "message": "Line too long (85/80)", - "messageId": "C0301", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 74, - "message": "Line too long (86/80)", - "messageId": "C0301", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "HIGH", - "endColumn": null, - "endLine": null, - "line": 1, - "message": "Missing module docstring", - "messageId": "C0114", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-module-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "HIGH", - "endColumn": 19, - "endLine": 2, - "line": 2, - "message": "Missing class docstring", - "messageId": "C0115", - "module": "inefficent_code_example", - "obj": "DataProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 24, - "endLine": 8, - "line": 8, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 16, - "confidence": "INFERENCE", - "endColumn": 25, - "endLine": 18, - "line": 18, - "message": "Catching too general exception Exception", - "messageId": "W0718", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "broad-exception-caught", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 25, - "confidence": "INFERENCE", - "endColumn": 49, - "endLine": 13, - "line": 13, - "message": "Instance of 'DataProcessor' has no 'complex_calculation' member", - "messageId": "E1101", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "no-member", - "type": "error" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 29, - "confidence": "UNDEFINED", - "endColumn": 38, - "endLine": 27, - "line": 27, - "message": "Comparison 'x != None' should be 'x is not None'", - "messageId": "C0121", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data.", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "singleton-comparison", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": 19, - "endLine": 2, - "line": 2, - "message": "Too few public methods (1/2)", - "messageId": "R0903", - "module": "inefficent_code_example", - "obj": "DataProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-few-public-methods", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "HIGH", - "endColumn": 23, - "endLine": 35, - "line": 35, - "message": "Missing class docstring", - "messageId": "C0115", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": 23, - "endLine": 35, - "line": 35, - "message": "Class 'AdvancedProcessor' inherits from object, can be safely removed from bases in python3", - "messageId": "R0205", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "useless-object-inheritance", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": 23, - "endLine": 35, - "line": 35, - "message": "Inconsistent method resolution order for class 'AdvancedProcessor'", - "messageId": "E0240", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "inconsistent-mro", - "type": "error" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "UNDEFINED", - "endColumn": 8, - "endLine": 36, - "line": 36, - "message": "Unnecessary pass statement", - "messageId": "W0107", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "unnecessary-pass", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 18, - "endLine": 39, - "line": 39, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.check_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 29, - "endLine": 45, - "line": 45, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_comprehension", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 18, - "endLine": 54, - "line": 54, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.long_chain", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 27, - "endLine": 63, - "line": 63, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "UNDEFINED", - "endColumn": 27, - "endLine": 63, - "line": 63, - "message": "Too many branches (6/3)", - "messageId": "R0912", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-many-branches", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 8, - "confidence": "UNDEFINED", - "endColumn": 45, - "endLine": 70, - "line": 64, - "message": "Too many nested blocks (6/3)", - "messageId": "R1702", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-many-nested-blocks", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "UNDEFINED", - "endColumn": 27, - "endLine": 63, - "line": 63, - "message": "Either all return statements in a function should return an expression, or none of them should.", - "messageId": "R1710", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "inconsistent-return-statements", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "INFERENCE", - "endColumn": 27, - "endLine": 73, - "line": 73, - "message": "Missing function or method docstring", - "messageId": "C0116", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "UNDEFINED", - "endColumn": 27, - "endLine": 73, - "line": 73, - "message": "Too many arguments (9/5)", - "messageId": "R0913", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "HIGH", - "endColumn": 27, - "endLine": 73, - "line": 73, - "message": "Too many positional arguments (9/5)", - "messageId": "R0917", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-many-positional-arguments", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 20, - "confidence": "INFERENCE", - "endColumn": 25, - "endLine": 74, - "line": 74, - "message": "Unused argument 'flag1'", - "messageId": "W0613", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 27, - "confidence": "INFERENCE", - "endColumn": 32, - "endLine": 74, - "line": 74, - "message": "Unused argument 'flag2'", - "messageId": "W0613", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 67, - "confidence": "INFERENCE", - "endColumn": 73, - "endLine": 74, - "line": 74, - "message": "Unused argument 'option'", - "messageId": "W0613", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 75, - "confidence": "INFERENCE", - "endColumn": 86, - "endLine": 74, - "line": 74, - "message": "Unused argument 'final_stage'", - "messageId": "W0613", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "unused-argument", - "type": "warning" - } -] \ No newline at end of file diff --git a/src-combined/output/pylint_configured_smells.json b/src-combined/output/pylint_configured_smells.json deleted file mode 100644 index 256b1a84..00000000 --- a/src-combined/output/pylint_configured_smells.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 4, - "confidence": "UNDEFINED", - "endColumn": 27, - "endLine": 73, - "line": 73, - "message": "Too many arguments (9/5)", - "messageId": "R0913", - "module": "inefficent_code_example", - "obj": "AdvancedProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "column": 0, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 41, - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "module": "inefficent_code_example", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "symbol": "line-too-long", - "type": "convention" - } -] \ No newline at end of file diff --git a/src-combined/output/report.txt b/src-combined/output/report.txt deleted file mode 100644 index 2c1a3c0b..00000000 --- a/src-combined/output/report.txt +++ /dev/null @@ -1,152 +0,0 @@ -[ - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 19, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (85/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 57, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (86/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 74, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "CUST-1", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - } -] diff --git a/src-combined/refactorer/__init__.py b/src-combined/refactorer/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src-combined/refactorer/base_refactorer.py b/src-combined/refactorer/base_refactorer.py deleted file mode 100644 index 3450ad9f..00000000 --- a/src-combined/refactorer/base_refactorer.py +++ /dev/null @@ -1,26 +0,0 @@ -# src/refactorer/base_refactorer.py - -from abc import ABC, abstractmethod - - -class BaseRefactorer(ABC): - """ - Abstract base class for refactorers. - Subclasses should implement the `refactor` method. - """ - @abstractmethod - def __init__(self, code): - """ - Initialize the refactorer with the code to refactor. - - :param code: The code that needs refactoring - """ - self.code = code - - @abstractmethod - def refactor(code_smell_error, input_code): - """ - Perform the refactoring process. - Must be implemented by subclasses. - """ - pass diff --git a/src-combined/refactorer/complex_list_comprehension_refactorer.py b/src-combined/refactorer/complex_list_comprehension_refactorer.py deleted file mode 100644 index 7bf924b8..00000000 --- a/src-combined/refactorer/complex_list_comprehension_refactorer.py +++ /dev/null @@ -1,116 +0,0 @@ -import ast -import astor -from .base_refactorer import BaseRefactorer - -class ComplexListComprehensionRefactorer(BaseRefactorer): - """ - Refactorer for complex list comprehensions to improve readability. - """ - - def __init__(self, code: str): - """ - Initializes the refactorer. - - :param code: The source code to refactor. - """ - super().__init__(code) - - def refactor(self): - """ - Refactor the code by transforming complex list comprehensions into for-loops. - - :return: The refactored code. - """ - # Parse the code to get the AST - tree = ast.parse(self.code) - - # Walk through the AST and refactor complex list comprehensions - for node in ast.walk(tree): - if isinstance(node, ast.ListComp): - # Check if the list comprehension is complex - if self.is_complex(node): - # Create a for-loop equivalent - for_loop = self.create_for_loop(node) - # Replace the list comprehension with the for-loop in the AST - self.replace_node(node, for_loop) - - # Convert the AST back to code - return self.ast_to_code(tree) - - def create_for_loop(self, list_comp: ast.ListComp) -> ast.For: - """ - Create a for-loop that represents the list comprehension. - - :param list_comp: The ListComp node to convert. - :return: An ast.For node representing the for-loop. - """ - # Create the variable to hold results - result_var = ast.Name(id='result', ctx=ast.Store()) - - # Create the for-loop - for_loop = ast.For( - target=ast.Name(id='item', ctx=ast.Store()), - iter=list_comp.generators[0].iter, - body=[ - ast.Expr(value=ast.Call( - func=ast.Name(id='append', ctx=ast.Load()), - args=[self.transform_value(list_comp.elt)], - keywords=[] - )) - ], - orelse=[] - ) - - # Create a list to hold results - result_list = ast.List(elts=[], ctx=ast.Store()) - return ast.With( - context_expr=ast.Name(id='result', ctx=ast.Load()), - body=[for_loop], - lineno=list_comp.lineno, - col_offset=list_comp.col_offset - ) - - def transform_value(self, value_node: ast.AST) -> ast.AST: - """ - Transform the value in the list comprehension into a form usable in a for-loop. - - :param value_node: The value node to transform. - :return: The transformed value node. - """ - return value_node - - def replace_node(self, old_node: ast.AST, new_node: ast.AST): - """ - Replace an old node in the AST with a new node. - - :param old_node: The node to replace. - :param new_node: The node to insert in its place. - """ - parent = self.find_parent(old_node) - if parent: - for index, child in enumerate(ast.iter_child_nodes(parent)): - if child is old_node: - parent.body[index] = new_node - break - - def find_parent(self, node: ast.AST) -> ast.AST: - """ - Find the parent node of a given AST node. - - :param node: The node to find the parent for. - :return: The parent node, or None if not found. - """ - for parent in ast.walk(node): - for child in ast.iter_child_nodes(parent): - if child is node: - return parent - return None - - def ast_to_code(self, tree: ast.AST) -> str: - """ - Convert AST back to source code. - - :param tree: The AST to convert. - :return: The source code as a string. - """ - return astor.to_source(tree) diff --git a/src-combined/refactorer/large_class_refactorer.py b/src-combined/refactorer/large_class_refactorer.py deleted file mode 100644 index c4af6ba3..00000000 --- a/src-combined/refactorer/large_class_refactorer.py +++ /dev/null @@ -1,83 +0,0 @@ -import ast - -class LargeClassRefactorer: - """ - Refactorer for large classes that have too many methods. - """ - - def __init__(self, code: str, method_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of methods above which a class is considered large. - """ - super().__init__(code) - self.method_threshold = method_threshold - - def refactor(self): - """ - Refactor the class by splitting it into smaller classes if it exceeds the method threshold. - - :return: The refactored code. - """ - # Parse the code to get the class definition - tree = ast.parse(self.code) - class_definitions = [node for node in tree.body if isinstance(node, ast.ClassDef)] - - refactored_code = [] - - for class_def in class_definitions: - methods = [n for n in class_def.body if isinstance(n, ast.FunctionDef)] - if len(methods) > self.method_threshold: - # If the class is large, split it - new_classes = self.split_class(class_def, methods) - refactored_code.extend(new_classes) - else: - # Keep the class as is - refactored_code.append(class_def) - - # Convert the AST back to code - return self.ast_to_code(refactored_code) - - def split_class(self, class_def, methods): - """ - Split the large class into smaller classes based on methods. - - :param class_def: The class definition node. - :param methods: The list of methods in the class. - :return: A list of new class definitions. - """ - # For demonstration, we'll simply create two classes based on the method count - half_index = len(methods) // 2 - new_class1 = self.create_new_class(class_def.name + "Part1", methods[:half_index]) - new_class2 = self.create_new_class(class_def.name + "Part2", methods[half_index:]) - - return [new_class1, new_class2] - - def create_new_class(self, new_class_name, methods): - """ - Create a new class definition with the specified methods. - - :param new_class_name: Name of the new class. - :param methods: List of methods to include in the new class. - :return: A new class definition node. - """ - # Create the class definition with methods - class_def = ast.ClassDef( - name=new_class_name, - bases=[], - body=methods, - decorator_list=[] - ) - return class_def - - def ast_to_code(self, nodes): - """ - Convert AST nodes back to source code. - - :param nodes: The AST nodes to convert. - :return: The source code as a string. - """ - import astor - return astor.to_source(nodes) diff --git a/src-combined/refactorer/long_base_class_list.py b/src-combined/refactorer/long_base_class_list.py deleted file mode 100644 index fdd15297..00000000 --- a/src-combined/refactorer/long_base_class_list.py +++ /dev/null @@ -1,14 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongBaseClassListRefactorer(BaseRefactorer): - """ - Refactorer that targets long base class lists to improve performance. - """ - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src-combined/refactorer/long_element_chain.py b/src-combined/refactorer/long_element_chain.py deleted file mode 100644 index 6c168afa..00000000 --- a/src-combined/refactorer/long_element_chain.py +++ /dev/null @@ -1,21 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongElementChainRefactorer(BaseRefactorer): - """ - Refactorer for data objects (dictionary) that have too many deeply nested elements inside. - Ex: deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] - """ - - def __init__(self, code: str, element_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of nested elements allowed before dictionary has too many deeply nested elements. - """ - super().__init__(code) - self.element_threshold = element_threshold - - def refactor(self): - - return self.code \ No newline at end of file diff --git a/src-combined/refactorer/long_lambda_function_refactorer.py b/src-combined/refactorer/long_lambda_function_refactorer.py deleted file mode 100644 index 421ada60..00000000 --- a/src-combined/refactorer/long_lambda_function_refactorer.py +++ /dev/null @@ -1,16 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongLambdaFunctionRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src-combined/refactorer/long_message_chain_refactorer.py b/src-combined/refactorer/long_message_chain_refactorer.py deleted file mode 100644 index 2438910f..00000000 --- a/src-combined/refactorer/long_message_chain_refactorer.py +++ /dev/null @@ -1,17 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongMessageChainRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src-combined/refactorer/long_method_refactorer.py b/src-combined/refactorer/long_method_refactorer.py deleted file mode 100644 index 734afa67..00000000 --- a/src-combined/refactorer/long_method_refactorer.py +++ /dev/null @@ -1,18 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongMethodRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src-combined/refactorer/long_scope_chaining.py b/src-combined/refactorer/long_scope_chaining.py deleted file mode 100644 index 39e53316..00000000 --- a/src-combined/refactorer/long_scope_chaining.py +++ /dev/null @@ -1,24 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongScopeRefactorer(BaseRefactorer): - """ - Refactorer for methods that have too many deeply nested loops. - """ - def __init__(self, code: str, loop_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of loops allowed before method is considered one with too many nested loops. - """ - super().__init__(code) - self.loop_threshold = loop_threshold - - def refactor(self): - """ - Refactor code by ... - - Return: refactored code - """ - - return self.code \ No newline at end of file diff --git a/src-combined/refactorer/long_ternary_cond_expression.py b/src-combined/refactorer/long_ternary_cond_expression.py deleted file mode 100644 index 994ccfc3..00000000 --- a/src-combined/refactorer/long_ternary_cond_expression.py +++ /dev/null @@ -1,17 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LTCERefactorer(BaseRefactorer): - """ - Refactorer that targets long ternary conditional expressions (LTCEs) to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor LTCEs into smaller methods. - Implement the logic to detect and refactor LTCEs. - """ - # Logic to identify LTCEs goes here - pass diff --git a/src-combined/testing/__init__.py b/src-combined/testing/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src-combined/testing/test_runner.py b/src-combined/testing/test_runner.py deleted file mode 100644 index 84fe92a9..00000000 --- a/src-combined/testing/test_runner.py +++ /dev/null @@ -1,17 +0,0 @@ -import unittest -import os -import sys - -# Add the src directory to the path to import modules -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) - -# Discover and run all tests in the 'tests' directory -def run_tests(): - test_loader = unittest.TestLoader() - test_suite = test_loader.discover('tests', pattern='*.py') - - test_runner = unittest.TextTestRunner(verbosity=2) - test_runner.run(test_suite) - -if __name__ == '__main__': - run_tests() diff --git a/src-combined/testing/test_validator.py b/src-combined/testing/test_validator.py deleted file mode 100644 index cbbb29d4..00000000 --- a/src-combined/testing/test_validator.py +++ /dev/null @@ -1,3 +0,0 @@ -def validate_output(original, refactored): - # Compare original and refactored output - return original == refactored diff --git a/src-combined/utils/__init__.py b/src-combined/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src-combined/utils/analyzers_config.py b/src-combined/utils/analyzers_config.py deleted file mode 100644 index d65c646d..00000000 --- a/src-combined/utils/analyzers_config.py +++ /dev/null @@ -1,49 +0,0 @@ -# Any configurations that are done by the analyzers -from enum import Enum -from itertools import chain - -class ExtendedEnum(Enum): - - @classmethod - def list(cls) -> list[str]: - return [c.value for c in cls] - - def __str__(self): - return str(self.value) - -# ============================================= -# IMPORTANT -# ============================================= -# Make sure any new smells are added to the factory in this same directory -class PylintSmell(ExtendedEnum): - LONG_MESSAGE_CHAIN = "R0914" # pylint smell - LARGE_CLASS = "R0902" # pylint smell - LONG_PARAMETER_LIST = "R0913" # pylint smell - LONG_METHOD = "R0915" # pylint smell - COMPLEX_LIST_COMPREHENSION = "C0200" # pylint smell - INVALID_NAMING_CONVENTIONS = "C0103" # pylint smell - -class CustomSmell(ExtendedEnum): - LONG_TERN_EXPR = "CUST-1" # custom smell - -# Smells that lead to wanted smells -class IntermediateSmells(ExtendedEnum): - LINE_TOO_LONG = "C0301" # pylint smell - -# Enum containing a combination of all relevant smells -class AllSmells(ExtendedEnum): - _ignore_ = 'member cls' - cls = vars() - for member in chain(list(PylintSmell), list(CustomSmell)): - cls[member.name] = member.value - -# List of all codes -SMELL_CODES = [s.value for s in AllSmells] - -# Extra pylint options -EXTRA_PYLINT_OPTIONS = [ - "--max-line-length=80", - "--max-nested-blocks=3", - "--max-branches=3", - "--max-parents=3" -] diff --git a/src-combined/utils/ast_parser.py b/src-combined/utils/ast_parser.py deleted file mode 100644 index 6a7f6fd8..00000000 --- a/src-combined/utils/ast_parser.py +++ /dev/null @@ -1,17 +0,0 @@ -import ast - -def parse_line(file: str, line: int): - with open(file, "r") as f: - file_lines = f.readlines() - try: - node = ast.parse(file_lines[line - 1].strip()) - except(SyntaxError) as e: - return None - - return node - -def parse_file(file: str): - with open(file, "r") as f: - source = f.read() - - return ast.parse(source) \ No newline at end of file diff --git a/src-combined/utils/code_smells.py b/src-combined/utils/code_smells.py deleted file mode 100644 index 0a9391bd..00000000 --- a/src-combined/utils/code_smells.py +++ /dev/null @@ -1,22 +0,0 @@ -from enum import Enum - -class ExtendedEnum(Enum): - - @classmethod - def list(cls) -> list[str]: - return [c.value for c in cls] - -class CodeSmells(ExtendedEnum): - # Add codes here - LINE_TOO_LONG = "C0301" - LONG_MESSAGE_CHAIN = "R0914" - LONG_LAMBDA_FUNC = "R0914" - LONG_TERN_EXPR = "CUST-1" - # "R0902": LargeClassRefactorer, # Too many instance attributes - # "R0913": "Long Parameter List", # Too many arguments - # "R0915": "Long Method", # Too many statements - # "C0200": "Complex List Comprehension", # Loop can be simplified - # "C0103": "Invalid Naming Convention", # Non-standard names - - def __str__(self): - return str(self.value) diff --git a/src-combined/utils/factory.py b/src-combined/utils/factory.py deleted file mode 100644 index 6a915d7b..00000000 --- a/src-combined/utils/factory.py +++ /dev/null @@ -1,21 +0,0 @@ -from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer as LLFR -from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer as LMCR -from refactorer.long_ternary_cond_expression import LTCERefactorer as LTCER - -from refactorer.base_refactorer import BaseRefactorer - -from utils.analyzers_config import CustomSmell, PylintSmell - -class RefactorerFactory(): - - @staticmethod - def build(smell_name: str, file_path: str) -> BaseRefactorer: - selected = None - match smell_name: - case PylintSmell.LONG_MESSAGE_CHAIN: - selected = LMCR(file_path) - case CustomSmell.LONG_TERN_EXPR: - selected = LTCER(file_path) - case _: - selected = None - return selected \ No newline at end of file diff --git a/src-combined/utils/logger.py b/src-combined/utils/logger.py deleted file mode 100644 index 711c62b5..00000000 --- a/src-combined/utils/logger.py +++ /dev/null @@ -1,34 +0,0 @@ -import logging -import os - -def setup_logger(log_file: str = "app.log", log_level: int = logging.INFO): - """ - Set up the logger configuration. - - Args: - log_file (str): The name of the log file to write logs to. - log_level (int): The logging level (default is INFO). - - Returns: - Logger: Configured logger instance. - """ - # Create log directory if it does not exist - log_directory = os.path.dirname(log_file) - if log_directory and not os.path.exists(log_directory): - os.makedirs(log_directory) - - # Configure the logger - logging.basicConfig( - filename=log_file, - filemode='a', # Append mode - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=log_level, - ) - - logger = logging.getLogger(__name__) - return logger - -# # Example usage -# if __name__ == "__main__": -# logger = setup_logger() # You can customize the log file and level here -# logger.info("Logger is set up and ready to use.") diff --git a/src1/analyzers/base_analyzer.py b/src1/analyzers/base_analyzer.py index 29377637..5a287c5a 100644 --- a/src1/analyzers/base_analyzer.py +++ b/src1/analyzers/base_analyzer.py @@ -3,7 +3,7 @@ from utils.logger import Logger class Analyzer(ABC): - def __init__(self, file_path, logger): + def __init__(self, file_path: str, logger: Logger): """ Base class for analyzers to find code smells of a given file. @@ -11,7 +11,7 @@ def __init__(self, file_path, logger): :param logger: Logger instance to handle log messages. """ self.file_path = file_path - self.smells_data = [] + self.smells_data: list[object] = [] self.logger = logger # Use logger instance def validate_file(self): @@ -26,7 +26,7 @@ def validate_file(self): return is_valid @abstractmethod - def analyze_smells(self): + def analyze(self): """ Abstract method to analyze the code smells of the specified file. Must be implemented by subclasses. diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index 95e953d6..a71b494d 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -1,21 +1,20 @@ import json +import ast import os + from pylint.lint import Run from pylint.reporters.json_reporter import JSONReporter from io import StringIO + +from utils.logger import Logger + from .base_analyzer import Analyzer -from .ternary_expression_pylint_analyzer import TernaryExpressionPylintAnalyzer -from utils.analyzers_config import AllPylintSmells, EXTRA_PYLINT_OPTIONS +from utils.analyzers_config import PylintSmell, CustomSmell, IntermediateSmells, EXTRA_PYLINT_OPTIONS + +from utils.ast_parser import parse_line class PylintAnalyzer(Analyzer): - def __init__(self, file_path, logger): - """ - Initializes the PylintAnalyzer with a file path and logger, - setting up attributes to collect code smells. - - :param file_path: Path to the file to be analyzed. - :param logger: Logger instance to handle log messages. - """ + def __init__(self, file_path: str, logger: Logger): super().__init__(file_path, logger) def build_pylint_options(self): @@ -25,8 +24,8 @@ def build_pylint_options(self): :return: List of pylint options for analysis. """ return [self.file_path] + EXTRA_PYLINT_OPTIONS - - def analyze_smells(self): + + def analyze(self): """ Executes pylint on the specified file and captures the output in JSON format. """ @@ -53,36 +52,42 @@ def analyze_smells(self): except Exception as e: self.logger.log(f"An error occurred during pylint analysis: {e}") - self._find_custom_pylint_smells() # Find all custom smells in pylint-detected data - - def _find_custom_pylint_smells(self): + def configure_smells(self): """ - Identifies custom smells, like long ternary expressions, in Pylint-detected data. - Updates self.smells_data with any new custom smells found. + Filters the report data to retrieve only the smells with message IDs specified in the config. """ - self.logger.log("Examining pylint smells for custom code smells") - ternary_analyzer = TernaryExpressionPylintAnalyzer(self.file_path, self.smells_data) - self.smells_data = ternary_analyzer.detect_long_ternary_expressions() + self.logger.log("Filtering pylint smells") - def get_smells_by_name(self, smell): + configured_smells: list[object] = [] + + for smell in self.smells_data: + if smell["message-id"] in PylintSmell.list(): + configured_smells.append(smell) + + if smell == IntermediateSmells.LINE_TOO_LONG.value: + self.filter_ternary(smell) + + self.smells_data = configured_smells + + def filter_for_one_code_smell(self, pylint_results: list[object], code: str): """ - Retrieves smells based on the Smell enum (e.g., Smell.LONG_MESSAGE_CHAIN). - - :param smell: The Smell enum member to filter by. - :return: List of report entries matching the smell name. + Filters LINE_TOO_LONG smells to find ternary expression smells """ - return [ - item for item in self.smells_data - if item.get("message-id") == smell.value - ] + filtered_results: list[object] = [] + for error in pylint_results: + if error["message-id"] == code: + filtered_results.append(error) - def get_configured_smells(self): - """ - Filters the report data to retrieve only the smells with message IDs specified in the config. + return filtered_results + + def filter_ternary(self, smell: object): + root_node = parse_line(self.file_path, smell["line"]) - :return: List of detected code smells based on the configuration. - """ - configured_smells = [] - for smell in AllPylintSmells: - configured_smells.extend(self.get_smells_by_name(smell)) - return configured_smells + if root_node is None: + return + + for node in ast.walk(root_node): + if isinstance(node, ast.IfExp): # Ternary expression node + smell["message-id"] = CustomSmell.LONG_TERN_EXPR.value + self.smells_data.append(smell) + break \ No newline at end of file diff --git a/src1/analyzers/ternary_expression_pylint_analyzer.py b/src1/analyzers/ternary_expression_pylint_analyzer.py deleted file mode 100644 index fbca4636..00000000 --- a/src1/analyzers/ternary_expression_pylint_analyzer.py +++ /dev/null @@ -1,35 +0,0 @@ -import ast -from utils.ast_parser import parse_line -from utils.analyzers_config import AllPylintSmells - -class TernaryExpressionPylintAnalyzer: - def __init__(self, file_path, smells_data): - """ - Initializes with smells data from PylintAnalyzer to find long ternary - expressions. - - :param file_path: Path to file used by PylintAnalyzer. - :param smells_data: List of smells from PylintAnalyzer. - """ - self.file_path = file_path - self.smells_data = smells_data - - def detect_long_ternary_expressions(self): - """ - Processes long lines to identify ternary expressions. - - :return: List of smells with updated ternary expression detection message IDs. - """ - for smell in self.smells_data: - if smell.get("message-id") == AllPylintSmells.LINE_TOO_LONG.value: - root_node = parse_line(self.file_path, smell["line"]) - - if root_node is None: - continue - - for node in ast.walk(root_node): - if isinstance(node, ast.IfExp): # Ternary expression node - smell["message-id"] = AllPylintSmells.LONG_TERN_EXPR.value - break - - return self.smells_data diff --git a/src1/main.py b/src1/main.py index 3ab6cc68..699bb031 100644 --- a/src1/main.py +++ b/src1/main.py @@ -1,23 +1,21 @@ -import json import os +from utils.outputs_config import save_json_files, copy_file_to_output + from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter from analyzers.pylint_analyzer import PylintAnalyzer -from utils.outputs_config import save_json_files, copy_file_to_output from utils.refactorer_factory import RefactorerFactory from utils.logger import Logger +DIRNAME = os.path.dirname(__file__) def main(): # Path to the file to be analyzed - test_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src1-tests/ineffcient_code_example_1.py")) + TEST_FILE = os.path.abspath(os.path.join(DIRNAME, "../tests/input/ineffcient_code_example_1.py")) # Set up logging - log_file = os.path.join(os.path.dirname(__file__), "outputs/log.txt") - logger = Logger(log_file) - - - + LOG_FILE = os.path.join(DIRNAME, "outputs/log.txt") + logger = Logger(LOG_FILE) # Log start of emissions capture logger.log("#####################################################################################################") @@ -25,7 +23,7 @@ def main(): logger.log("#####################################################################################################") # Measure energy with CodeCarbonEnergyMeter - codecarbon_energy_meter = CodeCarbonEnergyMeter(test_file, logger) + codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) codecarbon_energy_meter.measure_energy() # Measure emissions initial_emission = codecarbon_energy_meter.emissions # Get initial emission initial_emission_data = codecarbon_energy_meter.emissions_data # Get initial emission data @@ -35,38 +33,32 @@ def main(): logger.log(f"Initial Emissions: {initial_emission} kg CO2") logger.log("#####################################################################################################\n\n") - - - # Log start of code smells capture logger.log("#####################################################################################################") logger.log(" CAPTURE CODE SMELLS ") logger.log("#####################################################################################################") # Anaylze code smells with PylintAnalyzer - pylint_analyzer = PylintAnalyzer(test_file, logger) - pylint_analyzer.analyze_smells() # analyze all smells - detected_pylint_smells = pylint_analyzer.get_configured_smells() # get all configured smells + pylint_analyzer = PylintAnalyzer(TEST_FILE, logger) + pylint_analyzer.analyze() # analyze all smells + pylint_analyzer.configure_smells() # get all configured smells # Save code smells - save_json_files("all_configured_pylint_smells.json", detected_pylint_smells, logger) - logger.log(f"Refactorable code smells: {len(detected_pylint_smells)}") + save_json_files("all_configured_pylint_smells.json", pylint_analyzer.smells_data, logger) + logger.log(f"Refactorable code smells: {len(pylint_analyzer.smells_data)}") logger.log("#####################################################################################################\n\n") - - - # Log start of refactoring codes logger.log("#####################################################################################################") logger.log(" REFACTOR CODE SMELLS ") logger.log("#####################################################################################################") # Refactor code smells - test_file_copy = copy_file_to_output(test_file, "refactored-test-case.py") + TEST_FILE_COPY = copy_file_to_output(TEST_FILE, "refactored-test-case.py") emission = initial_emission - for pylint_smell in detected_pylint_smells: - refactoring_class = RefactorerFactory.build_refactorer_class(test_file_copy, pylint_smell["message-id"], pylint_smell, emission, logger) + for pylint_smell in pylint_analyzer.smells_data: + refactoring_class = RefactorerFactory.build_refactorer_class(TEST_FILE_COPY, pylint_smell["message-id"], pylint_smell, emission, logger) if refactoring_class: refactoring_class.refactor() @@ -75,16 +67,13 @@ def main(): logger.log(f"Refactoring for smell {pylint_smell['symbol']} is not implemented.") logger.log("#####################################################################################################\n\n") - - - # Log start of emissions capture logger.log("#####################################################################################################") logger.log(" CAPTURE FINAL EMISSIONS ") logger.log("#####################################################################################################") # Measure energy with CodeCarbonEnergyMeter - codecarbon_energy_meter = CodeCarbonEnergyMeter(test_file, logger) + codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) codecarbon_energy_meter.measure_energy() # Measure emissions final_emission = codecarbon_energy_meter.emissions # Get final emission final_emission_data = codecarbon_energy_meter.emissions_data # Get final emission data @@ -94,15 +83,12 @@ def main(): logger.log(f"Final Emissions: {final_emission} kg CO2") logger.log("#####################################################################################################\n\n") - - - # The emissions from codecarbon are so inconsistent that this could be a possibility :( if final_emission >= initial_emission: - logger.log(f"Final emissions are greater than initial emissions; we are going to fail") + logger.log("Final emissions are greater than initial emissions; we are going to fail") else: logger.log(f"Saved {initial_emission - final_emission} kg CO2") if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/src1/measurements/base_energy_meter.py b/src1/measurements/base_energy_meter.py index 144aae3a..3c583904 100644 --- a/src1/measurements/base_energy_meter.py +++ b/src1/measurements/base_energy_meter.py @@ -3,7 +3,7 @@ from utils.logger import Logger class BaseEnergyMeter(ABC): - def __init__(self, file_path, logger): + def __init__(self, file_path: str, logger: Logger): """ Base class for energy meters to measure the emissions of a given file. diff --git a/src1/measurements/codecarbon_energy_meter.py b/src1/measurements/codecarbon_energy_meter.py index f2a0a2ef..ce6dde52 100644 --- a/src1/measurements/codecarbon_energy_meter.py +++ b/src1/measurements/codecarbon_energy_meter.py @@ -3,6 +3,9 @@ import sys import subprocess import pandas as pd + +from utils.outputs_config import save_file + from codecarbon import EmissionsTracker from measurements.base_energy_meter import BaseEnergyMeter from tempfile import TemporaryDirectory @@ -32,11 +35,12 @@ def measure_energy(self): os.environ['TEMP'] = custom_temp_dir # For Windows os.environ['TMPDIR'] = custom_temp_dir # For Unix-based systems + # TODO: Save to logger so doesn't print to console tracker = EmissionsTracker(output_dir=custom_temp_dir, allow_multiple_runs=True) tracker.start() try: - subprocess.run([sys.executable, self.file_path], check=True) + subprocess.run([sys.executable, self.file_path], capture_output=True, text=True, check=True) self.logger.log("CodeCarbon measurement completed successfully.") except subprocess.CalledProcessError as e: self.logger.log(f"Error executing file '{self.file_path}': {e}") diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index 86f6dbf4..fc8067e0 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -8,7 +8,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "has_positive", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -21,7 +21,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "all_non_negative", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -34,7 +34,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "contains_large_strings", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -47,7 +47,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "all_uppercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -60,7 +60,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "contains_special_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -73,7 +73,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "all_lowercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -86,7 +86,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "any_even_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" }, @@ -99,7 +99,7 @@ "message-id": "R1729", "module": "ineffcient_code_example_1", "obj": "all_strings_start_with_a", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\src1-tests\\ineffcient_code_example_1.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "use-a-generator", "type": "refactor" } diff --git a/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt b/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt @@ -0,0 +1,2 @@ + + diff --git a/src1/outputs/code_carbon_refactored-test-case_log.txt b/src1/outputs/code_carbon_refactored-test-case_log.txt new file mode 100644 index 00000000..12a6f48e --- /dev/null +++ b/src1/outputs/code_carbon_refactored-test-case_log.txt @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index c24ac6cb..9bded5cd 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 12, - "cpu_energy": 3.003186364367139e-07, - "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", - "cpu_power": 23.924, - "duration": 2.316929100023117, - "emissions": 1.3831601079554254e-08, - "emissions_rate": 5.9697990238096845e-09, - "energy_consumed": 3.501985780487408e-07, + "cpu_count": 8, + "cpu_energy": 2.0728687498679695e-07, + "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", + "cpu_power": 7.5, + "duration": 0.1009901000652462, + "emissions": 1.3743098537414196e-08, + "emissions_rate": 1.360836213503626e-07, + "energy_consumed": 3.4795780604896405e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": 1, - "gpu_energy": 0.0, - "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_count": NaN, + "gpu_energy": 0, + "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 43.2642, - "longitude": -79.9143, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "Windows-10-10.0.19045-SP0", + "os": "Windows-11-10.0.22631-SP0", "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 4.9879941612026864e-08, - "ram_power": 5.91276741027832, - "ram_total_size": 15.767379760742188, + "ram_energy": 1.406709310621671e-07, + "ram_power": 6.730809688568115, + "ram_total_size": 17.94882583618164, "region": "ontario", - "run_id": "9acaf59e-0cc7-430f-b237-5b0fc071450a", - "timestamp": "2024-11-08T06:50:50", + "run_id": "ffcd8517-0fe8-4782-a20d-8a5bbfd16104", + "timestamp": "2024-11-09T00:02:07", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index 8e37578d..d47bf537 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 12, - "cpu_energy": 3.941996726949971e-07, - "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", - "cpu_power": 26.8962, - "duration": 2.388269099988974, - "emissions": 1.7910543037257115e-08, - "emissions_rate": 7.499382308861175e-09, - "energy_consumed": 4.534722095911076e-07, + "cpu_count": 8, + "cpu_energy": 1.639372916542925e-07, + "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", + "cpu_power": 7.5, + "duration": 0.079180600005202, + "emissions": 1.0797985699863445e-08, + "emissions_rate": 1.3637160742851206e-07, + "energy_consumed": 2.7339128826325853e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": 1, - "gpu_energy": 0.0, - "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_count": NaN, + "gpu_energy": 0, + "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 43.2642, - "longitude": -79.9143, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "Windows-10-10.0.19045-SP0", + "os": "Windows-11-10.0.22631-SP0", "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 5.9272536896110475e-08, - "ram_power": 5.91276741027832, - "ram_total_size": 15.767379760742188, + "ram_energy": 1.0945399660896601e-07, + "ram_power": 6.730809688568115, + "ram_total_size": 17.94882583618164, "region": "ontario", - "run_id": "c0408029-2c8c-4653-a6fb-98073ce8b637", - "timestamp": "2024-11-08T06:49:43", + "run_id": "d262c06e-8840-49da-9df9-77fb55f0e018", + "timestamp": "2024-11-09T00:01:15", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index a8daeefa..84c8fdef 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,94 +1,94 @@ -[2024-11-08 06:49:35] ##################################################################################################### -[2024-11-08 06:49:35] CAPTURE INITIAL EMISSIONS -[2024-11-08 06:49:35] ##################################################################################################### -[2024-11-08 06:49:35] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-08 06:49:40] CodeCarbon measurement completed successfully. -[2024-11-08 06:49:43] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt -[2024-11-08 06:49:43] Initial Emissions: 1.7910543037257115e-08 kg CO2 -[2024-11-08 06:49:43] ##################################################################################################### - - -[2024-11-08 06:49:43] ##################################################################################################### -[2024-11-08 06:49:43] CAPTURE CODE SMELLS -[2024-11-08 06:49:43] ##################################################################################################### -[2024-11-08 06:49:43] Running Pylint analysis on ineffcient_code_example_1.py -[2024-11-08 06:49:43] Pylint analyzer completed successfully. -[2024-11-08 06:49:43] Examining pylint smells for custom code smells -[2024-11-08 06:49:43] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json -[2024-11-08 06:49:43] Refactorable code smells: 8 -[2024-11-08 06:49:43] ##################################################################################################### - - -[2024-11-08 06:49:43] ##################################################################################################### -[2024-11-08 06:49:43] REFACTOR CODE SMELLS -[2024-11-08 06:49:43] ##################################################################################################### -[2024-11-08 06:49:43] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 5 for identified code smell. -[2024-11-08 06:49:43] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:49:48] CodeCarbon measurement completed successfully. -[2024-11-08 06:49:50] Measured emissions for 'refactored-test-case.py.temp': 4.095266300954314e-08 -[2024-11-08 06:49:50] Initial Emissions: 1.7910543037257115e-08 kg CO2. Final Emissions: 4.095266300954314e-08 kg CO2. -[2024-11-08 06:49:50] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-08 06:49:50] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 9 for identified code smell. -[2024-11-08 06:49:50] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:49:56] CodeCarbon measurement completed successfully. -[2024-11-08 06:49:58] Measured emissions for 'refactored-test-case.py.temp': 4.0307671392924016e-08 -[2024-11-08 06:49:58] Initial Emissions: 4.095266300954314e-08 kg CO2. Final Emissions: 4.0307671392924016e-08 kg CO2. -[2024-11-08 06:49:58] Refactored list comprehension to generator expression on line 9 and saved. - -[2024-11-08 06:49:58] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 13 for identified code smell. -[2024-11-08 06:49:58] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:03] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:05] Measured emissions for 'refactored-test-case.py.temp': 1.9387173249895166e-08 -[2024-11-08 06:50:05] Initial Emissions: 4.0307671392924016e-08 kg CO2. Final Emissions: 1.9387173249895166e-08 kg CO2. -[2024-11-08 06:50:05] Refactored list comprehension to generator expression on line 13 and saved. - -[2024-11-08 06:50:05] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 17 for identified code smell. -[2024-11-08 06:50:05] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:10] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:13] Measured emissions for 'refactored-test-case.py.temp': 2.951190821474716e-08 -[2024-11-08 06:50:13] Initial Emissions: 1.9387173249895166e-08 kg CO2. Final Emissions: 2.951190821474716e-08 kg CO2. -[2024-11-08 06:50:13] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-08 06:50:13] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 21 for identified code smell. -[2024-11-08 06:50:13] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:18] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:20] Measured emissions for 'refactored-test-case.py.temp': 3.45807880672747e-08 -[2024-11-08 06:50:20] Initial Emissions: 2.951190821474716e-08 kg CO2. Final Emissions: 3.45807880672747e-08 kg CO2. -[2024-11-08 06:50:20] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-08 06:50:20] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 25 for identified code smell. -[2024-11-08 06:50:20] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:25] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:28] Measured emissions for 'refactored-test-case.py.temp': 3.4148420368067676e-08 -[2024-11-08 06:50:28] Initial Emissions: 3.45807880672747e-08 kg CO2. Final Emissions: 3.4148420368067676e-08 kg CO2. -[2024-11-08 06:50:28] Refactored list comprehension to generator expression on line 25 and saved. - -[2024-11-08 06:50:28] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 29 for identified code smell. -[2024-11-08 06:50:28] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:33] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:35] Measured emissions for 'refactored-test-case.py.temp': 4.0344935213547e-08 -[2024-11-08 06:50:35] Initial Emissions: 3.4148420368067676e-08 kg CO2. Final Emissions: 4.0344935213547e-08 kg CO2. -[2024-11-08 06:50:35] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-08 06:50:35] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 33 for identified code smell. -[2024-11-08 06:50:35] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-08 06:50:40] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:42] Measured emissions for 'refactored-test-case.py.temp': 1.656956729885559e-08 -[2024-11-08 06:50:42] Initial Emissions: 4.0344935213547e-08 kg CO2. Final Emissions: 1.656956729885559e-08 kg CO2. -[2024-11-08 06:50:42] Refactored list comprehension to generator expression on line 33 and saved. - -[2024-11-08 06:50:42] ##################################################################################################### - - -[2024-11-08 06:50:42] ##################################################################################################### -[2024-11-08 06:50:42] CAPTURE FINAL EMISSIONS -[2024-11-08 06:50:42] ##################################################################################################### -[2024-11-08 06:50:42] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-08 06:50:47] CodeCarbon measurement completed successfully. -[2024-11-08 06:50:50] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt -[2024-11-08 06:50:50] Final Emissions: 1.3831601079554254e-08 kg CO2 -[2024-11-08 06:50:50] ##################################################################################################### - - -[2024-11-08 06:50:50] Saved 4.0789419577028616e-09 kg CO2 +[2024-11-09 00:01:09] ##################################################################################################### +[2024-11-09 00:01:09] CAPTURE INITIAL EMISSIONS +[2024-11-09 00:01:09] ##################################################################################################### +[2024-11-09 00:01:09] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-09 00:01:15] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:15] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt +[2024-11-09 00:01:15] Initial Emissions: 1.0797985699863445e-08 kg CO2 +[2024-11-09 00:01:15] ##################################################################################################### + + +[2024-11-09 00:01:15] ##################################################################################################### +[2024-11-09 00:01:15] CAPTURE CODE SMELLS +[2024-11-09 00:01:15] ##################################################################################################### +[2024-11-09 00:01:15] Running Pylint analysis on ineffcient_code_example_1.py +[2024-11-09 00:01:15] Pylint analyzer completed successfully. +[2024-11-09 00:01:15] Filtering pylint smells +[2024-11-09 00:01:15] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json +[2024-11-09 00:01:15] Refactorable code smells: 8 +[2024-11-09 00:01:15] ##################################################################################################### + + +[2024-11-09 00:01:15] ##################################################################################################### +[2024-11-09 00:01:15] REFACTOR CODE SMELLS +[2024-11-09 00:01:15] ##################################################################################################### +[2024-11-09 00:01:15] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 5 for identified code smell. +[2024-11-09 00:01:15] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:21] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:21] Measured emissions for 'refactored-test-case.py.temp': 1.4291086052002757e-08 +[2024-11-09 00:01:21] Initial Emissions: 1.0797985699863445e-08 kg CO2. Final Emissions: 1.4291086052002757e-08 kg CO2. +[2024-11-09 00:01:21] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-09 00:01:21] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 9 for identified code smell. +[2024-11-09 00:01:21] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:27] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:27] Measured emissions for 'refactored-test-case.py.temp': 1.4151753578674423e-08 +[2024-11-09 00:01:27] Initial Emissions: 1.4291086052002757e-08 kg CO2. Final Emissions: 1.4151753578674423e-08 kg CO2. +[2024-11-09 00:01:27] Refactored list comprehension to generator expression on line 9 and saved. + +[2024-11-09 00:01:27] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 13 for identified code smell. +[2024-11-09 00:01:27] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:33] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:33] Measured emissions for 'refactored-test-case.py.temp': 1.4556037328786188e-08 +[2024-11-09 00:01:33] Initial Emissions: 1.4151753578674423e-08 kg CO2. Final Emissions: 1.4556037328786188e-08 kg CO2. +[2024-11-09 00:01:33] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-09 00:01:33] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 17 for identified code smell. +[2024-11-09 00:01:33] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:38] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:38] Measured emissions for 'refactored-test-case.py.temp': 1.3124271407934068e-08 +[2024-11-09 00:01:38] Initial Emissions: 1.4556037328786188e-08 kg CO2. Final Emissions: 1.3124271407934068e-08 kg CO2. +[2024-11-09 00:01:38] Refactored list comprehension to generator expression on line 17 and saved. + +[2024-11-09 00:01:38] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 21 for identified code smell. +[2024-11-09 00:01:38] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:44] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:44] Measured emissions for 'refactored-test-case.py.temp': 1.3861280032740713e-08 +[2024-11-09 00:01:44] Initial Emissions: 1.3124271407934068e-08 kg CO2. Final Emissions: 1.3861280032740713e-08 kg CO2. +[2024-11-09 00:01:44] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-09 00:01:44] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 25 for identified code smell. +[2024-11-09 00:01:44] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:49] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:50] Measured emissions for 'refactored-test-case.py.temp': 1.408449410957712e-08 +[2024-11-09 00:01:50] Initial Emissions: 1.3861280032740713e-08 kg CO2. Final Emissions: 1.408449410957712e-08 kg CO2. +[2024-11-09 00:01:50] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-09 00:01:50] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 29 for identified code smell. +[2024-11-09 00:01:50] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:01:55] CodeCarbon measurement completed successfully. +[2024-11-09 00:01:55] Measured emissions for 'refactored-test-case.py.temp': 1.3973626482026841e-08 +[2024-11-09 00:01:55] Initial Emissions: 1.408449410957712e-08 kg CO2. Final Emissions: 1.3973626482026841e-08 kg CO2. +[2024-11-09 00:01:55] Refactored list comprehension to generator expression on line 29 and saved. + +[2024-11-09 00:01:55] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 33 for identified code smell. +[2024-11-09 00:01:55] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 00:02:01] CodeCarbon measurement completed successfully. +[2024-11-09 00:02:01] Measured emissions for 'refactored-test-case.py.temp': 1.3353186227676251e-08 +[2024-11-09 00:02:01] Initial Emissions: 1.3973626482026841e-08 kg CO2. Final Emissions: 1.3353186227676251e-08 kg CO2. +[2024-11-09 00:02:01] Refactored list comprehension to generator expression on line 33 and saved. + +[2024-11-09 00:02:01] ##################################################################################################### + + +[2024-11-09 00:02:01] ##################################################################################################### +[2024-11-09 00:02:01] CAPTURE FINAL EMISSIONS +[2024-11-09 00:02:01] ##################################################################################################### +[2024-11-09 00:02:01] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-09 00:02:07] CodeCarbon measurement completed successfully. +[2024-11-09 00:02:07] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt +[2024-11-09 00:02:07] Final Emissions: 1.3743098537414197e-08 kg CO2 +[2024-11-09 00:02:07] ##################################################################################################### + + +[2024-11-09 00:02:07] Final emissions are greater than initial emissions; we are going to fail diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index d351ccc5..3e73abfd 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -10,11 +10,11 @@ def all_non_negative(numbers): def contains_large_strings(strings): # List comprehension inside `any()` - triggers R1729 - return any(len(s) > 10 for s in strings) + return any([len(s) > 10 for s in strings]) def all_uppercase(strings): # List comprehension inside `all()` - triggers R1729 - return all([s.isupper() for s in strings]) + return all(s.isupper() for s in strings) def contains_special_numbers(numbers): # List comprehension inside `any()` - triggers R1729 @@ -22,11 +22,11 @@ def contains_special_numbers(numbers): def all_lowercase(strings): # List comprehension inside `all()` - triggers R1729 - return all(s.islower() for s in strings) + return all([s.islower() for s in strings]) def any_even_numbers(numbers): # List comprehension inside `any()` - triggers R1729 - return any([num % 2 == 0 for num in numbers]) + return any(num % 2 == 0 for num in numbers) def all_strings_start_with_a(strings): # List comprehension inside `all()` - triggers R1729 diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 2f12442e..3a7624cb 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -1,10 +1,18 @@ # Any configurations that are done by the analyzers - from enum import Enum +from itertools import chain + +class ExtendedEnum(Enum): + + @classmethod + def list(cls) -> list[str]: + return [c.value for c in cls] + + def __str__(self): + return str(self.value) # Enum class for standard Pylint code smells -class PylintSmell(Enum): - LINE_TOO_LONG = "C0301" # Pylint code smell for lines that exceed the max length +class PylintSmell(ExtendedEnum): LONG_MESSAGE_CHAIN = "R0914" # Pylint code smell for long message chains LARGE_CLASS = "R0902" # Pylint code smell for classes with too many attributes LONG_PARAMETER_LIST = "R0913" # Pylint code smell for functions with too many parameters @@ -13,13 +21,20 @@ class PylintSmell(Enum): INVALID_NAMING_CONVENTIONS = "C0103" # Pylint code smell for naming conventions violations USE_A_GENERATOR = "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` - # Enum class for custom code smells not detected by Pylint -class CustomPylintSmell(Enum): +class CustomSmell(ExtendedEnum): LONG_TERN_EXPR = "CUST-1" # Custom code smell for long ternary expressions -# Combined enum for all smells -AllPylintSmells = Enum('AllSmells', {**{s.name: s.value for s in PylintSmell}, **{s.name: s.value for s in CustomPylintSmell}}) +class IntermediateSmells(ExtendedEnum): + LINE_TOO_LONG = "C0301" # pylint smell + +# Enum containing all smells +class AllSmells(ExtendedEnum): + _ignore_ = 'member cls' + cls = vars() + for member in chain(list(PylintSmell), + list(CustomSmell)): + cls[member.name] = member.value # Additional Pylint configuration options for analyzing code EXTRA_PYLINT_OPTIONS = [ @@ -27,4 +42,4 @@ class CustomPylintSmell(Enum): "--max-nested-blocks=3", # Limits maximum nesting of blocks "--max-branches=3", # Limits maximum branches in a function "--max-parents=3" # Limits maximum inheritance levels for a class -] +] \ No newline at end of file diff --git a/src1/utils/logger.py b/src1/utils/logger.py index 22251f93..948a0414 100644 --- a/src1/utils/logger.py +++ b/src1/utils/logger.py @@ -1,8 +1,8 @@ # utils/logger.py - import os from datetime import datetime +# TODO: Make Logger class implement python logging.Logger class Logger: def __init__(self, log_path): """ diff --git a/src1/utils/outputs_config.py b/src1/utils/outputs_config.py index b87a183a..1a2ef31e 100644 --- a/src1/utils/outputs_config.py +++ b/src1/utils/outputs_config.py @@ -1,5 +1,4 @@ # utils/output_config.py - import json import os import shutil @@ -7,6 +6,31 @@ OUTPUT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../outputs/")) +def save_file(filename: str, data, mode: str, message="", logger=None): + """ + Saves any data to a file in the output folder. + + :param filename: Name of the file to save data to. + :param data: Data to be saved. + :param mode: file IO mode (w,w+,a,a+,etc). + :param logger: Optional logger instance to log messages. + """ + file_path = os.path.join(OUTPUT_DIR, filename) + + # Ensure the output directory exists; if not, create it + if not os.path.exists(OUTPUT_DIR): + os.makedirs(OUTPUT_DIR) + + # Write data to the specified file + with open(file_path, mode) as file: + file.write(data) + + message = message if len(message) > 0 else f"Output saved to {file_path.removeprefix(os.path.dirname(__file__))}" + if logger: + logger.log(message) + else: + print(message) + def save_json_files(filename, data, logger=None): """ Saves JSON data to a file in the output folder. diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index 2f82d794..f8883b82 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -3,7 +3,7 @@ from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells -from utils.analyzers_config import AllPylintSmells +from utils.analyzers_config import AllSmells class RefactorerFactory(): """ @@ -30,7 +30,7 @@ def build_refactorer_class(file_path, smell_messageId, smell_data, initial_emiss # Use match statement to select the appropriate refactorer based on smell message ID match smell_messageId: - case AllPylintSmells.USE_A_GENERATOR.value: + case AllSmells.USE_A_GENERATOR.value: selected = UseAGeneratorRefactor(file_path, smell_data, initial_emission, logger) case _: selected = None diff --git a/test/carbon_report.csv b/test/carbon_report.csv deleted file mode 100644 index f8912394..00000000 --- a/test/carbon_report.csv +++ /dev/null @@ -1,33 +0,0 @@ -Attribute,Value -timestamp,2024-11-06T15:59:19 -project_name,codecarbon -run_id,28e822bb-bf1c-4dd3-8688-29a820e468d5 -experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,0.038788334000855684 -emissions,1.9307833465060534e-08 -emissions_rate,4.977742396627449e-07 -cpu_power,42.5 -gpu_power,0.0 -ram_power,3.0 -cpu_energy,4.569394466468819e-07 -gpu_energy,0 -ram_energy,3.1910382507097286e-08 -energy_consumed,4.888498291539792e-07 -country_name,Canada -country_iso_code,CAN -region,ontario -cloud_provider, -cloud_region, -os,macOS-15.1-arm64-arm-64bit -python_version,3.10.0 -codecarbon_version,2.7.2 -cpu_count,8 -cpu_model,Apple M2 -gpu_count, -gpu_model, -longitude,-79.9441 -latitude,43.266 -ram_total_size,8.0 -tracking_mode,machine -on_cloud,N -pue,1.0 diff --git a/test/inefficent_code_example.py b/test/inefficent_code_example.py deleted file mode 100644 index f8f32921..00000000 --- a/test/inefficent_code_example.py +++ /dev/null @@ -1,90 +0,0 @@ -# LC: Large Class with too many responsibilities -class DataProcessor: - def __init__(self, data): - self.data = data - self.processed_data = [] - - # LM: Long Method - this method does way too much - def process_all_data(self): - results = [] - for item in self.data: - try: - # LPL: Long Parameter List - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) - results.append(result) - except ( - Exception - ) as e: # UEH: Unqualified Exception Handling, catching generic exceptions - print("An error occurred:", e) - - # LMC: Long Message Chain - print(self.data[0].upper().strip().replace(" ", "_").lower()) - - # LLF: Long Lambda Function - self.processed_data = list( - filter(lambda x: x != None and x != 0 and len(str(x)) > 1, results) - ) - - return self.processed_data - - # LBCL: Long Base Class List - - -class AdvancedProcessor(DataProcessor, object, dict, list, set, tuple): - pass - - # LTCE: Long Ternary Conditional Expression - def check_data(self, item): - return ( - True if item > 10 else False if item < -10 else None if item == 0 else item - ) - - # Complex List Comprehension - def complex_comprehension(self): - # CLC: Complex List Comprehension - self.processed_data = [ - x**2 if x % 2 == 0 else x**3 - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] - - # Long Element Chain - def long_chain(self): - # LEC: Long Element Chain accessing deeply nested elements - try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] - return deep_value - except KeyError: - return None - - # Long Scope Chaining (LSC) - def long_scope_chaining(self): - for a in range(10): - for b in range(10): - for c in range(10): - for d in range(10): - for e in range(10): - if a + b + c + d + e > 25: - return "Done" - - # LPL: Long Parameter List - def complex_calculation( - self, item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": - result = item * threshold - elif operation == "add": - result = item + max_value - else: - result = item - return result - - -# Main method to execute the code -if __name__ == "__main__": - sample_data = [1, 2, 3, 4, 5] - processor = DataProcessor(sample_data) - processed = processor.process_all_data() - print("Processed Data:", processed) diff --git a/test/README.md b/tests/README.md similarity index 100% rename from test/README.md rename to tests/README.md diff --git a/src1-tests/ineffcient_code_example_1.py b/tests/input/ineffcient_code_example_1.py similarity index 100% rename from src1-tests/ineffcient_code_example_1.py rename to tests/input/ineffcient_code_example_1.py diff --git a/src1-tests/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py similarity index 100% rename from src1-tests/ineffcient_code_example_2.py rename to tests/input/ineffcient_code_example_2.py diff --git a/test/high_energy_code_example.py b/tests/input/ineffcient_code_example_3.py similarity index 100% rename from test/high_energy_code_example.py rename to tests/input/ineffcient_code_example_3.py diff --git a/test/test_analyzer.py b/tests/test_analyzer.py similarity index 100% rename from test/test_analyzer.py rename to tests/test_analyzer.py diff --git a/test/test_end_to_end.py b/tests/test_end_to_end.py similarity index 100% rename from test/test_end_to_end.py rename to tests/test_end_to_end.py diff --git a/test/test_energy_measure.py b/tests/test_energy_measure.py similarity index 100% rename from test/test_energy_measure.py rename to tests/test_energy_measure.py diff --git a/test/test_refactorer.py b/tests/test_refactorer.py similarity index 100% rename from test/test_refactorer.py rename to tests/test_refactorer.py From 58dfa9b5b46d8749af3236e1c127590044cf1894 Mon Sep 17 00:00:00 2001 From: mya Date: Sat, 9 Nov 2024 02:04:55 -0500 Subject: [PATCH 051/105] Added long message chain custom analyzer: --- __init__.py | 0 .../__pycache__/base_analyzer.cpython-310.pyc | Bin 732 -> 732 bytes src/analyzers/inefficent_code_example.py | 90 ++++ src/analyzers/pylint_analyzer.py | 63 ++- src/output/ast.txt | 471 +----------------- src/output/ast_lines.txt | 239 --------- src1/analyzers/pylint_analyzer.py | 121 ++++- src1/main.py | 103 ++-- .../outputs/all_configured_pylint_smells.json | 122 +---- src1/outputs/initial_emissions_data.txt | 38 +- src1/outputs/log.txt | 112 +---- src1/outputs/smells.json | 197 ++++++++ src1/refactorers/base_refactorer.py | 1 - .../long_lambda_function_refactorer.py | 17 + .../long_message_chain_refactorer.py | 17 + src1/refactorers/use_a_generator_refactor.py | 44 +- src1/utils/analyzers_config.py | 33 +- tests/__init__.py | 0 tests/test_analyzer.py | 31 +- 19 files changed, 678 insertions(+), 1021 deletions(-) create mode 100644 __init__.py create mode 100644 src/analyzers/inefficent_code_example.py create mode 100644 src1/outputs/smells.json create mode 100644 src1/refactorers/long_lambda_function_refactorer.py create mode 100644 src1/refactorers/long_message_chain_refactorer.py create mode 100644 tests/__init__.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc b/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc index f8229c8a019579445fe63c363da49d150fd7c0b4..9e719a7982b155e4863ac8611a5092b72de327c9 100644 GIT binary patch delta 20 acmcb^dWV%epO=@50SJmN>uuz|$OHg4_XT4B delta 20 acmcb^dWV%epO=@50SJ_Cscq!G$OHg2$psPs diff --git a/src/analyzers/inefficent_code_example.py b/src/analyzers/inefficent_code_example.py new file mode 100644 index 00000000..f8f32921 --- /dev/null +++ b/src/analyzers/inefficent_code_example.py @@ -0,0 +1,90 @@ +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] + + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except ( + Exception + ) as e: # UEH: Unqualified Exception Handling, catching generic exceptions + print("An error occurred:", e) + + # LMC: Long Message Chain + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x != None and x != 0 and len(str(x)) > 1, results) + ) + + return self.processed_data + + # LBCL: Long Base Class List + + +class AdvancedProcessor(DataProcessor, object, dict, list, set, tuple): + pass + + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return ( + True if item > 10 else False if item < -10 else None if item == 0 else item + ) + + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + # LEC: Long Element Chain accessing deeply nested elements + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except KeyError: + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + # LPL: Long Parameter List + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py index 9ff4fd13..e69d2692 100644 --- a/src/analyzers/pylint_analyzer.py +++ b/src/analyzers/pylint_analyzer.py @@ -1,15 +1,16 @@ import json from io import StringIO + # ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN # you will need to change imports too # ====================================================== -# from os.path import dirname, abspath -# import sys - +from os.path import dirname, abspath +import sys +import ast -# # Sets src as absolute path, everything needs to be relative to src folder -# REFACTOR_DIR = dirname(abspath(__file__)) -# sys.path.append(dirname(REFACTOR_DIR)) +# Sets src as absolute path, everything needs to be relative to src folder +REFACTOR_DIR = dirname(abspath(__file__)) +sys.path.append(dirname(REFACTOR_DIR)) from pylint.lint import Run from pylint.reporters.json_reporter import JSON2Reporter @@ -25,6 +26,7 @@ from utils.code_smells import CodeSmells from utils.ast_parser import parse_line, parse_file + class PylintAnalyzer(BaseAnalyzer): def __init__(self, code_path: str): super().__init__(code_path) @@ -43,7 +45,17 @@ def analyze(self): reporter = JSON2Reporter(output_stream) # Run pylint - Run(["--max-line-length=80", "--max-nested-blocks=3", "--max-branches=3", "--max-parents=3", self.code_path], reporter=reporter, exit=False) + Run( + [ + "--max-line-length=80", + "--max-nested-blocks=3", + "--max-branches=3", + "--max-parents=3", + self.code_path, + ], + reporter=reporter, + exit=False, + ) # Retrieve and parse output as JSON output = output_stream.getvalue() @@ -54,6 +66,7 @@ def analyze(self): print("Error: Could not decode pylint output") pylint_results = [] + print(pylint_results) return pylint_results def filter_for_all_wanted_code_smells(self, pylint_results): @@ -65,7 +78,7 @@ def filter_for_all_wanted_code_smells(self, pylint_results): if error["messageId"] in CodeSmells.list(): statistics[error["messageId"]] = True filtered_results.append(error) - + report.append(filtered_results) report.append(statistics) @@ -82,30 +95,26 @@ def filter_for_one_code_smell(self, pylint_results, code): return filtered_results -# Example usage -# if __name__ == "__main__": - -# FILE_PATH = abspath("test/inefficent_code_example.py") -# analyzer = PylintAnalyzer(FILE_PATH) - -# # print("THIS IS REPORT for our smells:") -# report = analyzer.analyze() +# Example usage +if __name__ == "__main__": -# with open("src/output/ast.txt", "w+") as f: -# print(parse_file(FILE_PATH), file=f) + FILE_PATH = abspath("test/inefficent_code_example.py") -# filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") + analyzer = PylintAnalyzer(FILE_PATH) + # print("THIS IS REPORT for our smells:") + report = analyzer.analyze() -# with open(FILE_PATH, "r") as f: -# file_lines = f.readlines() + with open("src/output/ast.txt", "w+") as f: + print(parse_file(FILE_PATH), file=f) -# for smell in filtered_results: -# with open("src/output/ast_lines.txt", "a+") as f: -# print("Parsing line ", smell["line"], file=f) -# print(parse_line(file_lines, smell["line"]), end="\n", file=f) - + filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") + with open(FILE_PATH, "r") as f: + file_lines = f.readlines() - + for smell in filtered_results: + with open("src/output/ast_lines.txt", "a+") as f: + print("Parsing line ", smell["line"], file=f) + print(parse_line(file_lines, smell["line"]), end="\n", file=f) diff --git a/src/output/ast.txt b/src/output/ast.txt index bbeae637..a96cb4af 100644 --- a/src/output/ast.txt +++ b/src/output/ast.txt @@ -1,470 +1 @@ -Module( - body=[ - ClassDef( - name='DataProcessor', - body=[ - FunctionDef( - name='__init__', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='data')]), - body=[ - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Store())], - value=Name(id='data', ctx=Load())), - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=List(ctx=Load()))]), - FunctionDef( - name='process_all_data', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Assign( - targets=[ - Name(id='results', ctx=Store())], - value=List(ctx=Load())), - For( - target=Name(id='item', ctx=Store()), - iter=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - body=[ - Try( - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=Call( - func=Attribute( - value=Name(id='self', ctx=Load()), - attr='complex_calculation', - ctx=Load()), - args=[ - Name(id='item', ctx=Load()), - Constant(value=True), - Constant(value=False), - Constant(value='multiply'), - Constant(value=10), - Constant(value=20), - Constant(value=None), - Constant(value='end')])), - Expr( - value=Call( - func=Attribute( - value=Name(id='results', ctx=Load()), - attr='append', - ctx=Load()), - args=[ - Name(id='result', ctx=Load())]))], - handlers=[ - ExceptHandler( - type=Name(id='Exception', ctx=Load()), - name='e', - body=[ - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Constant(value='An error occurred:'), - Name(id='e', ctx=Load())]))])])]), - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Call( - func=Attribute( - value=Call( - func=Attribute( - value=Call( - func=Attribute( - value=Call( - func=Attribute( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - attr='upper', - ctx=Load())), - attr='strip', - ctx=Load())), - attr='replace', - ctx=Load()), - args=[ - Constant(value=' '), - Constant(value='_')]), - attr='lower', - ctx=Load()))])), - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=Call( - func=Name(id='list', ctx=Load()), - args=[ - Call( - func=Name(id='filter', ctx=Load()), - args=[ - Lambda( - args=arguments( - args=[ - arg(arg='x')]), - body=BoolOp( - op=And(), - values=[ - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=None)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=0)]), - Compare( - left=Call( - func=Name(id='len', ctx=Load()), - args=[ - Call( - func=Name(id='str', ctx=Load()), - args=[ - Name(id='x', ctx=Load())])]), - ops=[ - Gt()], - comparators=[ - Constant(value=1)])])), - Name(id='results', ctx=Load())])])), - Return( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Load()))])]), - ClassDef( - name='AdvancedProcessor', - bases=[ - Name(id='DataProcessor', ctx=Load()), - Name(id='object', ctx=Load()), - Name(id='dict', ctx=Load()), - Name(id='list', ctx=Load()), - Name(id='set', ctx=Load()), - Name(id='tuple', ctx=Load())], - body=[ - Pass(), - FunctionDef( - name='check_data', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='item')]), - body=[ - Return( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]), - FunctionDef( - name='complex_comprehension', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Assign( - targets=[ - Attribute( - value=Name(id='self', ctx=Load()), - attr='processed_data', - ctx=Store())], - value=ListComp( - elt=IfExp( - test=Compare( - left=BinOp( - left=Name(id='x', ctx=Load()), - op=Mod(), - right=Constant(value=2)), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=BinOp( - left=Name(id='x', ctx=Load()), - op=Pow(), - right=Constant(value=2)), - orelse=BinOp( - left=Name(id='x', ctx=Load()), - op=Pow(), - right=Constant(value=3))), - generators=[ - comprehension( - target=Name(id='x', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=1), - Constant(value=100)]), - ifs=[ - BoolOp( - op=And(), - values=[ - Compare( - left=BinOp( - left=Name(id='x', ctx=Load()), - op=Mod(), - right=Constant(value=5)), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - NotEq()], - comparators=[ - Constant(value=50)]), - Compare( - left=Name(id='x', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=3)])])], - is_async=0)]))]), - FunctionDef( - name='long_chain', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - Try( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load())), - Return( - value=Name(id='deep_value', ctx=Load()))], - handlers=[ - ExceptHandler( - type=Name(id='KeyError', ctx=Load()), - body=[ - Return( - value=Constant(value=None))])])]), - FunctionDef( - name='long_scope_chaining', - args=arguments( - args=[ - arg(arg='self')]), - body=[ - For( - target=Name(id='a', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='b', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='c', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='d', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - For( - target=Name(id='e', ctx=Store()), - iter=Call( - func=Name(id='range', ctx=Load()), - args=[ - Constant(value=10)]), - body=[ - If( - test=Compare( - left=BinOp( - left=BinOp( - left=BinOp( - left=BinOp( - left=Name(id='a', ctx=Load()), - op=Add(), - right=Name(id='b', ctx=Load())), - op=Add(), - right=Name(id='c', ctx=Load())), - op=Add(), - right=Name(id='d', ctx=Load())), - op=Add(), - right=Name(id='e', ctx=Load())), - ops=[ - Gt()], - comparators=[ - Constant(value=25)]), - body=[ - Return( - value=Constant(value='Done'))])])])])])])]), - FunctionDef( - name='complex_calculation', - args=arguments( - args=[ - arg(arg='self'), - arg(arg='item'), - arg(arg='flag1'), - arg(arg='flag2'), - arg(arg='operation'), - arg(arg='threshold'), - arg(arg='max_value'), - arg(arg='option'), - arg(arg='final_stage')]), - body=[ - If( - test=Compare( - left=Name(id='operation', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='multiply')]), - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=BinOp( - left=Name(id='item', ctx=Load()), - op=Mult(), - right=Name(id='threshold', ctx=Load())))], - orelse=[ - If( - test=Compare( - left=Name(id='operation', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='add')]), - body=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=BinOp( - left=Name(id='item', ctx=Load()), - op=Add(), - right=Name(id='max_value', ctx=Load())))], - orelse=[ - Assign( - targets=[ - Name(id='result', ctx=Store())], - value=Name(id='item', ctx=Load()))])]), - Return( - value=Name(id='result', ctx=Load()))])]), - If( - test=Compare( - left=Name(id='__name__', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value='__main__')]), - body=[ - Assign( - targets=[ - Name(id='sample_data', ctx=Store())], - value=List( - elts=[ - Constant(value=1), - Constant(value=2), - Constant(value=3), - Constant(value=4), - Constant(value=5)], - ctx=Load())), - Assign( - targets=[ - Name(id='processor', ctx=Store())], - value=Call( - func=Name(id='DataProcessor', ctx=Load()), - args=[ - Name(id='sample_data', ctx=Load())])), - Assign( - targets=[ - Name(id='processed', ctx=Store())], - value=Call( - func=Attribute( - value=Name(id='processor', ctx=Load()), - attr='process_all_data', - ctx=Load()))), - Expr( - value=Call( - func=Name(id='print', ctx=Load()), - args=[ - Constant(value='Processed Data:'), - Name(id='processed', ctx=Load())]))])]) + diff --git a/src/output/ast_lines.txt b/src/output/ast_lines.txt index 76343f17..eb04405d 100644 --- a/src/output/ast_lines.txt +++ b/src/output/ast_lines.txt @@ -1,240 +1 @@ Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) -Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) -Parsing line 19 -Not Valid Smell -Parsing line 41 -Module( - body=[ - Expr( - value=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Gt()], - comparators=[ - Constant(value=10)]), - body=Constant(value=True), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Lt()], - comparators=[ - UnaryOp( - op=USub(), - operand=Constant(value=10))]), - body=Constant(value=False), - orelse=IfExp( - test=Compare( - left=Name(id='item', ctx=Load()), - ops=[ - Eq()], - comparators=[ - Constant(value=0)]), - body=Constant(value=None), - orelse=Name(id='item', ctx=Load())))))]) -Parsing line 57 -Module( - body=[ - Assign( - targets=[ - Name(id='deep_value', ctx=Store())], - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Subscript( - value=Attribute( - value=Name(id='self', ctx=Load()), - attr='data', - ctx=Load()), - slice=Constant(value=0), - ctx=Load()), - slice=Constant(value=1), - ctx=Load()), - slice=Constant(value='details'), - ctx=Load()), - slice=Constant(value='info'), - ctx=Load()), - slice=Constant(value='more_info'), - ctx=Load()), - slice=Constant(value=2), - ctx=Load()), - slice=Constant(value='target'), - ctx=Load()))]) -Parsing line 74 -Module( - body=[ - Expr( - value=Tuple( - elts=[ - Name(id='self', ctx=Load()), - Name(id='item', ctx=Load()), - Name(id='flag1', ctx=Load()), - Name(id='flag2', ctx=Load()), - Name(id='operation', ctx=Load()), - Name(id='threshold', ctx=Load()), - Name(id='max_value', ctx=Load()), - Name(id='option', ctx=Load()), - Name(id='final_stage', ctx=Load())], - ctx=Load()))]) diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index a71b494d..0a429871 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -9,10 +9,16 @@ from utils.logger import Logger from .base_analyzer import Analyzer -from utils.analyzers_config import PylintSmell, CustomSmell, IntermediateSmells, EXTRA_PYLINT_OPTIONS +from utils.analyzers_config import ( + PylintSmell, + CustomSmell, + IntermediateSmells, + EXTRA_PYLINT_OPTIONS, +) from utils.ast_parser import parse_line + class PylintAnalyzer(Analyzer): def __init__(self, file_path: str, logger: Logger): super().__init__(file_path, logger) @@ -24,7 +30,7 @@ def build_pylint_options(self): :return: List of pylint options for analysis. """ return [self.file_path] + EXTRA_PYLINT_OPTIONS - + def analyze(self): """ Executes pylint on the specified file and captures the output in JSON format. @@ -32,7 +38,9 @@ def analyze(self): if not self.validate_file(): return - self.logger.log(f"Running Pylint analysis on {os.path.basename(self.file_path)}") + self.logger.log( + f"Running Pylint analysis on {os.path.basename(self.file_path)}" + ) # Capture pylint output in a JSON format buffer with StringIO() as buffer: @@ -52,6 +60,15 @@ def analyze(self): except Exception as e: self.logger.log(f"An error occurred during pylint analysis: {e}") + self.logger.log("Running custom parsers:") + lmc_data = PylintAnalyzer.detect_long_message_chain( + PylintAnalyzer.read_code_from_path(self.file_path), + self.file_path, + os.path.basename(self.file_path), + ) + print("THIS IS LMC DATA:", lmc_data) + self.smells_data += lmc_data + def configure_smells(self): """ Filters the report data to retrieve only the smells with message IDs specified in the config. @@ -63,6 +80,8 @@ def configure_smells(self): for smell in self.smells_data: if smell["message-id"] in PylintSmell.list(): configured_smells.append(smell) + elif smell["message-id"] in CustomSmell.list(): + configured_smells.append(smell) if smell == IntermediateSmells.LINE_TOO_LONG.value: self.filter_ternary(smell) @@ -79,8 +98,8 @@ def filter_for_one_code_smell(self, pylint_results: list[object], code: str): filtered_results.append(error) return filtered_results - - def filter_ternary(self, smell: object): + + def filter_ternary(self, smell: object): root_node = parse_line(self.file_path, smell["line"]) if root_node is None: @@ -90,4 +109,94 @@ def filter_ternary(self, smell: object): if isinstance(node, ast.IfExp): # Ternary expression node smell["message-id"] = CustomSmell.LONG_TERN_EXPR.value self.smells_data.append(smell) - break \ No newline at end of file + break + + def detect_long_message_chain(code, file_path, module_name, threshold=3): + """ + Detects long message chains in the given Python code and returns a list of results. + + Args: + - code (str): Python source code to be analyzed. + - file_path (str): The path to the file being analyzed (for reporting purposes). + - module_name (str): The name of the module (for reporting purposes). + - threshold (int): The minimum number of chained method calls to flag as a long chain. + + Returns: + - List of dictionaries: Each dictionary contains details about the detected long chain. + """ + # Parse the code into an Abstract Syntax Tree (AST) + tree = ast.parse(code) + + results = [] + used_lines = set() + + # Function to detect long chains + def check_chain(node, chain_length=0): + # If the chain length exceeds the threshold, add it to results + if chain_length >= threshold: + # Create the message for the convention + message = f"Method chain too long ({chain_length}/{threshold})" + # Add the result in the required format + result = { + "type": "convention", + "symbol": "long-message-chain", + "message": message, + "message-id": "LMC001", + "confidence": "UNDEFINED", + "module": module_name, + "obj": "", + "line": node.lineno, + "column": node.col_offset, + "endLine": None, + "endColumn": None, + "path": file_path, + "absolutePath": file_path, # Assuming file_path is the absolute path + } + + if node.lineno in used_lines: + return + used_lines.add(node.lineno) + results.append(result) + return + + if isinstance(node, ast.Call): + # If the node is a function call, increment the chain length + chain_length += 1 + # Recursively check if there's a chain in the function being called + if isinstance(node.func, ast.Attribute): + check_chain(node.func, chain_length) + + elif isinstance(node, ast.Attribute): + # Increment chain length for attribute access (part of the chain) + chain_length += 1 + check_chain(node.value, chain_length) + + # Walk through the AST + for node in ast.walk(tree): + # We are only interested in method calls (attribute access) + if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute): + # Call check_chain to detect long chains + check_chain(node.func) + + return results + + def read_code_from_path(file_path): + """ + Reads the Python code from a given file path. + + Args: + - file_path (str): The path to the Python file. + + Returns: + - str: The content of the file as a string. + """ + try: + with open(file_path, "r") as file: + code = file.read() + return code + except FileNotFoundError: + print(f"Error: The file at {file_path} was not found.") + return None + except IOError as e: + print(f"Error reading file {file_path}: {e}") + return None diff --git a/src1/main.py b/src1/main.py index 699bb031..0267ff5e 100644 --- a/src1/main.py +++ b/src1/main.py @@ -9,86 +9,133 @@ DIRNAME = os.path.dirname(__file__) + def main(): # Path to the file to be analyzed - TEST_FILE = os.path.abspath(os.path.join(DIRNAME, "../tests/input/ineffcient_code_example_1.py")) + TEST_FILE = os.path.abspath( + os.path.join(DIRNAME, "../tests/input/ineffcient_code_example_2.py") + ) # Set up logging LOG_FILE = os.path.join(DIRNAME, "outputs/log.txt") logger = Logger(LOG_FILE) # Log start of emissions capture - logger.log("#####################################################################################################") - logger.log(" CAPTURE INITIAL EMISSIONS ") - logger.log("#####################################################################################################") + logger.log( + "#####################################################################################################" + ) + logger.log( + " CAPTURE INITIAL EMISSIONS " + ) + logger.log( + "#####################################################################################################" + ) # Measure energy with CodeCarbonEnergyMeter codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) codecarbon_energy_meter.measure_energy() # Measure emissions initial_emission = codecarbon_energy_meter.emissions # Get initial emission - initial_emission_data = codecarbon_energy_meter.emissions_data # Get initial emission data + initial_emission_data = ( + codecarbon_energy_meter.emissions_data + ) # Get initial emission data # Save initial emission data save_json_files("initial_emissions_data.txt", initial_emission_data, logger) logger.log(f"Initial Emissions: {initial_emission} kg CO2") - logger.log("#####################################################################################################\n\n") + logger.log( + "#####################################################################################################\n\n" + ) # Log start of code smells capture - logger.log("#####################################################################################################") - logger.log(" CAPTURE CODE SMELLS ") - logger.log("#####################################################################################################") - + logger.log( + "#####################################################################################################" + ) + logger.log( + " CAPTURE CODE SMELLS " + ) + logger.log( + "#####################################################################################################" + ) + # Anaylze code smells with PylintAnalyzer pylint_analyzer = PylintAnalyzer(TEST_FILE, logger) - pylint_analyzer.analyze() # analyze all smells - pylint_analyzer.configure_smells() # get all configured smells + pylint_analyzer.analyze() # analyze all smells + pylint_analyzer.configure_smells() # get all configured smells # Save code smells - save_json_files("all_configured_pylint_smells.json", pylint_analyzer.smells_data, logger) + save_json_files( + "all_configured_pylint_smells.json", pylint_analyzer.smells_data, logger + ) logger.log(f"Refactorable code smells: {len(pylint_analyzer.smells_data)}") - logger.log("#####################################################################################################\n\n") - + logger.log( + "#####################################################################################################\n\n" + ) + return # Log start of refactoring codes - logger.log("#####################################################################################################") - logger.log(" REFACTOR CODE SMELLS ") - logger.log("#####################################################################################################") + logger.log( + "#####################################################################################################" + ) + logger.log( + " REFACTOR CODE SMELLS " + ) + logger.log( + "#####################################################################################################" + ) # Refactor code smells TEST_FILE_COPY = copy_file_to_output(TEST_FILE, "refactored-test-case.py") emission = initial_emission for pylint_smell in pylint_analyzer.smells_data: - refactoring_class = RefactorerFactory.build_refactorer_class(TEST_FILE_COPY, pylint_smell["message-id"], pylint_smell, emission, logger) + refactoring_class = RefactorerFactory.build_refactorer_class( + TEST_FILE_COPY, pylint_smell["message-id"], pylint_smell, emission, logger + ) if refactoring_class: refactoring_class.refactor() emission = refactoring_class.final_emission else: - logger.log(f"Refactoring for smell {pylint_smell['symbol']} is not implemented.") - logger.log("#####################################################################################################\n\n") + logger.log( + f"Refactoring for smell {pylint_smell['symbol']} is not implemented." + ) + logger.log( + "#####################################################################################################\n\n" + ) # Log start of emissions capture - logger.log("#####################################################################################################") - logger.log(" CAPTURE FINAL EMISSIONS ") - logger.log("#####################################################################################################") + logger.log( + "#####################################################################################################" + ) + logger.log( + " CAPTURE FINAL EMISSIONS " + ) + logger.log( + "#####################################################################################################" + ) # Measure energy with CodeCarbonEnergyMeter codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) codecarbon_energy_meter.measure_energy() # Measure emissions final_emission = codecarbon_energy_meter.emissions # Get final emission - final_emission_data = codecarbon_energy_meter.emissions_data # Get final emission data + final_emission_data = ( + codecarbon_energy_meter.emissions_data + ) # Get final emission data # Save final emission data save_json_files("final_emissions_data.txt", final_emission_data, logger) logger.log(f"Final Emissions: {final_emission} kg CO2") - logger.log("#####################################################################################################\n\n") + logger.log( + "#####################################################################################################\n\n" + ) # The emissions from codecarbon are so inconsistent that this could be a possibility :( if final_emission >= initial_emission: - logger.log("Final emissions are greater than initial emissions; we are going to fail") + logger.log( + "Final emissions are greater than initial emissions; we are going to fail" + ) else: logger.log(f"Saved {initial_emission - final_emission} kg CO2") if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index fc8067e0..5896a92f 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -1,106 +1,30 @@ [ { - "column": 11, - "endColumn": 44, - "endLine": 5, - "line": 5, - "message": "Use a generator instead 'any(num > 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "has_positive", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", + "column": 4, + "endColumn": 27, + "endLine": 32, + "line": 32, + "message": "Too many arguments (9/5)", + "message-id": "R0913", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "too-many-arguments", "type": "refactor" }, { - "column": 11, - "endColumn": 45, - "endLine": 9, - "line": 9, - "message": "Use a generator instead 'all(num >= 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_non_negative", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 13, - "line": 13, - "message": "Use a generator instead 'any(len(s) > 10 for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "contains_large_strings", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 17, - "line": 17, - "message": "Use a generator instead 'all(s.isupper() for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_uppercase", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 63, - "endLine": 21, - "line": 21, - "message": "Use a generator instead 'any(num % 5 == 0 and num > 100 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "contains_special_numbers", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 25, - "line": 25, - "message": "Use a generator instead 'all(s.islower() for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_lowercase", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 49, - "endLine": 29, - "line": 29, - "message": "Use a generator instead 'any(num % 2 == 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "any_even_numbers", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 11, - "endColumn": 52, - "endLine": 33, - "line": 33, - "message": "Use a generator instead 'all(s.startswith('A') for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_strings_start_with_a", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "column": 18, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 22, + "message": "Method chain too long (3/3)", + "message-id": "LMC001", + "module": "ineffcient_code_example_2.py", + "obj": "", + "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "long-message-chain", + "type": "convention" } ] \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index d47bf537..f166360a 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 8, - "cpu_energy": 1.639372916542925e-07, - "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", - "cpu_power": 7.5, - "duration": 0.079180600005202, - "emissions": 1.0797985699863445e-08, - "emissions_rate": 1.3637160742851206e-07, - "energy_consumed": 2.7339128826325853e-07, + "cpu_count": 16, + "cpu_energy": NaN, + "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "cpu_power": NaN, + "duration": 4.997579105984187, + "emissions": NaN, + "emissions_rate": NaN, + "energy_consumed": NaN, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": NaN, - "gpu_energy": 0, - "gpu_model": NaN, - "gpu_power": 0.0, + "gpu_count": 1, + "gpu_energy": NaN, + "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "gpu_power": NaN, "latitude": 43.266, "longitude": -79.9441, "on_cloud": "N", - "os": "Windows-11-10.0.22631-SP0", + "os": "macOS-14.4-x86_64-i386-64bit", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 1.0945399660896601e-07, - "ram_power": 6.730809688568115, - "ram_total_size": 17.94882583618164, + "python_version": "3.10.10", + "ram_energy": 8.645874331705273e-08, + "ram_power": 6.0, + "ram_total_size": 16.0, "region": "ontario", - "run_id": "d262c06e-8840-49da-9df9-77fb55f0e018", - "timestamp": "2024-11-09T00:01:15", + "run_id": "26c0c12d-ea46-46ff-91b4-fe00b698fe37", + "timestamp": "2024-11-09T02:01:36", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 84c8fdef..c1464c8a 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,94 +1,22 @@ -[2024-11-09 00:01:09] ##################################################################################################### -[2024-11-09 00:01:09] CAPTURE INITIAL EMISSIONS -[2024-11-09 00:01:09] ##################################################################################################### -[2024-11-09 00:01:09] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-09 00:01:15] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:15] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt -[2024-11-09 00:01:15] Initial Emissions: 1.0797985699863445e-08 kg CO2 -[2024-11-09 00:01:15] ##################################################################################################### +[2024-11-09 02:01:18] ##################################################################################################### +[2024-11-09 02:01:18] CAPTURE INITIAL EMISSIONS +[2024-11-09 02:01:18] ##################################################################################################### +[2024-11-09 02:01:18] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 02:01:31] CodeCarbon measurement completed successfully. +[2024-11-09 02:01:36] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-09 02:01:36] Initial Emissions: nan kg CO2 +[2024-11-09 02:01:36] ##################################################################################################### + + +[2024-11-09 02:01:36] ##################################################################################################### +[2024-11-09 02:01:36] CAPTURE CODE SMELLS +[2024-11-09 02:01:36] ##################################################################################################### +[2024-11-09 02:01:36] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-09 02:01:36] Pylint analyzer completed successfully. +[2024-11-09 02:01:36] Running custom parsers: +[2024-11-09 02:01:36] Filtering pylint smells +[2024-11-09 02:01:36] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-09 02:01:36] Refactorable code smells: 2 +[2024-11-09 02:01:36] ##################################################################################################### -[2024-11-09 00:01:15] ##################################################################################################### -[2024-11-09 00:01:15] CAPTURE CODE SMELLS -[2024-11-09 00:01:15] ##################################################################################################### -[2024-11-09 00:01:15] Running Pylint analysis on ineffcient_code_example_1.py -[2024-11-09 00:01:15] Pylint analyzer completed successfully. -[2024-11-09 00:01:15] Filtering pylint smells -[2024-11-09 00:01:15] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json -[2024-11-09 00:01:15] Refactorable code smells: 8 -[2024-11-09 00:01:15] ##################################################################################################### - - -[2024-11-09 00:01:15] ##################################################################################################### -[2024-11-09 00:01:15] REFACTOR CODE SMELLS -[2024-11-09 00:01:15] ##################################################################################################### -[2024-11-09 00:01:15] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 5 for identified code smell. -[2024-11-09 00:01:15] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:21] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:21] Measured emissions for 'refactored-test-case.py.temp': 1.4291086052002757e-08 -[2024-11-09 00:01:21] Initial Emissions: 1.0797985699863445e-08 kg CO2. Final Emissions: 1.4291086052002757e-08 kg CO2. -[2024-11-09 00:01:21] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-09 00:01:21] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 9 for identified code smell. -[2024-11-09 00:01:21] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:27] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:27] Measured emissions for 'refactored-test-case.py.temp': 1.4151753578674423e-08 -[2024-11-09 00:01:27] Initial Emissions: 1.4291086052002757e-08 kg CO2. Final Emissions: 1.4151753578674423e-08 kg CO2. -[2024-11-09 00:01:27] Refactored list comprehension to generator expression on line 9 and saved. - -[2024-11-09 00:01:27] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 13 for identified code smell. -[2024-11-09 00:01:27] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:33] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:33] Measured emissions for 'refactored-test-case.py.temp': 1.4556037328786188e-08 -[2024-11-09 00:01:33] Initial Emissions: 1.4151753578674423e-08 kg CO2. Final Emissions: 1.4556037328786188e-08 kg CO2. -[2024-11-09 00:01:33] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-09 00:01:33] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 17 for identified code smell. -[2024-11-09 00:01:33] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:38] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:38] Measured emissions for 'refactored-test-case.py.temp': 1.3124271407934068e-08 -[2024-11-09 00:01:38] Initial Emissions: 1.4556037328786188e-08 kg CO2. Final Emissions: 1.3124271407934068e-08 kg CO2. -[2024-11-09 00:01:38] Refactored list comprehension to generator expression on line 17 and saved. - -[2024-11-09 00:01:38] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 21 for identified code smell. -[2024-11-09 00:01:38] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:44] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:44] Measured emissions for 'refactored-test-case.py.temp': 1.3861280032740713e-08 -[2024-11-09 00:01:44] Initial Emissions: 1.3124271407934068e-08 kg CO2. Final Emissions: 1.3861280032740713e-08 kg CO2. -[2024-11-09 00:01:44] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-09 00:01:44] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 25 for identified code smell. -[2024-11-09 00:01:44] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:49] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:50] Measured emissions for 'refactored-test-case.py.temp': 1.408449410957712e-08 -[2024-11-09 00:01:50] Initial Emissions: 1.3861280032740713e-08 kg CO2. Final Emissions: 1.408449410957712e-08 kg CO2. -[2024-11-09 00:01:50] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-09 00:01:50] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 29 for identified code smell. -[2024-11-09 00:01:50] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:01:55] CodeCarbon measurement completed successfully. -[2024-11-09 00:01:55] Measured emissions for 'refactored-test-case.py.temp': 1.3973626482026841e-08 -[2024-11-09 00:01:55] Initial Emissions: 1.408449410957712e-08 kg CO2. Final Emissions: 1.3973626482026841e-08 kg CO2. -[2024-11-09 00:01:55] Refactored list comprehension to generator expression on line 29 and saved. - -[2024-11-09 00:01:55] Applying 'Use a Generator' refactor on 'refactored-test-case.py' at line 33 for identified code smell. -[2024-11-09 00:01:55] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 00:02:01] CodeCarbon measurement completed successfully. -[2024-11-09 00:02:01] Measured emissions for 'refactored-test-case.py.temp': 1.3353186227676251e-08 -[2024-11-09 00:02:01] Initial Emissions: 1.3973626482026841e-08 kg CO2. Final Emissions: 1.3353186227676251e-08 kg CO2. -[2024-11-09 00:02:01] Refactored list comprehension to generator expression on line 33 and saved. - -[2024-11-09 00:02:01] ##################################################################################################### - - -[2024-11-09 00:02:01] ##################################################################################################### -[2024-11-09 00:02:01] CAPTURE FINAL EMISSIONS -[2024-11-09 00:02:01] ##################################################################################################### -[2024-11-09 00:02:01] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-09 00:02:07] CodeCarbon measurement completed successfully. -[2024-11-09 00:02:07] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt -[2024-11-09 00:02:07] Final Emissions: 1.3743098537414197e-08 kg CO2 -[2024-11-09 00:02:07] ##################################################################################################### - - -[2024-11-09 00:02:07] Final emissions are greater than initial emissions; we are going to fail diff --git a/src1/outputs/smells.json b/src1/outputs/smells.json new file mode 100644 index 00000000..974c2a05 --- /dev/null +++ b/src1/outputs/smells.json @@ -0,0 +1,197 @@ +{ + "messages": [ + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 19, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (87/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 41, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (85/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 57, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "line-too-long", + "message": "Line too long (86/80)", + "messageId": "C0301", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "", + "line": 74, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "missing-module-docstring", + "message": "Missing module docstring", + "messageId": "C0114", + "confidence": "HIGH", + "module": "inefficent_code_example", + "obj": "", + "line": 1, + "column": 0, + "endLine": null, + "endColumn": null, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "missing-class-docstring", + "message": "Missing class docstring", + "messageId": "C0115", + "confidence": "HIGH", + "module": "inefficent_code_example", + "obj": "DataProcessor", + "line": 2, + "column": 0, + "endLine": 2, + "endColumn": 19, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "missing-function-docstring", + "message": "Missing function or method docstring", + "messageId": "C0116", + "confidence": "INFERENCE", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "line": 8, + "column": 4, + "endLine": 8, + "endColumn": 24, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "warning", + "symbol": "broad-exception-caught", + "message": "Catching too general exception Exception", + "messageId": "W0718", + "confidence": "INFERENCE", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "line": 18, + "column": 16, + "endLine": 18, + "endColumn": 25, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "error", + "symbol": "no-member", + "message": "Instance of 'DataProcessor' has no 'complex_calculation' member", + "messageId": "E1101", + "confidence": "INFERENCE", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data", + "line": 13, + "column": 25, + "endLine": 13, + "endColumn": 49, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "convention", + "symbol": "singleton-comparison", + "message": "Comparison 'x != None' should be 'x is not None'", + "messageId": "C0121", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "DataProcessor.process_all_data.", + "line": 27, + "column": 29, + "endLine": 27, + "endColumn": 38, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "type": "refactor", + "symbol": "too-few-public-methods", + "message": "Too few public methods (1/2)", + "messageId": "R0903", + "confidence": "UNDEFINED", + "module": "inefficent_code_example", + "obj": "DataProcessor", + "line": 2, + "column": 0, + "endLine": 2, + "endColumn": 19, + "path": "test/inefficent_code_example.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" + }, + { + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "column": 18, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 22, + "message": "Method chain too long (3/3)", + "message-id": "LMC001", + "module": "ineffcient_code_example_2.py", + "obj": "", + "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "long-message-chain", + "type": "convention" + } + ], + "statistics": { + "messageTypeCount": { + "fatal": 0, + "error": 2, + "warning": 6, + "refactor": 7, + "convention": 14, + "info": 0 + }, + "modulesLinted": 3, + "score": 2.13 + } + } + \ No newline at end of file diff --git a/src1/refactorers/base_refactorer.py b/src1/refactorers/base_refactorer.py index d6604de8..ed3b29f3 100644 --- a/src1/refactorers/base_refactorer.py +++ b/src1/refactorers/base_refactorer.py @@ -12,7 +12,6 @@ def __init__(self, logger): :param logger: Logger instance to handle log messages. """ - self.final_emission = None self.logger = logger # Store the mandatory logger instance @abstractmethod diff --git a/src1/refactorers/long_lambda_function_refactorer.py b/src1/refactorers/long_lambda_function_refactorer.py new file mode 100644 index 00000000..bc409b73 --- /dev/null +++ b/src1/refactorers/long_lambda_function_refactorer.py @@ -0,0 +1,17 @@ +from .base_refactorer import BaseRefactorer + + +class LongLambdaFunctionRefactorer(BaseRefactorer): + """ + Refactorer that targets long methods to improve readability. + """ + + def __init__(self, logger): + super().__init__(logger) + + def refactor(self, file_path, pylint_smell, initial_emission): + """ + Refactor long lambda functions + """ + # Logic to identify long methods goes here + pass diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py new file mode 100644 index 00000000..c98572c1 --- /dev/null +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -0,0 +1,17 @@ +from .base_refactorer import BaseRefactorer + + +class LongMessageChainRefactorer(BaseRefactorer): + """ + Refactorer that targets long method chains to improve performance. + """ + + def __init__(self, logger): + super().__init__(logger) + + def refactor(self, file_path, pylint_smell, initial_emission): + """ + Refactor long message chain + """ + # Logic to identify long methods goes here + pass diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactor.py index 86f87441..0e6ed762 100644 --- a/src1/refactorers/use_a_generator_refactor.py +++ b/src1/refactorers/use_a_generator_refactor.py @@ -1,34 +1,37 @@ # refactorers/use_a_generator_refactor.py import ast -import astor # For converting AST back to source code +import ast # For converting AST back to source code import shutil import os from .base_refactorer import BaseRefactorer + class UseAGeneratorRefactor(BaseRefactorer): def __init__(self, logger): """ Initializes the UseAGeneratorRefactor with a file path, pylint smell, initial emission, and logger. - + :param file_path: Path to the file to be refactored. :param pylint_smell: Dictionary containing details of the Pylint smell. :param initial_emission: Initial emission value before refactoring. :param logger: Logger instance to handle log messages. """ - super().__init__( logger) + super().__init__(logger) def refactor(self, file_path, pylint_smell, initial_emission): """ Refactors an unnecessary list comprehension by converting it to a generator expression. Modifies the specified instance in the file directly if it results in lower emissions. """ - line_number = self.pylint_smell['line'] - self.logger.log(f"Applying 'Use a Generator' refactor on '{os.path.basename(self.file_path)}' at line {line_number} for identified code smell.") - + line_number = self.pylint_smell["line"] + self.logger.log( + f"Applying 'Use a Generator' refactor on '{os.path.basename(self.file_path)}' at line {line_number} for identified code smell." + ) + # Load the source code as a list of lines - with open(self.file_path, 'r') as file: + with open(self.file_path, "r") as file: original_lines = file.readlines() # Check if the line number is valid within the file @@ -39,10 +42,12 @@ def refactor(self, file_path, pylint_smell, initial_emission): # Target the specific line and remove leading whitespace for parsing line = original_lines[line_number - 1] stripped_line = line.lstrip() # Strip leading indentation - indentation = line[:len(line) - len(stripped_line)] # Track indentation + indentation = line[: len(line) - len(stripped_line)] # Track indentation # Parse the line as an AST - line_ast = ast.parse(stripped_line, mode='exec') # Use 'exec' mode for full statements + line_ast = ast.parse( + stripped_line, mode="exec" + ) # Use 'exec' mode for full statements # Look for a list comprehension within the AST of this line modified = False @@ -50,11 +55,10 @@ def refactor(self, file_path, pylint_smell, initial_emission): if isinstance(node, ast.ListComp): # Convert the list comprehension to a generator expression generator_expr = ast.GeneratorExp( - elt=node.elt, - generators=node.generators + elt=node.elt, generators=node.generators ) ast.copy_location(generator_expr, node) - + # Replace the list comprehension node with the generator expression self._replace_node(line_ast, node, generator_expr) modified = True @@ -69,7 +73,7 @@ def refactor(self, file_path, pylint_smell, initial_emission): # Temporarily write the modified content to a temporary file temp_file_path = f"{self.file_path}.temp" - with open(temp_file_path, 'w') as temp_file: + with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) # Measure emissions of the modified code @@ -79,18 +83,24 @@ def refactor(self, file_path, pylint_smell, initial_emission): if self.check_energy_improvement(): # If improved, replace the original file with the modified content shutil.move(temp_file_path, self.file_path) - self.logger.log(f"Refactored list comprehension to generator expression on line {line_number} and saved.\n") + self.logger.log( + f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" + ) else: # Remove the temporary file if no improvement os.remove(temp_file_path) - self.logger.log("No emission improvement after refactoring. Discarded refactored changes.\n") + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) else: - self.logger.log("No applicable list comprehension found on the specified line.\n") + self.logger.log( + "No applicable list comprehension found on the specified line.\n" + ) def _replace_node(self, tree, old_node, new_node): """ Helper function to replace an old AST node with a new one within a tree. - + :param tree: The AST tree or node containing the node to be replaced. :param old_node: The node to be replaced. :param new_node: The new node to replace it with. diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 3a7624cb..89207f9c 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -2,44 +2,55 @@ from enum import Enum from itertools import chain + class ExtendedEnum(Enum): @classmethod def list(cls) -> list[str]: return [c.value for c in cls] - + def __str__(self): return str(self.value) + # Enum class for standard Pylint code smells class PylintSmell(ExtendedEnum): - LONG_MESSAGE_CHAIN = "R0914" # Pylint code smell for long message chains LARGE_CLASS = "R0902" # Pylint code smell for classes with too many attributes - LONG_PARAMETER_LIST = "R0913" # Pylint code smell for functions with too many parameters + LONG_PARAMETER_LIST = ( + "R0913" # Pylint code smell for functions with too many parameters + ) LONG_METHOD = "R0915" # Pylint code smell for methods that are too long - COMPLEX_LIST_COMPREHENSION = "C0200" # Pylint code smell for complex list comprehensions - INVALID_NAMING_CONVENTIONS = "C0103" # Pylint code smell for naming conventions violations + COMPLEX_LIST_COMPREHENSION = ( + "C0200" # Pylint code smell for complex list comprehensions + ) + INVALID_NAMING_CONVENTIONS = ( + "C0103" # Pylint code smell for naming conventions violations + ) USE_A_GENERATOR = "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` + # Enum class for custom code smells not detected by Pylint class CustomSmell(ExtendedEnum): LONG_TERN_EXPR = "CUST-1" # Custom code smell for long ternary expressions + LONG_MESSAGE_CHAIN = "LMC001" # CUSTOM CODE + class IntermediateSmells(ExtendedEnum): - LINE_TOO_LONG = "C0301" # pylint smell + LINE_TOO_LONG = "C0301" # pylint smell + # Enum containing all smells class AllSmells(ExtendedEnum): - _ignore_ = 'member cls' + _ignore_ = "member cls" cls = vars() - for member in chain(list(PylintSmell), - list(CustomSmell)): + for member in chain(list(PylintSmell), list(CustomSmell)): cls[member.name] = member.value + # Additional Pylint configuration options for analyzing code EXTRA_PYLINT_OPTIONS = [ "--max-line-length=80", # Sets maximum allowed line length "--max-nested-blocks=3", # Limits maximum nesting of blocks "--max-branches=3", # Limits maximum branches in a function - "--max-parents=3" # Limits maximum inheritance levels for a class -] \ No newline at end of file + "--max-parents=3", # Limits maximum inheritance levels for a class +] diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index 3f522dd4..cff91662 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -1,12 +1,19 @@ -# import unittest -# from src.analyzer.pylint_analyzer import PylintAnalyzer - -# class TestPylintAnalyzer(unittest.TestCase): -# def test_analyze_method(self): -# analyzer = PylintAnalyzer("path/to/test/code.py") -# report = analyzer.analyze() -# self.assertIsInstance(report, list) # Check if the output is a list -# # Add more assertions based on expected output - -# if __name__ == "__main__": -# unittest.main() +import unittest +from ..src1.analyzers.pylint_analyzer import PylintAnalyzer + + +class TestPylintAnalyzer(unittest.TestCase): + def test_analyze_method(self): + analyzer = PylintAnalyzer("input/ineffcient_code_example_2.py") + analyzer.analyze() + analyzer.configure_smells() + + data = analyzer.smells_data + + print(data) + # self.assertIsInstance(report, list) # Check if the output is a list + # # Add more assertions based on expected output + + +if __name__ == "__main__": + unittest.main() From 8835302f902f783262961e5cf29a90b9f8d08ff5 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 9 Nov 2024 16:17:25 -0500 Subject: [PATCH 052/105] delete old src folder --- src/README.md | 5 - src/__init__.py | 5 - src/analyzers/__init__.py | 0 .../__pycache__/base_analyzer.cpython-310.pyc | Bin 732 -> 0 bytes src/analyzers/base_analyzer.py | 11 -- src/analyzers/inefficent_code_example.py | 90 ------------- src/analyzers/pylint_analyzer.py | 120 ------------------ src/main.py | 57 --------- src/measurement/__init__.py | 0 src/measurement/code_carbon_meter.py | 60 --------- src/measurement/custom_energy_measure.py | 62 --------- src/measurement/energy_meter.py | 115 ----------------- src/measurement/measurement_utils.py | 41 ------ src/output/ast.txt | 1 - src/output/ast_lines.txt | 1 - src/output/carbon_report.csv | 3 - src/output/initial_carbon_report.csv | 33 ----- src/output/report.txt | 67 ---------- src/refactorer/__init__.py | 0 src/refactorer/base_refactorer.py | 26 ---- .../complex_list_comprehension_refactorer.py | 116 ----------------- src/refactorer/large_class_refactorer.py | 83 ------------ src/refactorer/long_base_class_list.py | 14 -- src/refactorer/long_element_chain.py | 21 --- .../long_lambda_function_refactorer.py | 16 --- .../long_message_chain_refactorer.py | 17 --- src/refactorer/long_method_refactorer.py | 18 --- src/refactorer/long_scope_chaining.py | 24 ---- .../long_ternary_cond_expression.py | 17 --- src/testing/__init__.py | 0 src/testing/test_runner.py | 17 --- src/testing/test_validator.py | 3 - src/utils/__init__.py | 0 src/utils/ast_parser.py | 17 --- src/utils/code_smells.py | 22 ---- src/utils/factory.py | 23 ---- src/utils/logger.py | 34 ----- 37 files changed, 1139 deletions(-) delete mode 100644 src/README.md delete mode 100644 src/__init__.py delete mode 100644 src/analyzers/__init__.py delete mode 100644 src/analyzers/__pycache__/base_analyzer.cpython-310.pyc delete mode 100644 src/analyzers/base_analyzer.py delete mode 100644 src/analyzers/inefficent_code_example.py delete mode 100644 src/analyzers/pylint_analyzer.py delete mode 100644 src/main.py delete mode 100644 src/measurement/__init__.py delete mode 100644 src/measurement/code_carbon_meter.py delete mode 100644 src/measurement/custom_energy_measure.py delete mode 100644 src/measurement/energy_meter.py delete mode 100644 src/measurement/measurement_utils.py delete mode 100644 src/output/ast.txt delete mode 100644 src/output/ast_lines.txt delete mode 100644 src/output/carbon_report.csv delete mode 100644 src/output/initial_carbon_report.csv delete mode 100644 src/output/report.txt delete mode 100644 src/refactorer/__init__.py delete mode 100644 src/refactorer/base_refactorer.py delete mode 100644 src/refactorer/complex_list_comprehension_refactorer.py delete mode 100644 src/refactorer/large_class_refactorer.py delete mode 100644 src/refactorer/long_base_class_list.py delete mode 100644 src/refactorer/long_element_chain.py delete mode 100644 src/refactorer/long_lambda_function_refactorer.py delete mode 100644 src/refactorer/long_message_chain_refactorer.py delete mode 100644 src/refactorer/long_method_refactorer.py delete mode 100644 src/refactorer/long_scope_chaining.py delete mode 100644 src/refactorer/long_ternary_cond_expression.py delete mode 100644 src/testing/__init__.py delete mode 100644 src/testing/test_runner.py delete mode 100644 src/testing/test_validator.py delete mode 100644 src/utils/__init__.py delete mode 100644 src/utils/ast_parser.py delete mode 100644 src/utils/code_smells.py delete mode 100644 src/utils/factory.py delete mode 100644 src/utils/logger.py diff --git a/src/README.md b/src/README.md deleted file mode 100644 index 50aa3a2c..00000000 --- a/src/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Project Name Source Code - -The folders and files for this project are as follows: - -... diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index 56f09c20..00000000 --- a/src/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from . import analyzers -from . import measurement -from . import refactorer -from . import testing -from . import utils \ No newline at end of file diff --git a/src/analyzers/__init__.py b/src/analyzers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc b/src/analyzers/__pycache__/base_analyzer.cpython-310.pyc deleted file mode 100644 index 9e719a7982b155e4863ac8611a5092b72de327c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 732 zcmY*Wy>8nu5ayATt)#XQ1nDaj5Kvn$P!vf#bn_Av1+)+}$uuq`%O&N(Mz;7tlF`r8 zjYF19d4*2BlWjmf;Ewn4=kEKC^>BF3(EOjt&sSXE2y{&%xJD13F<54yWEB)p@qz+=~Choyp9@VaOHgq_RN34y}v*5@4@+y zR~wyAv28xptI*U-mz!fU9*27EjT;lIalL95)dE@O!JAwkDTjQH0@MjkR-2eAwOB41 zrFuk{xL?BdV^`GD*hC7gk$pKkL*7$8KU2PS6-+Gdh(ul{Rx zyfDLQBekWjoKo>zsj9Z?lJbF4zt_4vo(TMAKcr4HazCO#1M388?1>=_H>4O+HUch2 n(C%hQ6nbtvNk0_nQ$`OuMcSIJg!IdS%2!e!Nbm(q;Y$1i-It)8 diff --git a/src/analyzers/base_analyzer.py b/src/analyzers/base_analyzer.py deleted file mode 100644 index 25840b46..00000000 --- a/src/analyzers/base_analyzer.py +++ /dev/null @@ -1,11 +0,0 @@ -from abc import ABC, abstractmethod -import os - - -class BaseAnalyzer(ABC): - def __init__(self, code_path: str): - self.code_path = os.path.abspath(code_path) - - @abstractmethod - def analyze(self): - pass diff --git a/src/analyzers/inefficent_code_example.py b/src/analyzers/inefficent_code_example.py deleted file mode 100644 index f8f32921..00000000 --- a/src/analyzers/inefficent_code_example.py +++ /dev/null @@ -1,90 +0,0 @@ -# LC: Large Class with too many responsibilities -class DataProcessor: - def __init__(self, data): - self.data = data - self.processed_data = [] - - # LM: Long Method - this method does way too much - def process_all_data(self): - results = [] - for item in self.data: - try: - # LPL: Long Parameter List - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) - results.append(result) - except ( - Exception - ) as e: # UEH: Unqualified Exception Handling, catching generic exceptions - print("An error occurred:", e) - - # LMC: Long Message Chain - print(self.data[0].upper().strip().replace(" ", "_").lower()) - - # LLF: Long Lambda Function - self.processed_data = list( - filter(lambda x: x != None and x != 0 and len(str(x)) > 1, results) - ) - - return self.processed_data - - # LBCL: Long Base Class List - - -class AdvancedProcessor(DataProcessor, object, dict, list, set, tuple): - pass - - # LTCE: Long Ternary Conditional Expression - def check_data(self, item): - return ( - True if item > 10 else False if item < -10 else None if item == 0 else item - ) - - # Complex List Comprehension - def complex_comprehension(self): - # CLC: Complex List Comprehension - self.processed_data = [ - x**2 if x % 2 == 0 else x**3 - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] - - # Long Element Chain - def long_chain(self): - # LEC: Long Element Chain accessing deeply nested elements - try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] - return deep_value - except KeyError: - return None - - # Long Scope Chaining (LSC) - def long_scope_chaining(self): - for a in range(10): - for b in range(10): - for c in range(10): - for d in range(10): - for e in range(10): - if a + b + c + d + e > 25: - return "Done" - - # LPL: Long Parameter List - def complex_calculation( - self, item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": - result = item * threshold - elif operation == "add": - result = item + max_value - else: - result = item - return result - - -# Main method to execute the code -if __name__ == "__main__": - sample_data = [1, 2, 3, 4, 5] - processor = DataProcessor(sample_data) - processed = processor.process_all_data() - print("Processed Data:", processed) diff --git a/src/analyzers/pylint_analyzer.py b/src/analyzers/pylint_analyzer.py deleted file mode 100644 index e69d2692..00000000 --- a/src/analyzers/pylint_analyzer.py +++ /dev/null @@ -1,120 +0,0 @@ -import json -from io import StringIO - -# ONLY UNCOMMENT IF RUNNING FROM THIS FILE NOT MAIN -# you will need to change imports too -# ====================================================== -from os.path import dirname, abspath -import sys -import ast - -# Sets src as absolute path, everything needs to be relative to src folder -REFACTOR_DIR = dirname(abspath(__file__)) -sys.path.append(dirname(REFACTOR_DIR)) - -from pylint.lint import Run -from pylint.reporters.json_reporter import JSON2Reporter - -from analyzers.base_analyzer import BaseAnalyzer -from refactorer.large_class_refactorer import LargeClassRefactorer -from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer -from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer - -from utils.code_smells import CodeSmells -from utils.ast_parser import parse_line, parse_file - -from utils.code_smells import CodeSmells -from utils.ast_parser import parse_line, parse_file - - -class PylintAnalyzer(BaseAnalyzer): - def __init__(self, code_path: str): - super().__init__(code_path) - # We are going to use the codes to identify the smells this is a dict of all of them - - def analyze(self): - """ - Runs pylint on the specified Python file and returns the output as a list of dictionaries. - Each dictionary contains information about a code smell or warning identified by pylint. - - :param file_path: The path to the Python file to be analyzed. - :return: A list of dictionaries with pylint messages. - """ - # Capture pylint output into a string stream - output_stream = StringIO() - reporter = JSON2Reporter(output_stream) - - # Run pylint - Run( - [ - "--max-line-length=80", - "--max-nested-blocks=3", - "--max-branches=3", - "--max-parents=3", - self.code_path, - ], - reporter=reporter, - exit=False, - ) - - # Retrieve and parse output as JSON - output = output_stream.getvalue() - - try: - pylint_results = json.loads(output) - except json.JSONDecodeError: - print("Error: Could not decode pylint output") - pylint_results = [] - - print(pylint_results) - return pylint_results - - def filter_for_all_wanted_code_smells(self, pylint_results): - statistics = {} - report = [] - filtered_results = [] - - for error in pylint_results: - if error["messageId"] in CodeSmells.list(): - statistics[error["messageId"]] = True - filtered_results.append(error) - - report.append(filtered_results) - report.append(statistics) - - with open("src/output/report.txt", "w+") as f: - print(json.dumps(report, indent=2), file=f) - - return report - - def filter_for_one_code_smell(self, pylint_results, code): - filtered_results = [] - for error in pylint_results: - if error["messageId"] == code: - filtered_results.append(error) - - return filtered_results - - -# Example usage -if __name__ == "__main__": - - FILE_PATH = abspath("test/inefficent_code_example.py") - - analyzer = PylintAnalyzer(FILE_PATH) - - # print("THIS IS REPORT for our smells:") - report = analyzer.analyze() - - with open("src/output/ast.txt", "w+") as f: - print(parse_file(FILE_PATH), file=f) - - filtered_results = analyzer.filter_for_one_code_smell(report["messages"], "C0301") - - with open(FILE_PATH, "r") as f: - file_lines = f.readlines() - - for smell in filtered_results: - with open("src/output/ast_lines.txt", "a+") as f: - print("Parsing line ", smell["line"], file=f) - print(parse_line(file_lines, smell["line"]), end="\n", file=f) diff --git a/src/main.py b/src/main.py deleted file mode 100644 index c3696a46..00000000 --- a/src/main.py +++ /dev/null @@ -1,57 +0,0 @@ -import ast -import os - -from analyzers.pylint_analyzer import PylintAnalyzer -from measurement.code_carbon_meter import CarbonAnalyzer -from utils.factory import RefactorerFactory -from utils.code_smells import CodeSmells -from utils import ast_parser - -dirname = os.path.dirname(__file__) - -def main(): - """ - Entry point for the refactoring tool. - - Create an instance of the analyzer. - - Perform code analysis and print the results. - """ - - # okay so basically this guy gotta call 1) pylint 2) refactoring class for every bug - TEST_FILE_PATH = os.path.join(dirname, "../test/inefficent_code_example.py") - INITIAL_REPORT_FILE_PATH = os.path.join(dirname, "output/initial_carbon_report.csv") - - carbon_analyzer = CarbonAnalyzer(TEST_FILE_PATH) - carbon_analyzer.run_and_measure() - carbon_analyzer.save_report(INITIAL_REPORT_FILE_PATH) - - analyzer = PylintAnalyzer(TEST_FILE_PATH) - report = analyzer.analyze() - - filtered_report = analyzer.filter_for_all_wanted_code_smells(report["messages"]) - detected_smells = filtered_report[0] - # statistics = filtered_report[1] - - for smell in detected_smells: - smell_id = smell["messageId"] - - if smell_id == CodeSmells.LINE_TOO_LONG.value: - root_node = ast_parser.parse_line(TEST_FILE_PATH, smell["line"]) - - if root_node is None: - continue - - smell_id = CodeSmells.LONG_TERN_EXPR - - # for node in ast.walk(root_node): - # print("Body: ", node["body"]) - # for expr in ast.walk(node.body[0]): - # if isinstance(expr, ast.IfExp): - # smell_id = CodeSmells.LONG_TERN_EXPR - - print("Refactoring ", smell_id) - refactoring_class = RefactorerFactory.build(smell_id, TEST_FILE_PATH) - refactoring_class.refactor() - - -if __name__ == "__main__": - main() diff --git a/src/measurement/__init__.py b/src/measurement/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/measurement/code_carbon_meter.py b/src/measurement/code_carbon_meter.py deleted file mode 100644 index a60ed932..00000000 --- a/src/measurement/code_carbon_meter.py +++ /dev/null @@ -1,60 +0,0 @@ -import subprocess -import sys -from codecarbon import EmissionsTracker -from pathlib import Path -import pandas as pd -from os.path import dirname, abspath - -REFACTOR_DIR = dirname(abspath(__file__)) -sys.path.append(dirname(REFACTOR_DIR)) - -class CarbonAnalyzer: - def __init__(self, script_path: str): - self.script_path = script_path - self.tracker = EmissionsTracker(save_to_file=False, allow_multiple_runs=True) - - def run_and_measure(self): - script = Path(self.script_path) - if not script.exists() or script.suffix != ".py": - raise ValueError("Please provide a valid Python script path.") - self.tracker.start() - try: - subprocess.run([sys.executable, str(script)], check=True) - except subprocess.CalledProcessError as e: - print(f"Error: The script encountered an error: {e}") - finally: - # Stop tracking and get emissions data - emissions = self.tracker.stop() - if emissions is None or pd.isna(emissions): - print("Warning: No valid emissions data collected. Check system compatibility.") - else: - print("Emissions data:", emissions) - - def save_report(self, report_path: str): - """ - Save the emissions report to a CSV file with two columns: attribute and value. - """ - emissions_data = self.tracker.final_emissions_data - if emissions_data: - # Convert EmissionsData object to a dictionary and create rows for each attribute - emissions_dict = emissions_data.__dict__ - attributes = list(emissions_dict.keys()) - values = list(emissions_dict.values()) - - # Create a DataFrame with two columns: 'Attribute' and 'Value' - df = pd.DataFrame({ - "Attribute": attributes, - "Value": values - }) - - # Save the DataFrame to CSV - df.to_csv(report_path, index=False) - print(f"Report saved to {report_path}") - else: - print("No data to save. Ensure CodeCarbon supports your system hardware for emissions tracking.") - -# Example usage -if __name__ == "__main__": - analyzer = CarbonAnalyzer("src/output/inefficent_code_example.py") - analyzer.run_and_measure() - analyzer.save_report("src/output/test/carbon_report.csv") diff --git a/src/measurement/custom_energy_measure.py b/src/measurement/custom_energy_measure.py deleted file mode 100644 index 212fcd2f..00000000 --- a/src/measurement/custom_energy_measure.py +++ /dev/null @@ -1,62 +0,0 @@ -import resource - -from measurement_utils import (start_process, calculate_ram_power, - start_pm_process, stop_pm_process, get_cpu_power_from_pm_logs) -import time - - -class CustomEnergyMeasure: - """ - Handles custom CPU and RAM energy measurements for executing a Python script. - Currently only works for Apple Silicon Chips with sudo access(password prompt in terminal) - Next step includes device detection for calculating on multiple platforms - """ - - def __init__(self, script_path: str): - self.script_path = script_path - self.results = {"cpu": 0.0, "ram": 0.0} - self.code_process_time = 0 - - def measure_cpu_power(self): - # start powermetrics as a child process - powermetrics_process = start_pm_process() - # allow time to enter password for sudo rights in mac - time.sleep(5) - try: - start_time = time.time() - # execute the provided code as another child process and wait to finish - code_process = start_process(["python3", self.script_path]) - code_process_pid = code_process.pid - code_process.wait() - end_time = time.time() - self.code_process_time = end_time - start_time - # Parse powermetrics log to extract CPU power data for this PID - finally: - stop_pm_process(powermetrics_process) - self.results["cpu"] = get_cpu_power_from_pm_logs("custom_energy_output.txt", code_process_pid) - - def measure_ram_power(self): - # execute provided code as a child process, this time without simultaneous powermetrics process - # code needs to rerun to use resource.getrusage() for a single child - # might look into another library that does not require this - code_process = start_process(["python3", self.script_path]) - code_process.wait() - - # get peak memory usage in bytes for this process - peak_memory_b = resource.getrusage(resource.RUSAGE_CHILDREN).ru_maxrss - - # calculate RAM power based on peak memory(3W/8GB ratio) - self.results["ram"] = calculate_ram_power(peak_memory_b) - - def calculate_energy_from_power(self): - # Return total energy consumed - total_power = self.results["cpu"] + self.results["ram"] # in watts - return total_power * self.code_process_time - - -if __name__ == "__main__": - custom_measure = CustomEnergyMeasure("/capstone--source-code-optimizer/test/high_energy_code_example.py") - custom_measure.measure_cpu_power() - custom_measure.measure_ram_power() - #can be saved as a report later - print(custom_measure.calculate_energy_from_power()) diff --git a/src/measurement/energy_meter.py b/src/measurement/energy_meter.py deleted file mode 100644 index 38426bf1..00000000 --- a/src/measurement/energy_meter.py +++ /dev/null @@ -1,115 +0,0 @@ -import time -from typing import Callable -from pyJoules.device import DeviceFactory -from pyJoules.device.rapl_device import RaplPackageDomain, RaplDramDomain -from pyJoules.device.nvidia_device import NvidiaGPUDomain -from pyJoules.energy_meter import EnergyMeter - -## Required for installation -# pip install pyJoules -# pip install nvidia-ml-py3 - -# TEST TO SEE IF PYJOULE WORKS FOR YOU - - -class EnergyMeterWrapper: - """ - A class to measure the energy consumption of specific code blocks using PyJoules. - """ - - def __init__(self): - """ - Initializes the EnergyMeterWrapper class. - """ - # Create and configure the monitored devices - domains = [RaplPackageDomain(0), RaplDramDomain(0), NvidiaGPUDomain(0)] - devices = DeviceFactory.create_devices(domains) - self.meter = EnergyMeter(devices) - - def measure_energy(self, func: Callable, *args, **kwargs): - """ - Measures the energy consumed by the specified function during its execution. - - Parameters: - - func (Callable): The function to measure. - - *args: Arguments to pass to the function. - - **kwargs: Keyword arguments to pass to the function. - - Returns: - - tuple: A tuple containing the return value of the function and the energy consumed (in Joules). - """ - self.meter.start(tag="function_execution") # Start measuring energy - - start_time = time.time() # Record start time - - result = func(*args, **kwargs) # Call the specified function - - end_time = time.time() # Record end time - self.meter.stop() # Stop measuring energy - - # Retrieve the energy trace - trace = self.meter.get_trace() - total_energy = sum( - sample.energy for sample in trace - ) # Calculate total energy consumed - - # Log the timing (optional) - print(f"Execution Time: {end_time - start_time:.6f} seconds") - print(f"Energy Consumed: {total_energy:.6f} Joules") - - return ( - result, - total_energy, - ) # Return the result of the function and the energy consumed - - def measure_block(self, code_block: str): - """ - Measures energy consumption for a block of code represented as a string. - - Parameters: - - code_block (str): A string containing the code to execute. - - Returns: - - float: The energy consumed (in Joules). - """ - local_vars = {} - self.meter.start(tag="block_execution") # Start measuring energy - exec(code_block, {}, local_vars) # Execute the code block - self.meter.stop() # Stop measuring energy - - # Retrieve the energy trace - trace = self.meter.get_trace() - total_energy = sum( - sample.energy for sample in trace - ) # Calculate total energy consumed - print(f"Energy Consumed for the block: {total_energy:.6f} Joules") - return total_energy - - def measure_file_energy(self, file_path: str): - """ - Measures the energy consumption of the code in the specified Python file. - - Parameters: - - file_path (str): The path to the Python file. - - Returns: - - float: The energy consumed (in Joules). - """ - try: - with open(file_path, "r") as file: - code = file.read() # Read the content of the file - - # Execute the code block and measure energy consumption - return self.measure_block(code) - - except Exception as e: - print(f"An error occurred while measuring energy for the file: {e}") - return None # Return None in case of an error - - -# Example usage -if __name__ == "__main__": - meter = EnergyMeterWrapper() - energy_used = meter.measure_file_energy("../test/inefficent_code_example.py") - if energy_used is not None: - print(f"Total Energy Consumed: {energy_used:.6f} Joules") diff --git a/src/measurement/measurement_utils.py b/src/measurement/measurement_utils.py deleted file mode 100644 index 292698c9..00000000 --- a/src/measurement/measurement_utils.py +++ /dev/null @@ -1,41 +0,0 @@ -import resource -import subprocess -import time -import re - - -def start_process(command): - return subprocess.Popen(command) - -def calculate_ram_power(memory_b): - memory_gb = memory_b / (1024 ** 3) - return memory_gb * 3 / 8 # 3W/8GB ratio - - -def start_pm_process(log_path="custom_energy_output.txt"): - powermetrics_process = subprocess.Popen( - ["sudo", "powermetrics", "--samplers", "tasks,cpu_power", "--show-process-gpu", "-i", "5000"], - stdout=open(log_path, "w"), - stderr=subprocess.PIPE - ) - return powermetrics_process - - -def stop_pm_process(powermetrics_process): - powermetrics_process.terminate() - -def get_cpu_power_from_pm_logs(log_path, pid): - cpu_share, total_cpu_power = None, None # in ms/s and mW respectively - with open(log_path, 'r') as file: - lines = file.readlines() - for line in lines: - if str(pid) in line: - cpu_share = float(line.split()[2]) - elif "CPU Power:" in line: - total_cpu_power = float(line.split()[2]) - if cpu_share and total_cpu_power: - break - if cpu_share and total_cpu_power: - cpu_power = (cpu_share / 1000) * (total_cpu_power / 1000) - return cpu_power - return None diff --git a/src/output/ast.txt b/src/output/ast.txt deleted file mode 100644 index a96cb4af..00000000 --- a/src/output/ast.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/output/ast_lines.txt b/src/output/ast_lines.txt deleted file mode 100644 index eb04405d..00000000 --- a/src/output/ast_lines.txt +++ /dev/null @@ -1 +0,0 @@ -Parsing line 19 diff --git a/src/output/carbon_report.csv b/src/output/carbon_report.csv deleted file mode 100644 index fd11fa7f..00000000 --- a/src/output/carbon_report.csv +++ /dev/null @@ -1,3 +0,0 @@ -timestamp,project_name,run_id,experiment_id,duration,emissions,emissions_rate,cpu_power,gpu_power,ram_power,cpu_energy,gpu_energy,ram_energy,energy_consumed,country_name,country_iso_code,region,cloud_provider,cloud_region,os,python_version,codecarbon_version,cpu_count,cpu_model,gpu_count,gpu_model,longitude,latitude,ram_total_size,tracking_mode,on_cloud,pue -2024-11-06T15:32:34,codecarbon,ab07718b-de1c-496e-91b2-c0ffd4e84ef5,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.1535916000138968,2.214386652360756e-08,1.4417368216493612e-07,7.5,0.0,6.730809688568115,3.176875000159877e-07,0,2.429670854124108e-07,5.606545854283984e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 -2024-11-06T15:37:39,codecarbon,515a920a-2566-4af3-92ef-5b930f41ca18,5b0fa12a-3dd7-45bb-9766-cc326314d9f1,0.15042520000133663,2.1765796594351643e-08,1.4469514811453293e-07,7.5,0.0,6.730809688568115,3.1103791661735157e-07,0,2.400444182185886e-07,5.510823348359402e-07,Canada,CAN,ontario,,,Windows-11-10.0.22631-SP0,3.13.0,2.7.2,8,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx,,,-79.9441,43.266,17.94882583618164,machine,N,1.0 diff --git a/src/output/initial_carbon_report.csv b/src/output/initial_carbon_report.csv deleted file mode 100644 index 7f3c8538..00000000 --- a/src/output/initial_carbon_report.csv +++ /dev/null @@ -1,33 +0,0 @@ -Attribute,Value -timestamp,2024-11-06T16:12:15 -project_name,codecarbon -run_id,17675603-c8ac-45c4-ae28-5b9fafa264d2 -experiment_id,5b0fa12a-3dd7-45bb-9766-cc326314d9f1 -duration,0.1571239999611862 -emissions,2.2439585954258806e-08 -emissions_rate,1.4281450293909256e-07 -cpu_power,7.5 -gpu_power,0.0 -ram_power,6.730809688568115 -cpu_energy,3.2567562496600047e-07 -gpu_energy,0 -ram_energy,2.4246620098645654e-07 -energy_consumed,5.68141825952457e-07 -country_name,Canada -country_iso_code,CAN -region,ontario -cloud_provider, -cloud_region, -os,Windows-11-10.0.22631-SP0 -python_version,3.13.0 -codecarbon_version,2.7.2 -cpu_count,8 -cpu_model,AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx -gpu_count, -gpu_model, -longitude,-79.9441 -latitude,43.266 -ram_total_size,17.94882583618164 -tracking_mode,machine -on_cloud,N -pue,1.0 diff --git a/src/output/report.txt b/src/output/report.txt deleted file mode 100644 index a478c274..00000000 --- a/src/output/report.txt +++ /dev/null @@ -1,67 +0,0 @@ -[ - [ - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 19, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (85/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 57, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (86/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 74, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py", - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\test\\inefficent_code_example.py" - } - ], - { - "C0301": true - } -] diff --git a/src/refactorer/__init__.py b/src/refactorer/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/refactorer/base_refactorer.py b/src/refactorer/base_refactorer.py deleted file mode 100644 index 3450ad9f..00000000 --- a/src/refactorer/base_refactorer.py +++ /dev/null @@ -1,26 +0,0 @@ -# src/refactorer/base_refactorer.py - -from abc import ABC, abstractmethod - - -class BaseRefactorer(ABC): - """ - Abstract base class for refactorers. - Subclasses should implement the `refactor` method. - """ - @abstractmethod - def __init__(self, code): - """ - Initialize the refactorer with the code to refactor. - - :param code: The code that needs refactoring - """ - self.code = code - - @abstractmethod - def refactor(code_smell_error, input_code): - """ - Perform the refactoring process. - Must be implemented by subclasses. - """ - pass diff --git a/src/refactorer/complex_list_comprehension_refactorer.py b/src/refactorer/complex_list_comprehension_refactorer.py deleted file mode 100644 index 7bf924b8..00000000 --- a/src/refactorer/complex_list_comprehension_refactorer.py +++ /dev/null @@ -1,116 +0,0 @@ -import ast -import astor -from .base_refactorer import BaseRefactorer - -class ComplexListComprehensionRefactorer(BaseRefactorer): - """ - Refactorer for complex list comprehensions to improve readability. - """ - - def __init__(self, code: str): - """ - Initializes the refactorer. - - :param code: The source code to refactor. - """ - super().__init__(code) - - def refactor(self): - """ - Refactor the code by transforming complex list comprehensions into for-loops. - - :return: The refactored code. - """ - # Parse the code to get the AST - tree = ast.parse(self.code) - - # Walk through the AST and refactor complex list comprehensions - for node in ast.walk(tree): - if isinstance(node, ast.ListComp): - # Check if the list comprehension is complex - if self.is_complex(node): - # Create a for-loop equivalent - for_loop = self.create_for_loop(node) - # Replace the list comprehension with the for-loop in the AST - self.replace_node(node, for_loop) - - # Convert the AST back to code - return self.ast_to_code(tree) - - def create_for_loop(self, list_comp: ast.ListComp) -> ast.For: - """ - Create a for-loop that represents the list comprehension. - - :param list_comp: The ListComp node to convert. - :return: An ast.For node representing the for-loop. - """ - # Create the variable to hold results - result_var = ast.Name(id='result', ctx=ast.Store()) - - # Create the for-loop - for_loop = ast.For( - target=ast.Name(id='item', ctx=ast.Store()), - iter=list_comp.generators[0].iter, - body=[ - ast.Expr(value=ast.Call( - func=ast.Name(id='append', ctx=ast.Load()), - args=[self.transform_value(list_comp.elt)], - keywords=[] - )) - ], - orelse=[] - ) - - # Create a list to hold results - result_list = ast.List(elts=[], ctx=ast.Store()) - return ast.With( - context_expr=ast.Name(id='result', ctx=ast.Load()), - body=[for_loop], - lineno=list_comp.lineno, - col_offset=list_comp.col_offset - ) - - def transform_value(self, value_node: ast.AST) -> ast.AST: - """ - Transform the value in the list comprehension into a form usable in a for-loop. - - :param value_node: The value node to transform. - :return: The transformed value node. - """ - return value_node - - def replace_node(self, old_node: ast.AST, new_node: ast.AST): - """ - Replace an old node in the AST with a new node. - - :param old_node: The node to replace. - :param new_node: The node to insert in its place. - """ - parent = self.find_parent(old_node) - if parent: - for index, child in enumerate(ast.iter_child_nodes(parent)): - if child is old_node: - parent.body[index] = new_node - break - - def find_parent(self, node: ast.AST) -> ast.AST: - """ - Find the parent node of a given AST node. - - :param node: The node to find the parent for. - :return: The parent node, or None if not found. - """ - for parent in ast.walk(node): - for child in ast.iter_child_nodes(parent): - if child is node: - return parent - return None - - def ast_to_code(self, tree: ast.AST) -> str: - """ - Convert AST back to source code. - - :param tree: The AST to convert. - :return: The source code as a string. - """ - return astor.to_source(tree) diff --git a/src/refactorer/large_class_refactorer.py b/src/refactorer/large_class_refactorer.py deleted file mode 100644 index c4af6ba3..00000000 --- a/src/refactorer/large_class_refactorer.py +++ /dev/null @@ -1,83 +0,0 @@ -import ast - -class LargeClassRefactorer: - """ - Refactorer for large classes that have too many methods. - """ - - def __init__(self, code: str, method_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of methods above which a class is considered large. - """ - super().__init__(code) - self.method_threshold = method_threshold - - def refactor(self): - """ - Refactor the class by splitting it into smaller classes if it exceeds the method threshold. - - :return: The refactored code. - """ - # Parse the code to get the class definition - tree = ast.parse(self.code) - class_definitions = [node for node in tree.body if isinstance(node, ast.ClassDef)] - - refactored_code = [] - - for class_def in class_definitions: - methods = [n for n in class_def.body if isinstance(n, ast.FunctionDef)] - if len(methods) > self.method_threshold: - # If the class is large, split it - new_classes = self.split_class(class_def, methods) - refactored_code.extend(new_classes) - else: - # Keep the class as is - refactored_code.append(class_def) - - # Convert the AST back to code - return self.ast_to_code(refactored_code) - - def split_class(self, class_def, methods): - """ - Split the large class into smaller classes based on methods. - - :param class_def: The class definition node. - :param methods: The list of methods in the class. - :return: A list of new class definitions. - """ - # For demonstration, we'll simply create two classes based on the method count - half_index = len(methods) // 2 - new_class1 = self.create_new_class(class_def.name + "Part1", methods[:half_index]) - new_class2 = self.create_new_class(class_def.name + "Part2", methods[half_index:]) - - return [new_class1, new_class2] - - def create_new_class(self, new_class_name, methods): - """ - Create a new class definition with the specified methods. - - :param new_class_name: Name of the new class. - :param methods: List of methods to include in the new class. - :return: A new class definition node. - """ - # Create the class definition with methods - class_def = ast.ClassDef( - name=new_class_name, - bases=[], - body=methods, - decorator_list=[] - ) - return class_def - - def ast_to_code(self, nodes): - """ - Convert AST nodes back to source code. - - :param nodes: The AST nodes to convert. - :return: The source code as a string. - """ - import astor - return astor.to_source(nodes) diff --git a/src/refactorer/long_base_class_list.py b/src/refactorer/long_base_class_list.py deleted file mode 100644 index fdd15297..00000000 --- a/src/refactorer/long_base_class_list.py +++ /dev/null @@ -1,14 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongBaseClassListRefactorer(BaseRefactorer): - """ - Refactorer that targets long base class lists to improve performance. - """ - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src/refactorer/long_element_chain.py b/src/refactorer/long_element_chain.py deleted file mode 100644 index 6c168afa..00000000 --- a/src/refactorer/long_element_chain.py +++ /dev/null @@ -1,21 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongElementChainRefactorer(BaseRefactorer): - """ - Refactorer for data objects (dictionary) that have too many deeply nested elements inside. - Ex: deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] - """ - - def __init__(self, code: str, element_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of nested elements allowed before dictionary has too many deeply nested elements. - """ - super().__init__(code) - self.element_threshold = element_threshold - - def refactor(self): - - return self.code \ No newline at end of file diff --git a/src/refactorer/long_lambda_function_refactorer.py b/src/refactorer/long_lambda_function_refactorer.py deleted file mode 100644 index 421ada60..00000000 --- a/src/refactorer/long_lambda_function_refactorer.py +++ /dev/null @@ -1,16 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongLambdaFunctionRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src/refactorer/long_message_chain_refactorer.py b/src/refactorer/long_message_chain_refactorer.py deleted file mode 100644 index 2438910f..00000000 --- a/src/refactorer/long_message_chain_refactorer.py +++ /dev/null @@ -1,17 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongMessageChainRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src/refactorer/long_method_refactorer.py b/src/refactorer/long_method_refactorer.py deleted file mode 100644 index 734afa67..00000000 --- a/src/refactorer/long_method_refactorer.py +++ /dev/null @@ -1,18 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongMethodRefactorer(BaseRefactorer): - """ - Refactorer that targets long methods to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - - def refactor(self): - """ - Refactor long methods into smaller methods. - Implement the logic to detect and refactor long methods. - """ - # Logic to identify long methods goes here - pass diff --git a/src/refactorer/long_scope_chaining.py b/src/refactorer/long_scope_chaining.py deleted file mode 100644 index 39e53316..00000000 --- a/src/refactorer/long_scope_chaining.py +++ /dev/null @@ -1,24 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LongScopeRefactorer(BaseRefactorer): - """ - Refactorer for methods that have too many deeply nested loops. - """ - def __init__(self, code: str, loop_threshold: int = 5): - """ - Initializes the refactorer. - - :param code: The source code of the class to refactor. - :param method_threshold: The number of loops allowed before method is considered one with too many nested loops. - """ - super().__init__(code) - self.loop_threshold = loop_threshold - - def refactor(self): - """ - Refactor code by ... - - Return: refactored code - """ - - return self.code \ No newline at end of file diff --git a/src/refactorer/long_ternary_cond_expression.py b/src/refactorer/long_ternary_cond_expression.py deleted file mode 100644 index 994ccfc3..00000000 --- a/src/refactorer/long_ternary_cond_expression.py +++ /dev/null @@ -1,17 +0,0 @@ -from .base_refactorer import BaseRefactorer - -class LTCERefactorer(BaseRefactorer): - """ - Refactorer that targets long ternary conditional expressions (LTCEs) to improve readability. - """ - - def __init__(self, code): - super().__init__(code) - - def refactor(self): - """ - Refactor LTCEs into smaller methods. - Implement the logic to detect and refactor LTCEs. - """ - # Logic to identify LTCEs goes here - pass diff --git a/src/testing/__init__.py b/src/testing/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/testing/test_runner.py b/src/testing/test_runner.py deleted file mode 100644 index 84fe92a9..00000000 --- a/src/testing/test_runner.py +++ /dev/null @@ -1,17 +0,0 @@ -import unittest -import os -import sys - -# Add the src directory to the path to import modules -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src'))) - -# Discover and run all tests in the 'tests' directory -def run_tests(): - test_loader = unittest.TestLoader() - test_suite = test_loader.discover('tests', pattern='*.py') - - test_runner = unittest.TextTestRunner(verbosity=2) - test_runner.run(test_suite) - -if __name__ == '__main__': - run_tests() diff --git a/src/testing/test_validator.py b/src/testing/test_validator.py deleted file mode 100644 index cbbb29d4..00000000 --- a/src/testing/test_validator.py +++ /dev/null @@ -1,3 +0,0 @@ -def validate_output(original, refactored): - # Compare original and refactored output - return original == refactored diff --git a/src/utils/__init__.py b/src/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src/utils/ast_parser.py b/src/utils/ast_parser.py deleted file mode 100644 index 6a7f6fd8..00000000 --- a/src/utils/ast_parser.py +++ /dev/null @@ -1,17 +0,0 @@ -import ast - -def parse_line(file: str, line: int): - with open(file, "r") as f: - file_lines = f.readlines() - try: - node = ast.parse(file_lines[line - 1].strip()) - except(SyntaxError) as e: - return None - - return node - -def parse_file(file: str): - with open(file, "r") as f: - source = f.read() - - return ast.parse(source) \ No newline at end of file diff --git a/src/utils/code_smells.py b/src/utils/code_smells.py deleted file mode 100644 index 0a9391bd..00000000 --- a/src/utils/code_smells.py +++ /dev/null @@ -1,22 +0,0 @@ -from enum import Enum - -class ExtendedEnum(Enum): - - @classmethod - def list(cls) -> list[str]: - return [c.value for c in cls] - -class CodeSmells(ExtendedEnum): - # Add codes here - LINE_TOO_LONG = "C0301" - LONG_MESSAGE_CHAIN = "R0914" - LONG_LAMBDA_FUNC = "R0914" - LONG_TERN_EXPR = "CUST-1" - # "R0902": LargeClassRefactorer, # Too many instance attributes - # "R0913": "Long Parameter List", # Too many arguments - # "R0915": "Long Method", # Too many statements - # "C0200": "Complex List Comprehension", # Loop can be simplified - # "C0103": "Invalid Naming Convention", # Non-standard names - - def __str__(self): - return str(self.value) diff --git a/src/utils/factory.py b/src/utils/factory.py deleted file mode 100644 index a60628b4..00000000 --- a/src/utils/factory.py +++ /dev/null @@ -1,23 +0,0 @@ -from refactorer.long_lambda_function_refactorer import LongLambdaFunctionRefactorer as LLFR -from refactorer.long_message_chain_refactorer import LongMessageChainRefactorer as LMCR -from refactorer.long_ternary_cond_expression import LTCERefactorer as LTCER - -from refactorer.base_refactorer import BaseRefactorer - -from utils.code_smells import CodeSmells - -class RefactorerFactory(): - - @staticmethod - def build(smell_name: str, file_path: str) -> BaseRefactorer: - selected = None - match smell_name: - case CodeSmells.LONG_LAMBDA_FUNC: - selected = LLFR(file_path) - case CodeSmells.LONG_MESSAGE_CHAIN: - selected = LMCR(file_path) - case CodeSmells.LONG_TERN_EXPR: - selected = LTCER(file_path) - case _: - raise ValueError(smell_name) - return selected \ No newline at end of file diff --git a/src/utils/logger.py b/src/utils/logger.py deleted file mode 100644 index 711c62b5..00000000 --- a/src/utils/logger.py +++ /dev/null @@ -1,34 +0,0 @@ -import logging -import os - -def setup_logger(log_file: str = "app.log", log_level: int = logging.INFO): - """ - Set up the logger configuration. - - Args: - log_file (str): The name of the log file to write logs to. - log_level (int): The logging level (default is INFO). - - Returns: - Logger: Configured logger instance. - """ - # Create log directory if it does not exist - log_directory = os.path.dirname(log_file) - if log_directory and not os.path.exists(log_directory): - os.makedirs(log_directory) - - # Configure the logger - logging.basicConfig( - filename=log_file, - filemode='a', # Append mode - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=log_level, - ) - - logger = logging.getLogger(__name__) - return logger - -# # Example usage -# if __name__ == "__main__": -# logger = setup_logger() # You can customize the log file and level here -# logger.info("Logger is set up and ready to use.") From b759d4e0d382c285f662a021ebb9d15b74b2e5af Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sat, 9 Nov 2024 13:25:48 -0800 Subject: [PATCH 053/105] added refactoring class for unused imports --- src1/refactorers/unused_imports_refactor.py | 62 +++++++++++++++++++++ src1/utils/analyzers_config.py | 21 ++++++- src1/utils/refactorer_factory.py | 4 ++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src1/refactorers/unused_imports_refactor.py diff --git a/src1/refactorers/unused_imports_refactor.py b/src1/refactorers/unused_imports_refactor.py new file mode 100644 index 00000000..5d85ab8b --- /dev/null +++ b/src1/refactorers/unused_imports_refactor.py @@ -0,0 +1,62 @@ +import os +import shutil +from refactorers.base_refactorer import BaseRefactorer + +class RemoveUnusedImportsRefactor(BaseRefactorer): + def __init__(self, logger): + """ + Initializes the RemoveUnusedImportsRefactor with the specified logger. + + :param logger: Logger instance to handle log messages. + """ + super().__init__(logger) + + def refactor(self, file_path, pylint_smell, initial_emission): + """ + Refactors unused imports by removing lines where they appear. + Modifies the specified instance in the file if it results in lower emissions. + + :param file_path: Path to the file to be refactored. + :param pylint_smell: Dictionary containing details of the Pylint smell, including the line number. + :param initial_emission: Initial emission value before refactoring. + """ + self.initial_emission = initial_emission + line_number = pylint_smell.get("line") + self.logger.log( + f"Applying 'Remove Unused Imports' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." + ) + + # Load the source code as a list of lines + with open(file_path, "r") as file: + original_lines = file.readlines() + + # Check if the line number is valid within the file + if not (1 <= line_number <= len(original_lines)): + self.logger.log("Specified line number is out of bounds.\n") + return + + # Remove the specified line if it's an unused import + modified_lines = original_lines[:] + del modified_lines[line_number - 1] + + # Write the modified content to a temporary file + temp_file_path = f"{file_path}.temp" + with open(temp_file_path, "w") as temp_file: + temp_file.writelines(modified_lines) + + # Measure emissions of the modified code + self.measure_energy(temp_file_path) + + # Check for improvement in emissions + if self.check_energy_improvement(): + # Replace the original file with the modified content if improved + shutil.move(temp_file_path, file_path) + self.logger.log( + f"Removed unused import on line {line_number} and saved changes.\n" + ) + else: + # Remove the temporary file if no improvement + os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) \ No newline at end of file diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 89207f9c..c5c90ea2 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -26,7 +26,26 @@ class PylintSmell(ExtendedEnum): INVALID_NAMING_CONVENTIONS = ( "C0103" # Pylint code smell for naming conventions violations ) - USE_A_GENERATOR = "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` + + # unused stuff + UNUSED_IMPORT = ( + "W0611" # Pylint code smell for unused imports + ) + UNUSED_VARIABLE = ( + "W0612" # Pylint code smell for unused variable + ) + UNUSED_ARGUMENT = ( + "W0613" # Pylint code smell for unused function or method argument + ) + UNUSED_CLASS_ATTRIBUTE = ( + "W0615" # Pylint code smell for unused class attribute + ) + + + USE_A_GENERATOR = ( + "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` + ) + # Enum class for custom code smells not detected by Pylint diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index f8883b82..b77c5cfa 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -1,5 +1,6 @@ # Import specific refactorer classes from refactorers.use_a_generator_refactor import UseAGeneratorRefactor +from refactorers.unused_imports_refactor import RemoveUnusedImportsRefactor from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells @@ -32,6 +33,9 @@ def build_refactorer_class(file_path, smell_messageId, smell_data, initial_emiss match smell_messageId: case AllSmells.USE_A_GENERATOR.value: selected = UseAGeneratorRefactor(file_path, smell_data, initial_emission, logger) + case AllSmells.UNUSED_IMPORT.value: + x = RemoveUnusedImportsRefactor(logger) + selected = x.refactor(file_path, smell_data, initial_emission) case _: selected = None From 13c87d806be63a3a48c9d9c2d503c3f97daaad33 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sat, 9 Nov 2024 13:26:13 -0800 Subject: [PATCH 054/105] Added to test case for unused imports --- src1/main.py | 3 +-- tests/input/ineffcient_code_example_2.py | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src1/main.py b/src1/main.py index 0267ff5e..460a826b 100644 --- a/src1/main.py +++ b/src1/main.py @@ -70,7 +70,7 @@ def main(): logger.log( "#####################################################################################################\n\n" ) - return + # Log start of refactoring codes logger.log( "#####################################################################################################" @@ -90,7 +90,6 @@ def main(): refactoring_class = RefactorerFactory.build_refactorer_class( TEST_FILE_COPY, pylint_smell["message-id"], pylint_smell, emission, logger ) - if refactoring_class: refactoring_class.refactor() emission = refactoring_class.final_emission diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index afc6a6bd..48e1887e 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,3 +1,6 @@ +import datetime # Unused import +import collections # Unused import + # LC: Large Class with too many responsibilities class DataProcessor: def __init__(self, data): From 6352bbeddfcf31f5ddbb3c15386f1b844c948147 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sat, 9 Nov 2024 13:26:29 -0800 Subject: [PATCH 055/105] fixed silly things --- src1/README.md | 5 +++++ src1/__init__.py | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 src1/README.md create mode 100644 src1/__init__.py diff --git a/src1/README.md b/src1/README.md new file mode 100644 index 00000000..50aa3a2c --- /dev/null +++ b/src1/README.md @@ -0,0 +1,5 @@ +# Project Name Source Code + +The folders and files for this project are as follows: + +... diff --git a/src1/__init__.py b/src1/__init__.py new file mode 100644 index 00000000..56f09c20 --- /dev/null +++ b/src1/__init__.py @@ -0,0 +1,5 @@ +from . import analyzers +from . import measurement +from . import refactorer +from . import testing +from . import utils \ No newline at end of file From db87805678daf35633bcb8f17a6ecd1d35cc11b2 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sat, 9 Nov 2024 13:26:49 -0800 Subject: [PATCH 056/105] update on output files from last run --- .../outputs/all_configured_pylint_smells.json | 88 ++++++++++++++- src1/outputs/final_emissions_data.txt | 34 +++--- src1/outputs/initial_emissions_data.txt | 44 ++++---- src1/outputs/log.txt | 79 ++++++++++---- src1/outputs/refactored-test-case.py | 100 +++++++++++++----- 5 files changed, 256 insertions(+), 89 deletions(-) diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index 5896a92f..e65a067b 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -2,8 +2,8 @@ { "column": 4, "endColumn": 27, - "endLine": 32, - "line": 32, + "endLine": 35, + "line": 35, "message": "Too many arguments (9/5)", "message-id": "R0913", "module": "ineffcient_code_example_2", @@ -13,17 +13,95 @@ "type": "refactor" }, { - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "column": 20, + "endColumn": 25, + "endLine": 36, + "line": 36, + "message": "Unused argument 'flag1'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 27, + "endColumn": 32, + "endLine": 36, + "line": 36, + "message": "Unused argument 'flag2'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 67, + "endColumn": 73, + "endLine": 36, + "line": 36, + "message": "Unused argument 'option'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 75, + "endColumn": 86, + "endLine": 36, + "line": 36, + "message": "Unused argument 'final_stage'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 0, + "endColumn": 15, + "endLine": 1, + "line": 1, + "message": "Unused import datetime", + "message-id": "W0611", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-import", + "type": "warning" + }, + { + "column": 0, + "endColumn": 18, + "endLine": 2, + "line": 2, + "message": "Unused import collections", + "message-id": "W0611", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "unused-import", + "type": "warning" + }, + { + "absolutePath": "/Users/ayushiamin/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 22, + "line": 25, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "/Users/ayushiamin/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" } diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index 9bded5cd..1d463887 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,30 +5,30 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 2.0728687498679695e-07, - "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", - "cpu_power": 7.5, - "duration": 0.1009901000652462, - "emissions": 1.3743098537414196e-08, - "emissions_rate": 1.360836213503626e-07, - "energy_consumed": 3.4795780604896405e-07, + "cpu_energy": 3.509270216252643e-07, + "cpu_model": "Apple M2", + "cpu_power": 42.5, + "duration": 0.0297950000094715, + "emissions": 5.219136414312479e-09, + "emissions_rate": 1.751681964307221e-07, + "energy_consumed": 3.755023691377978e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 43.266, - "longitude": -79.9441, + "latitude": 49.2643, + "longitude": -123.0961, "on_cloud": "N", - "os": "Windows-11-10.0.22631-SP0", + "os": "macOS-15.1-arm64-arm-64bit", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 1.406709310621671e-07, - "ram_power": 6.730809688568115, - "ram_total_size": 17.94882583618164, - "region": "ontario", - "run_id": "ffcd8517-0fe8-4782-a20d-8a5bbfd16104", - "timestamp": "2024-11-09T00:02:07", + "python_version": "3.10.0", + "ram_energy": 2.4575347512533576e-08, + "ram_power": 3.0, + "ram_total_size": 8.0, + "region": "british columbia", + "run_id": "56473086-896e-40aa-aa7c-2b639ddc2b82", + "timestamp": "2024-11-09T13:21:52", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index f166360a..66741fb0 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 16, - "cpu_energy": NaN, - "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "cpu_power": NaN, - "duration": 4.997579105984187, - "emissions": NaN, - "emissions_rate": NaN, - "energy_consumed": NaN, + "cpu_count": 8, + "cpu_energy": 5.591056923650387e-07, + "cpu_model": "Apple M2", + "cpu_power": 42.5, + "duration": 0.0474608749791514, + "emissions": 8.316502191347154e-09, + "emissions_rate": 1.752285897594687e-07, + "energy_consumed": 5.98349234027814e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": 1, - "gpu_energy": NaN, - "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "gpu_power": NaN, - "latitude": 43.266, - "longitude": -79.9441, + "gpu_count": NaN, + "gpu_energy": 0, + "gpu_model": NaN, + "gpu_power": 0.0, + "latitude": 49.2643, + "longitude": -123.0961, "on_cloud": "N", - "os": "macOS-14.4-x86_64-i386-64bit", + "os": "macOS-15.1-arm64-arm-64bit", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.10.10", - "ram_energy": 8.645874331705273e-08, - "ram_power": 6.0, - "ram_total_size": 16.0, - "region": "ontario", - "run_id": "26c0c12d-ea46-46ff-91b4-fe00b698fe37", - "timestamp": "2024-11-09T02:01:36", + "python_version": "3.10.0", + "ram_energy": 3.9243541662775296e-08, + "ram_power": 3.0, + "ram_total_size": 8.0, + "region": "british columbia", + "run_id": "0d17f604-8228-4a76-ab63-8886440337ec", + "timestamp": "2024-11-09T13:21:17", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index c1464c8a..0ae96321 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,22 +1,61 @@ -[2024-11-09 02:01:18] ##################################################################################################### -[2024-11-09 02:01:18] CAPTURE INITIAL EMISSIONS -[2024-11-09 02:01:18] ##################################################################################################### -[2024-11-09 02:01:18] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 02:01:31] CodeCarbon measurement completed successfully. -[2024-11-09 02:01:36] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-09 02:01:36] Initial Emissions: nan kg CO2 -[2024-11-09 02:01:36] ##################################################################################################### - - -[2024-11-09 02:01:36] ##################################################################################################### -[2024-11-09 02:01:36] CAPTURE CODE SMELLS -[2024-11-09 02:01:36] ##################################################################################################### -[2024-11-09 02:01:36] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-09 02:01:36] Pylint analyzer completed successfully. -[2024-11-09 02:01:36] Running custom parsers: -[2024-11-09 02:01:36] Filtering pylint smells -[2024-11-09 02:01:36] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-09 02:01:36] Refactorable code smells: 2 -[2024-11-09 02:01:36] ##################################################################################################### +[2024-11-09 13:21:13] ##################################################################################################### +[2024-11-09 13:21:13] CAPTURE INITIAL EMISSIONS +[2024-11-09 13:21:13] ##################################################################################################### +[2024-11-09 13:21:13] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 13:21:17] CodeCarbon measurement completed successfully. +[2024-11-09 13:21:17] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-09 13:21:17] Initial Emissions: 8.316502191347154e-09 kg CO2 +[2024-11-09 13:21:17] ##################################################################################################### +[2024-11-09 13:21:17] ##################################################################################################### +[2024-11-09 13:21:17] CAPTURE CODE SMELLS +[2024-11-09 13:21:17] ##################################################################################################### +[2024-11-09 13:21:17] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-09 13:21:17] Pylint analyzer completed successfully. +[2024-11-09 13:21:17] Running custom parsers: +[2024-11-09 13:21:17] Filtering pylint smells +[2024-11-09 13:21:17] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-09 13:21:17] Refactorable code smells: 8 +[2024-11-09 13:21:17] ##################################################################################################### + + +[2024-11-09 13:21:17] ##################################################################################################### +[2024-11-09 13:21:17] REFACTOR CODE SMELLS +[2024-11-09 13:21:17] ##################################################################################################### +[2024-11-09 13:21:17] Refactoring for smell too-many-arguments is not implemented. +[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. +[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. +[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. +[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. +[2024-11-09 13:21:17] Applying 'Remove Unused Imports' refactor on 'refactored-test-case.py' at line 1 for identified code smell. +[2024-11-09 13:21:17] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 13:21:48] CodeCarbon measurement completed successfully. +[2024-11-09 13:21:48] Measured emissions for 'refactored-test-case.py.temp': 7.848909375104974e-09 +[2024-11-09 13:21:48] Initial Emissions: 8.316502191347154e-09 kg CO2. Final Emissions: 7.848909375104974e-09 kg CO2. +[2024-11-09 13:21:48] Removed unused import on line 1 and saved changes. + +[2024-11-09 13:21:48] Refactoring for smell unused-import is not implemented. +[2024-11-09 13:21:48] Applying 'Remove Unused Imports' refactor on 'refactored-test-case.py' at line 2 for identified code smell. +[2024-11-09 13:21:48] Starting CodeCarbon energy measurement on refactored-test-case.py.temp +[2024-11-09 13:21:50] CodeCarbon measurement completed successfully. +[2024-11-09 13:21:50] Measured emissions for 'refactored-test-case.py.temp': 5.414795864199966e-09 +[2024-11-09 13:21:50] Initial Emissions: 8.316502191347154e-09 kg CO2. Final Emissions: 5.414795864199966e-09 kg CO2. +[2024-11-09 13:21:50] Removed unused import on line 2 and saved changes. + +[2024-11-09 13:21:50] Refactoring for smell unused-import is not implemented. +[2024-11-09 13:21:50] Refactoring for smell long-message-chain is not implemented. +[2024-11-09 13:21:50] ##################################################################################################### + + +[2024-11-09 13:21:50] ##################################################################################################### +[2024-11-09 13:21:50] CAPTURE FINAL EMISSIONS +[2024-11-09 13:21:50] ##################################################################################################### +[2024-11-09 13:21:50] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 13:21:52] CodeCarbon measurement completed successfully. +[2024-11-09 13:21:52] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt +[2024-11-09 13:21:52] Final Emissions: 5.219136414312479e-09 kg CO2 +[2024-11-09 13:21:52] ##################################################################################################### + + +[2024-11-09 13:21:52] Saved 3.097365777034675e-09 kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index 3e73abfd..9808777f 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,33 +1,83 @@ -# Should trigger Use A Generator code smells +import collections # Unused import +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] -def has_positive(numbers): - # List comprehension inside `any()` - triggers R1729 - return any([num > 0 for num in numbers]) + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except Exception as e: # UEH: Unqualified Exception Handling + print("An error occurred:", e) -def all_non_negative(numbers): - # List comprehension inside `all()` - triggers R1729 - return all(num >= 0 for num in numbers) + # LMC: Long Message Chain + if isinstance(self.data[0], str): + print(self.data[0].upper().strip().replace(" ", "_").lower()) -def contains_large_strings(strings): - # List comprehension inside `any()` - triggers R1729 - return any([len(s) > 10 for s in strings]) + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) + ) -def all_uppercase(strings): - # List comprehension inside `all()` - triggers R1729 - return all(s.isupper() for s in strings) + return self.processed_data -def contains_special_numbers(numbers): - # List comprehension inside `any()` - triggers R1729 - return any([num % 5 == 0 and num > 100 for num in numbers]) + # Moved the complex_calculation method here + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result -def all_lowercase(strings): - # List comprehension inside `all()` - triggers R1729 - return all([s.islower() for s in strings]) -def any_even_numbers(numbers): - # List comprehension inside `any()` - triggers R1729 - return any(num % 2 == 0 for num in numbers) +class AdvancedProcessor(DataProcessor): + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return True if item > 10 else False if item < -10 else None if item == 0 else item -def all_strings_start_with_a(strings): - # List comprehension inside `all()` - triggers R1729 - return all(s.startswith('A') for s in strings) + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except (KeyError, IndexError, TypeError): + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) From 5817ce5b473d6f17be04fd16e42603149ff26b42 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 9 Nov 2024 19:07:31 -0500 Subject: [PATCH 057/105] fixed refactorer --- __init__.py | 0 src1/analyzers/pylint_analyzer.py | 11 +- src1/main.py | 30 +- .../outputs/all_configured_pylint_smells.json | 70 ++- src1/outputs/all_pylint_smells.json | 498 ++++++++++++++++++ src1/outputs/final_emissions_data.txt | 34 +- src1/outputs/initial_emissions_data.txt | 34 +- src1/outputs/log.txt | 122 ++--- src1/outputs/refactored-test-case.py | 2 + src1/refactorers/base_refactorer.py | 16 +- .../long_lambda_function_refactorer.py | 2 +- .../long_message_chain_refactorer.py | 2 +- src1/refactorers/unused_imports_refactor.py | 7 +- src1/refactorers/use_a_generator_refactor.py | 18 +- src1/utils/analyzers_config.py | 2 + src1/utils/outputs_config.py | 6 +- src1/utils/refactorer_factory.py | 13 +- tests/input/ineffcient_code_example_2.py | 1 - 18 files changed, 713 insertions(+), 155 deletions(-) delete mode 100644 __init__.py create mode 100644 src1/outputs/all_pylint_smells.json diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index 0a429871..03056eb1 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -4,6 +4,7 @@ from pylint.lint import Run from pylint.reporters.json_reporter import JSONReporter + from io import StringIO from utils.logger import Logger @@ -83,15 +84,12 @@ def configure_smells(self): elif smell["message-id"] in CustomSmell.list(): configured_smells.append(smell) - if smell == IntermediateSmells.LINE_TOO_LONG.value: + if smell["message-id"] == IntermediateSmells.LINE_TOO_LONG.value: self.filter_ternary(smell) self.smells_data = configured_smells def filter_for_one_code_smell(self, pylint_results: list[object], code: str): - """ - Filters LINE_TOO_LONG smells to find ternary expression smells - """ filtered_results: list[object] = [] for error in pylint_results: if error["message-id"] == code: @@ -100,6 +98,9 @@ def filter_for_one_code_smell(self, pylint_results: list[object], code: str): return filtered_results def filter_ternary(self, smell: object): + """ + Filters LINE_TOO_LONG smells to find ternary expression smells + """ root_node = parse_line(self.file_path, smell["line"]) if root_node is None: @@ -108,6 +109,7 @@ def filter_ternary(self, smell: object): for node in ast.walk(root_node): if isinstance(node, ast.IfExp): # Ternary expression node smell["message-id"] = CustomSmell.LONG_TERN_EXPR.value + smell["message"] = "Ternary expression has too many branches" self.smells_data.append(smell) break @@ -180,6 +182,7 @@ def check_chain(node, chain_length=0): return results + @staticmethod def read_code_from_path(file_path): """ Reads the Python code from a given file path. diff --git a/src1/main.py b/src1/main.py index 460a826b..b4269405 100644 --- a/src1/main.py +++ b/src1/main.py @@ -33,15 +33,15 @@ def main(): # Measure energy with CodeCarbonEnergyMeter codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) - codecarbon_energy_meter.measure_energy() # Measure emissions - initial_emission = codecarbon_energy_meter.emissions # Get initial emission - initial_emission_data = ( + codecarbon_energy_meter.measure_energy() + initial_emissions = codecarbon_energy_meter.emissions # Get initial emission + initial_emissions_data = ( codecarbon_energy_meter.emissions_data ) # Get initial emission data # Save initial emission data - save_json_files("initial_emissions_data.txt", initial_emission_data, logger) - logger.log(f"Initial Emissions: {initial_emission} kg CO2") + save_json_files("initial_emissions_data.txt", initial_emissions_data, logger) + logger.log(f"Initial Emissions: {initial_emissions} kg CO2") logger.log( "#####################################################################################################\n\n" ) @@ -60,6 +60,12 @@ def main(): # Anaylze code smells with PylintAnalyzer pylint_analyzer = PylintAnalyzer(TEST_FILE, logger) pylint_analyzer.analyze() # analyze all smells + + # Save code smells + save_json_files( + "all_pylint_smells.json", pylint_analyzer.smells_data, logger + ) + pylint_analyzer.configure_smells() # get all configured smells # Save code smells @@ -83,16 +89,12 @@ def main(): ) # Refactor code smells - TEST_FILE_COPY = copy_file_to_output(TEST_FILE, "refactored-test-case.py") - emission = initial_emission + copy_file_to_output(TEST_FILE, "refactored-test-case.py") for pylint_smell in pylint_analyzer.smells_data: - refactoring_class = RefactorerFactory.build_refactorer_class( - TEST_FILE_COPY, pylint_smell["message-id"], pylint_smell, emission, logger - ) + refactoring_class = RefactorerFactory.build_refactorer_class(pylint_smell["message-id"],logger) if refactoring_class: - refactoring_class.refactor() - emission = refactoring_class.final_emission + refactoring_class.refactor(TEST_FILE, pylint_smell, initial_emissions) else: logger.log( f"Refactoring for smell {pylint_smell['symbol']} is not implemented." @@ -128,12 +130,12 @@ def main(): ) # The emissions from codecarbon are so inconsistent that this could be a possibility :( - if final_emission >= initial_emission: + if final_emission >= initial_emissions: logger.log( "Final emissions are greater than initial emissions; we are going to fail" ) else: - logger.log(f"Saved {initial_emission - final_emission} kg CO2") + logger.log(f"Saved {initial_emissions - final_emission} kg CO2") if __name__ == "__main__": diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index e65a067b..f60252cf 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -8,7 +8,7 @@ "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, @@ -21,7 +21,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, @@ -34,7 +34,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, @@ -47,7 +47,7 @@ "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, @@ -60,10 +60,49 @@ "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, + { + "column": 4, + "endColumn": 27, + "endLine": 35, + "line": 35, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 49, + "line": 49, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.check_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 70, + "line": 70, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, { "column": 0, "endColumn": 15, @@ -73,7 +112,7 @@ "message-id": "W0611", "module": "ineffcient_code_example_2", "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-import", "type": "warning" }, @@ -86,12 +125,12 @@ "message-id": "W0611", "module": "ineffcient_code_example_2", "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "unused-import", "type": "warning" }, { - "absolutePath": "/Users/ayushiamin/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, @@ -101,8 +140,21 @@ "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "/Users/ayushiamin/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 50, + "message": "Ternary expression has too many branches", + "message-id": "CUST-1", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" } ] \ No newline at end of file diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json new file mode 100644 index 00000000..1e08ea2e --- /dev/null +++ b/src1/outputs/all_pylint_smells.json @@ -0,0 +1,498 @@ +[ + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 29, + "message": "Line too long (83/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 36, + "message": "Line too long (86/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 50, + "message": "Line too long (90/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 64, + "message": "Line too long (85/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" + }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 1, + "message": "Missing module docstring", + "message-id": "C0114", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-module-docstring", + "type": "convention" + }, + { + "column": 0, + "endColumn": 19, + "endLine": 5, + "line": 5, + "message": "Missing class docstring", + "message-id": "C0115", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 24, + "endLine": 11, + "line": 11, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 19, + "endColumn": 28, + "endLine": 20, + "line": 20, + "message": "Catching too general exception Exception", + "message-id": "W0718", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "broad-exception-caught", + "type": "warning" + }, + { + "column": 12, + "endColumn": 46, + "endLine": 21, + "line": 14, + "message": "try clause contains 2 statements, expected at most 1", + "message-id": "W0717", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-try-statements", + "type": "warning" + }, + { + "column": 12, + "endColumn": 83, + "endLine": 29, + "line": 29, + "message": "Used builtin function 'filter'. Using a list comprehension can be clearer.", + "message-id": "W0141", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.process_all_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "bad-builtin", + "type": "warning" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 35, + "line": 35, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 35, + "line": 35, + "message": "Too many arguments (9/5)", + "message-id": "R0913", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 35, + "line": 35, + "message": "Too many positional arguments (9/5)", + "message-id": "R0917", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-positional-arguments", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 34, + "endLine": 38, + "line": 38, + "message": "Consider using a named constant or an enum instead of ''multiply''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 13, + "endColumn": 31, + "endLine": 40, + "line": 40, + "message": "Consider using a named constant or an enum instead of ''add''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 20, + "endColumn": 25, + "endLine": 36, + "line": 36, + "message": "Unused argument 'flag1'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 27, + "endColumn": 32, + "endLine": 36, + "line": 36, + "message": "Unused argument 'flag2'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 67, + "endColumn": 73, + "endLine": 36, + "line": 36, + "message": "Unused argument 'option'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 75, + "endColumn": 86, + "endLine": 36, + "line": 36, + "message": "Unused argument 'final_stage'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 35, + "line": 35, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.complex_calculation", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, + { + "column": 0, + "endColumn": 23, + "endLine": 47, + "line": 47, + "message": "Missing class docstring", + "message-id": "C0115", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-class-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 49, + "line": 49, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.check_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 23, + "endColumn": 32, + "endLine": 50, + "line": 50, + "message": "Consider using a named constant or an enum instead of '10'.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.check_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 49, + "line": 49, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.check_data", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 29, + "endLine": 53, + "line": 53, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.complex_comprehension", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 30, + "endColumn": 37, + "endLine": 58, + "line": 58, + "message": "Consider using a named constant or an enum instead of '50'.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.complex_comprehension", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 42, + "endColumn": 47, + "endLine": 58, + "line": 58, + "message": "Consider using a named constant or an enum instead of '3'.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.complex_comprehension", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 18, + "endLine": 62, + "line": 62, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_chain", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 8, + "endColumn": 23, + "endLine": 67, + "line": 63, + "message": "try clause contains 2 statements, expected at most 1", + "message-id": "W0717", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_chain", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-try-statements", + "type": "warning" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 70, + "line": 70, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 31, + "endColumn": 53, + "endLine": 76, + "line": 76, + "message": "Consider using a named constant or an enum instead of '25'.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 70, + "line": 70, + "message": "Too many branches (6/3)", + "message-id": "R0912", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-branches", + "type": "refactor" + }, + { + "column": 8, + "endColumn": 45, + "endLine": 77, + "line": 71, + "message": "Too many nested blocks (6/3)", + "message-id": "R1702", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "too-many-nested-blocks", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 70, + "line": 70, + "message": "Either all return statements in a function should return an expression, or none of them should.", + "message-id": "R1710", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "inconsistent-return-statements", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 27, + "endLine": 70, + "line": 70, + "message": "Method could be a function", + "message-id": "R6301", + "module": "ineffcient_code_example_2", + "obj": "AdvancedProcessor.long_scope_chaining", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "no-self-use", + "type": "refactor" + }, + { + "column": 0, + "endColumn": 15, + "endLine": 1, + "line": 1, + "message": "Unused import datetime", + "message-id": "W0611", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-import", + "type": "warning" + }, + { + "column": 0, + "endColumn": 18, + "endLine": 2, + "line": 2, + "message": "Unused import collections", + "message-id": "W0611", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "unused-import", + "type": "warning" + }, + { + "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "column": 18, + "confidence": "UNDEFINED", + "endColumn": null, + "endLine": null, + "line": 25, + "message": "Method chain too long (3/3)", + "message-id": "LMC001", + "module": "ineffcient_code_example_2.py", + "obj": "", + "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "symbol": "long-message-chain", + "type": "convention" + } +] \ No newline at end of file diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index 1d463887..2e2cf540 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,30 +5,30 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 3.509270216252643e-07, - "cpu_model": "Apple M2", - "cpu_power": 42.5, - "duration": 0.0297950000094715, - "emissions": 5.219136414312479e-09, - "emissions_rate": 1.751681964307221e-07, - "energy_consumed": 3.755023691377978e-07, + "cpu_energy": 1.8817833333741875e-07, + "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", + "cpu_power": 7.5, + "duration": 0.0912796999327838, + "emissions": 1.1923300735073934e-08, + "emissions_rate": 1.3062379416073854e-07, + "energy_consumed": 3.018828361991019e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 49.2643, - "longitude": -123.0961, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "macOS-15.1-arm64-arm-64bit", + "os": "Windows-11-10.0.22631-SP0", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.10.0", - "ram_energy": 2.4575347512533576e-08, - "ram_power": 3.0, - "ram_total_size": 8.0, - "region": "british columbia", - "run_id": "56473086-896e-40aa-aa7c-2b639ddc2b82", - "timestamp": "2024-11-09T13:21:52", + "python_version": "3.13.0", + "ram_energy": 1.1370450286168313e-07, + "ram_power": 6.730809688568115, + "ram_total_size": 17.94882583618164, + "region": "ontario", + "run_id": "2089b6e1-c373-4b66-87fa-1899c88dee17", + "timestamp": "2024-11-09T19:05:41", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index 66741fb0..ce512e82 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -5,30 +5,30 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 5.591056923650387e-07, - "cpu_model": "Apple M2", - "cpu_power": 42.5, - "duration": 0.0474608749791514, - "emissions": 8.316502191347154e-09, - "emissions_rate": 1.752285897594687e-07, - "energy_consumed": 5.98349234027814e-07, + "cpu_energy": 2.313262501653905e-07, + "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", + "cpu_power": 7.5, + "duration": 0.111857800045982, + "emissions": 1.5186652718459153e-08, + "emissions_rate": 1.3576748972549338e-07, + "energy_consumed": 3.845067651051595e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 49.2643, - "longitude": -123.0961, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "macOS-15.1-arm64-arm-64bit", + "os": "Windows-11-10.0.22631-SP0", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.10.0", - "ram_energy": 3.9243541662775296e-08, - "ram_power": 3.0, - "ram_total_size": 8.0, - "region": "british columbia", - "run_id": "0d17f604-8228-4a76-ab63-8886440337ec", - "timestamp": "2024-11-09T13:21:17", + "python_version": "3.13.0", + "ram_energy": 1.5318051493976906e-07, + "ram_power": 6.730809688568115, + "ram_total_size": 17.94882583618164, + "region": "ontario", + "run_id": "1f0dc5c1-ae3f-42d9-b4e3-100bec900593", + "timestamp": "2024-11-09T19:05:23", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 0ae96321..04246ff7 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,61 +1,61 @@ -[2024-11-09 13:21:13] ##################################################################################################### -[2024-11-09 13:21:13] CAPTURE INITIAL EMISSIONS -[2024-11-09 13:21:13] ##################################################################################################### -[2024-11-09 13:21:13] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 13:21:17] CodeCarbon measurement completed successfully. -[2024-11-09 13:21:17] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-09 13:21:17] Initial Emissions: 8.316502191347154e-09 kg CO2 -[2024-11-09 13:21:17] ##################################################################################################### - - -[2024-11-09 13:21:17] ##################################################################################################### -[2024-11-09 13:21:17] CAPTURE CODE SMELLS -[2024-11-09 13:21:17] ##################################################################################################### -[2024-11-09 13:21:17] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-09 13:21:17] Pylint analyzer completed successfully. -[2024-11-09 13:21:17] Running custom parsers: -[2024-11-09 13:21:17] Filtering pylint smells -[2024-11-09 13:21:17] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-09 13:21:17] Refactorable code smells: 8 -[2024-11-09 13:21:17] ##################################################################################################### - - -[2024-11-09 13:21:17] ##################################################################################################### -[2024-11-09 13:21:17] REFACTOR CODE SMELLS -[2024-11-09 13:21:17] ##################################################################################################### -[2024-11-09 13:21:17] Refactoring for smell too-many-arguments is not implemented. -[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. -[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. -[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. -[2024-11-09 13:21:17] Refactoring for smell unused-argument is not implemented. -[2024-11-09 13:21:17] Applying 'Remove Unused Imports' refactor on 'refactored-test-case.py' at line 1 for identified code smell. -[2024-11-09 13:21:17] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 13:21:48] CodeCarbon measurement completed successfully. -[2024-11-09 13:21:48] Measured emissions for 'refactored-test-case.py.temp': 7.848909375104974e-09 -[2024-11-09 13:21:48] Initial Emissions: 8.316502191347154e-09 kg CO2. Final Emissions: 7.848909375104974e-09 kg CO2. -[2024-11-09 13:21:48] Removed unused import on line 1 and saved changes. - -[2024-11-09 13:21:48] Refactoring for smell unused-import is not implemented. -[2024-11-09 13:21:48] Applying 'Remove Unused Imports' refactor on 'refactored-test-case.py' at line 2 for identified code smell. -[2024-11-09 13:21:48] Starting CodeCarbon energy measurement on refactored-test-case.py.temp -[2024-11-09 13:21:50] CodeCarbon measurement completed successfully. -[2024-11-09 13:21:50] Measured emissions for 'refactored-test-case.py.temp': 5.414795864199966e-09 -[2024-11-09 13:21:50] Initial Emissions: 8.316502191347154e-09 kg CO2. Final Emissions: 5.414795864199966e-09 kg CO2. -[2024-11-09 13:21:50] Removed unused import on line 2 and saved changes. - -[2024-11-09 13:21:50] Refactoring for smell unused-import is not implemented. -[2024-11-09 13:21:50] Refactoring for smell long-message-chain is not implemented. -[2024-11-09 13:21:50] ##################################################################################################### - - -[2024-11-09 13:21:50] ##################################################################################################### -[2024-11-09 13:21:50] CAPTURE FINAL EMISSIONS -[2024-11-09 13:21:50] ##################################################################################################### -[2024-11-09 13:21:50] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 13:21:52] CodeCarbon measurement completed successfully. -[2024-11-09 13:21:52] Output saved to /Users/ayushiamin/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt -[2024-11-09 13:21:52] Final Emissions: 5.219136414312479e-09 kg CO2 -[2024-11-09 13:21:52] ##################################################################################################### - - -[2024-11-09 13:21:52] Saved 3.097365777034675e-09 kg CO2 +[2024-11-09 19:05:18] ##################################################################################################### +[2024-11-09 19:05:18] CAPTURE INITIAL EMISSIONS +[2024-11-09 19:05:18] ##################################################################################################### +[2024-11-09 19:05:18] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 19:05:23] CodeCarbon measurement completed successfully. +[2024-11-09 19:05:23] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt +[2024-11-09 19:05:23] Initial Emissions: 1.5186652718459153e-08 kg CO2 +[2024-11-09 19:05:23] ##################################################################################################### + + +[2024-11-09 19:05:23] ##################################################################################################### +[2024-11-09 19:05:23] CAPTURE CODE SMELLS +[2024-11-09 19:05:23] ##################################################################################################### +[2024-11-09 19:05:23] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-09 19:05:24] Pylint analyzer completed successfully. +[2024-11-09 19:05:24] Running custom parsers: +[2024-11-09 19:05:24] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json +[2024-11-09 19:05:24] Filtering pylint smells +[2024-11-09 19:05:24] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json +[2024-11-09 19:05:24] Refactorable code smells: 12 +[2024-11-09 19:05:24] ##################################################################################################### + + +[2024-11-09 19:05:24] ##################################################################################################### +[2024-11-09 19:05:24] REFACTOR CODE SMELLS +[2024-11-09 19:05:24] ##################################################################################################### +[2024-11-09 19:05:24] Refactoring for smell too-many-arguments is not implemented. +[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. +[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. +[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. +[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. +[2024-11-09 19:05:24] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 1 for identified code smell. +[2024-11-09 19:05:24] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp +[2024-11-09 19:05:30] CodeCarbon measurement completed successfully. +[2024-11-09 19:05:30] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.9007551493553634e-08 +[2024-11-09 19:05:30] Initial Emissions: 1.5186652718459153e-08 kg CO2. Final Emissions: 1.9007551493553634e-08 kg CO2. +[2024-11-09 19:05:30] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-09 19:05:30] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 2 for identified code smell. +[2024-11-09 19:05:30] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp +[2024-11-09 19:05:36] CodeCarbon measurement completed successfully. +[2024-11-09 19:05:36] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.395160386463735e-08 +[2024-11-09 19:05:36] Initial Emissions: 1.5186652718459153e-08 kg CO2. Final Emissions: 1.395160386463735e-08 kg CO2. +[2024-11-09 19:05:36] Removed unused import on line 2 and saved changes. + +[2024-11-09 19:05:36] Refactoring for smell long-message-chain is not implemented. +[2024-11-09 19:05:36] Refactoring for smell line-too-long is not implemented. +[2024-11-09 19:05:36] ##################################################################################################### + + +[2024-11-09 19:05:36] ##################################################################################################### +[2024-11-09 19:05:36] CAPTURE FINAL EMISSIONS +[2024-11-09 19:05:36] ##################################################################################################### +[2024-11-09 19:05:36] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 19:05:41] CodeCarbon measurement completed successfully. +[2024-11-09 19:05:41] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt +[2024-11-09 19:05:41] Final Emissions: 1.1923300735073934e-08 kg CO2 +[2024-11-09 19:05:41] ##################################################################################################### + + +[2024-11-09 19:05:41] Saved 3.2633519833852193e-09 kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index 9808777f..48e1887e 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,4 +1,6 @@ +import datetime # Unused import import collections # Unused import + # LC: Large Class with too many responsibilities class DataProcessor: def __init__(self, data): diff --git a/src1/refactorers/base_refactorer.py b/src1/refactorers/base_refactorer.py index ed3b29f3..fe100716 100644 --- a/src1/refactorers/base_refactorer.py +++ b/src1/refactorers/base_refactorer.py @@ -15,7 +15,7 @@ def __init__(self, logger): self.logger = logger # Store the mandatory logger instance @abstractmethod - def refactor(self, file_path, pylint_smell, initial_emission): + def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): """ Abstract method for refactoring the code smell. Each subclass should implement this method. @@ -26,24 +26,26 @@ def refactor(self, file_path, pylint_smell, initial_emission): """ pass - def measure_energy(self, file_path): + def measure_energy(self, file_path: str) -> float: """ Method for measuring the energy after refactoring. """ codecarbon_energy_meter = CodeCarbonEnergyMeter(file_path, self.logger) codecarbon_energy_meter.measure_energy() # measure emissions - self.final_emission = codecarbon_energy_meter.emissions # get emission + emissions = codecarbon_energy_meter.emissions # get emission # Log the measured emissions - self.logger.log(f"Measured emissions for '{os.path.basename(file_path)}': {self.final_emission}") + self.logger.log(f"Measured emissions for '{os.path.basename(file_path)}': {emissions}") - def check_energy_improvement(self): + return emissions + + def check_energy_improvement(self, initial_emissions: float, final_emissions: float): """ Checks if the refactoring has reduced energy consumption. :return: True if the final emission is lower than the initial emission, indicating improvement; False otherwise. """ - improved = self.final_emission and (self.final_emission < self.initial_emission) - self.logger.log(f"Initial Emissions: {self.initial_emission} kg CO2. Final Emissions: {self.final_emission} kg CO2.") + improved = final_emissions and (final_emissions < initial_emissions) + self.logger.log(f"Initial Emissions: {initial_emissions} kg CO2. Final Emissions: {final_emissions} kg CO2.") return improved diff --git a/src1/refactorers/long_lambda_function_refactorer.py b/src1/refactorers/long_lambda_function_refactorer.py index bc409b73..0133c247 100644 --- a/src1/refactorers/long_lambda_function_refactorer.py +++ b/src1/refactorers/long_lambda_function_refactorer.py @@ -9,7 +9,7 @@ class LongLambdaFunctionRefactorer(BaseRefactorer): def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emission): + def refactor(self, file_path, pylint_smell, initial_emissions): """ Refactor long lambda functions """ diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index c98572c1..c6ead28d 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -9,7 +9,7 @@ class LongMessageChainRefactorer(BaseRefactorer): def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emission): + def refactor(self, file_path, pylint_smell, initial_emissions): """ Refactor long message chain """ diff --git a/src1/refactorers/unused_imports_refactor.py b/src1/refactorers/unused_imports_refactor.py index 5d85ab8b..46b03816 100644 --- a/src1/refactorers/unused_imports_refactor.py +++ b/src1/refactorers/unused_imports_refactor.py @@ -11,7 +11,7 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emission): + def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): """ Refactors unused imports by removing lines where they appear. Modifies the specified instance in the file if it results in lower emissions. @@ -20,7 +20,6 @@ def refactor(self, file_path, pylint_smell, initial_emission): :param pylint_smell: Dictionary containing details of the Pylint smell, including the line number. :param initial_emission: Initial emission value before refactoring. """ - self.initial_emission = initial_emission line_number = pylint_smell.get("line") self.logger.log( f"Applying 'Remove Unused Imports' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." @@ -45,10 +44,10 @@ def refactor(self, file_path, pylint_smell, initial_emission): temp_file.writelines(modified_lines) # Measure emissions of the modified code - self.measure_energy(temp_file_path) + final_emissions = self.measure_energy(temp_file_path) # Check for improvement in emissions - if self.check_energy_improvement(): + if self.check_energy_improvement(initial_emissions, final_emissions): # Replace the original file with the modified content if improved shutil.move(temp_file_path, file_path) self.logger.log( diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactor.py index 0e6ed762..9ae9b775 100644 --- a/src1/refactorers/use_a_generator_refactor.py +++ b/src1/refactorers/use_a_generator_refactor.py @@ -1,7 +1,7 @@ # refactorers/use_a_generator_refactor.py import ast -import ast # For converting AST back to source code +import astor # For converting AST back to source code import shutil import os from .base_refactorer import BaseRefactorer @@ -20,18 +20,18 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emission): + def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): """ Refactors an unnecessary list comprehension by converting it to a generator expression. Modifies the specified instance in the file directly if it results in lower emissions. """ - line_number = self.pylint_smell["line"] + line_number = pylint_smell["line"] self.logger.log( - f"Applying 'Use a Generator' refactor on '{os.path.basename(self.file_path)}' at line {line_number} for identified code smell." + f"Applying 'Use a Generator' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." ) # Load the source code as a list of lines - with open(self.file_path, "r") as file: + with open(file_path, "r") as file: original_lines = file.readlines() # Check if the line number is valid within the file @@ -72,17 +72,17 @@ def refactor(self, file_path, pylint_smell, initial_emission): modified_lines[line_number - 1] = indentation + modified_line + "\n" # Temporarily write the modified content to a temporary file - temp_file_path = f"{self.file_path}.temp" + temp_file_path = f"{file_path}.temp" with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) # Measure emissions of the modified code - self.measure_energy(temp_file_path) + final_emission = self.measure_energy(temp_file_path) # Check for improvement in emissions - if self.check_energy_improvement(): + if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content - shutil.move(temp_file_path, self.file_path) + shutil.move(temp_file_path, file_path) self.logger.log( f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" ) diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index c5c90ea2..3157f39d 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -26,6 +26,7 @@ class PylintSmell(ExtendedEnum): INVALID_NAMING_CONVENTIONS = ( "C0103" # Pylint code smell for naming conventions violations ) + NO_SELF_USE = "R6301" # Pylint code smell for class methods that don't use any self calls # unused stuff UNUSED_IMPORT = ( @@ -68,6 +69,7 @@ class AllSmells(ExtendedEnum): # Additional Pylint configuration options for analyzing code EXTRA_PYLINT_OPTIONS = [ + "--enable-all-extensions", "--max-line-length=80", # Sets maximum allowed line length "--max-nested-blocks=3", # Limits maximum nesting of blocks "--max-branches=3", # Limits maximum branches in a function diff --git a/src1/utils/outputs_config.py b/src1/utils/outputs_config.py index 1a2ef31e..4fad047f 100644 --- a/src1/utils/outputs_config.py +++ b/src1/utils/outputs_config.py @@ -63,8 +63,6 @@ def copy_file_to_output(source_file_path, new_file_name, logger=None): :param source_file_path: The path of the file to be copied. :param new_file_name: The desired name for the copied file in the output directory. :param logger: Optional logger instance to log messages. - - :return: Path of the copied file in the output directory. """ # Ensure the output directory exists; if not, create it if not os.path.exists(OUTPUT_DIR): @@ -80,6 +78,4 @@ def copy_file_to_output(source_file_path, new_file_name, logger=None): if logger: logger.log(message) else: - print(message) - - return destination_path + print(message) \ No newline at end of file diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index b77c5cfa..6d060703 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -1,9 +1,11 @@ # Import specific refactorer classes from refactorers.use_a_generator_refactor import UseAGeneratorRefactor from refactorers.unused_imports_refactor import RemoveUnusedImportsRefactor +from refactorers.member_ignoring_method_refactorer import MakeStaticRefactor from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells +from utils.logger import Logger from utils.analyzers_config import AllSmells class RefactorerFactory(): @@ -13,7 +15,7 @@ class RefactorerFactory(): """ @staticmethod - def build_refactorer_class(file_path, smell_messageId, smell_data, initial_emission, logger): + def build_refactorer_class(smell_messageID: str, logger: Logger): """ Static method to create and return a refactorer instance based on the provided code smell. @@ -30,12 +32,13 @@ def build_refactorer_class(file_path, smell_messageId, smell_data, initial_emiss selected = None # Initialize variable to hold the selected refactorer instance # Use match statement to select the appropriate refactorer based on smell message ID - match smell_messageId: + match smell_messageID: case AllSmells.USE_A_GENERATOR.value: - selected = UseAGeneratorRefactor(file_path, smell_data, initial_emission, logger) + selected = UseAGeneratorRefactor(logger) case AllSmells.UNUSED_IMPORT.value: - x = RemoveUnusedImportsRefactor(logger) - selected = x.refactor(file_path, smell_data, initial_emission) + selected = RemoveUnusedImportsRefactor(logger) + case AllSmells.NO_SELF_USE.value: + selected = MakeStaticRefactor(logger) case _: selected = None diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 48e1887e..f7fd3f84 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,5 +1,4 @@ import datetime # Unused import -import collections # Unused import # LC: Large Class with too many responsibilities class DataProcessor: From 3ac2ae69bdcf9399c07fa851be36b7c2ec88176b Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 9 Nov 2024 20:32:49 -0500 Subject: [PATCH 058/105] #239: Implemented Member Ignoring Method Refactoring --- src1/main.py | 2 +- .../outputs/all_configured_pylint_smells.json | 96 ++----- src1/outputs/all_pylint_smells.json | 235 +++++++----------- src1/outputs/final_emissions_data.txt | 16 +- src1/outputs/initial_emissions_data.txt | 16 +- src1/outputs/log.txt | 127 +++++----- src1/outputs/refactored-test-case.py | 69 ++--- src1/refactorers/base_refactorer.py | 2 +- .../long_lambda_function_refactorer.py | 2 +- .../long_message_chain_refactorer.py | 2 +- .../member_ignoring_method_refactorer.py | 75 ++++++ src1/refactorers/unused_imports_refactor.py | 2 +- src1/refactorers/use_a_generator_refactor.py | 2 +- src1/utils/analyzers_config.py | 2 - tests/input/ineffcient_code_example_2.py | 70 +++--- 15 files changed, 325 insertions(+), 393 deletions(-) create mode 100644 src1/refactorers/member_ignoring_method_refactorer.py diff --git a/src1/main.py b/src1/main.py index b4269405..cd84e652 100644 --- a/src1/main.py +++ b/src1/main.py @@ -97,7 +97,7 @@ def main(): refactoring_class.refactor(TEST_FILE, pylint_smell, initial_emissions) else: logger.log( - f"Refactoring for smell {pylint_smell['symbol']} is not implemented." + f"Refactoring for smell {pylint_smell['symbol']} is not implemented.\n" ) logger.log( "#####################################################################################################\n\n" diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index f60252cf..1b7cbd6d 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -2,9 +2,9 @@ { "column": 4, "endColumn": 27, - "endLine": 35, - "line": 35, - "message": "Too many arguments (9/5)", + "endLine": 26, + "line": 26, + "message": "Too many arguments (8/5)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", @@ -13,10 +13,10 @@ "type": "refactor" }, { - "column": 20, - "endColumn": 25, - "endLine": 36, - "line": 36, + "column": 34, + "endColumn": 39, + "endLine": 26, + "line": 26, "message": "Unused argument 'flag1'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -26,10 +26,10 @@ "type": "warning" }, { - "column": 27, - "endColumn": 32, - "endLine": 36, - "line": 36, + "column": 41, + "endColumn": 46, + "endLine": 26, + "line": 26, "message": "Unused argument 'flag2'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -39,10 +39,10 @@ "type": "warning" }, { - "column": 67, - "endColumn": 73, - "endLine": 36, - "line": 36, + "column": 19, + "endColumn": 25, + "endLine": 27, + "line": 27, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -52,10 +52,10 @@ "type": "warning" }, { - "column": 75, - "endColumn": 86, - "endLine": 36, - "line": 36, + "column": 27, + "endColumn": 38, + "endLine": 27, + "line": 27, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -64,24 +64,11 @@ "symbol": "unused-argument", "type": "warning" }, - { - "column": 4, - "endColumn": 27, - "endLine": 35, - "line": 35, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, { "column": 4, "endColumn": 18, - "endLine": 49, - "line": 49, + "endLine": 39, + "line": 39, "message": "Method could be a function", "message-id": "R6301", "module": "ineffcient_code_example_2", @@ -90,19 +77,6 @@ "symbol": "no-self-use", "type": "refactor" }, - { - "column": 4, - "endColumn": 27, - "endLine": 70, - "line": 70, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, { "column": 0, "endColumn": 15, @@ -116,26 +90,13 @@ "symbol": "unused-import", "type": "warning" }, - { - "column": 0, - "endColumn": 18, - "endLine": 2, - "line": 2, - "message": "Unused import collections", - "message-id": "W0611", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "unused-import", - "type": "warning" - }, { "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 25, + "line": 20, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", @@ -143,18 +104,5 @@ "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 50, - "message": "Ternary expression has too many branches", - "message-id": "CUST-1", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "line-too-long", - "type": "convention" } ] \ No newline at end of file diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index 1e08ea2e..5d1e5d4c 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -1,54 +1,28 @@ [ { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 29, - "message": "Line too long (83/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 36, - "message": "Line too long (86/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 0, + "column": 74, "endColumn": null, "endLine": null, - "line": 50, - "message": "Line too long (90/80)", - "message-id": "C0301", + "line": 21, + "message": "Trailing whitespace", + "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "line-too-long", + "symbol": "trailing-whitespace", "type": "convention" }, { - "column": 0, + "column": 71, "endColumn": null, "endLine": null, - "line": 64, - "message": "Line too long (85/80)", - "message-id": "C0301", + "line": 40, + "message": "Trailing whitespace", + "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "line-too-long", + "symbol": "trailing-whitespace", "type": "convention" }, { @@ -67,8 +41,8 @@ { "column": 0, "endColumn": 19, - "endLine": 5, - "line": 5, + "endLine": 4, + "line": 4, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", @@ -80,8 +54,8 @@ { "column": 4, "endColumn": 24, - "endLine": 11, - "line": 11, + "endLine": 10, + "line": 10, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -93,8 +67,8 @@ { "column": 19, "endColumn": 28, - "endLine": 20, - "line": 20, + "endLine": 17, + "line": 17, "message": "Catching too general exception Exception", "message-id": "W0718", "module": "ineffcient_code_example_2", @@ -106,8 +80,8 @@ { "column": 12, "endColumn": 46, - "endLine": 21, - "line": 14, + "endLine": 18, + "line": 13, "message": "try clause contains 2 statements, expected at most 1", "message-id": "W0717", "module": "ineffcient_code_example_2", @@ -117,10 +91,10 @@ "type": "warning" }, { - "column": 12, - "endColumn": 83, - "endLine": 29, - "line": 29, + "column": 35, + "endColumn": 43, + "endLine": 22, + "line": 21, "message": "Used builtin function 'filter'. Using a list comprehension can be clearer.", "message-id": "W0141", "module": "ineffcient_code_example_2", @@ -132,8 +106,8 @@ { "column": 4, "endColumn": 27, - "endLine": 35, - "line": 35, + "endLine": 26, + "line": 26, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -145,9 +119,9 @@ { "column": 4, "endColumn": 27, - "endLine": 35, - "line": 35, - "message": "Too many arguments (9/5)", + "endLine": 26, + "line": 26, + "message": "Too many arguments (8/5)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", @@ -158,9 +132,9 @@ { "column": 4, "endColumn": 27, - "endLine": 35, - "line": 35, - "message": "Too many positional arguments (9/5)", + "endLine": 26, + "line": 26, + "message": "Too many positional arguments (8/5)", "message-id": "R0917", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", @@ -171,8 +145,8 @@ { "column": 11, "endColumn": 34, - "endLine": 38, - "line": 38, + "endLine": 28, + "line": 28, "message": "Consider using a named constant or an enum instead of ''multiply''.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -184,8 +158,8 @@ { "column": 13, "endColumn": 31, - "endLine": 40, - "line": 40, + "endLine": 30, + "line": 30, "message": "Consider using a named constant or an enum instead of ''add''.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -195,10 +169,10 @@ "type": "refactor" }, { - "column": 20, - "endColumn": 25, - "endLine": 36, - "line": 36, + "column": 34, + "endColumn": 39, + "endLine": 26, + "line": 26, "message": "Unused argument 'flag1'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -208,10 +182,10 @@ "type": "warning" }, { - "column": 27, - "endColumn": 32, - "endLine": 36, - "line": 36, + "column": 41, + "endColumn": 46, + "endLine": 26, + "line": 26, "message": "Unused argument 'flag2'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -221,10 +195,10 @@ "type": "warning" }, { - "column": 67, - "endColumn": 73, - "endLine": 36, - "line": 36, + "column": 19, + "endColumn": 25, + "endLine": 27, + "line": 27, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -234,10 +208,10 @@ "type": "warning" }, { - "column": 75, - "endColumn": 86, - "endLine": 36, - "line": 36, + "column": 27, + "endColumn": 38, + "endLine": 27, + "line": 27, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", @@ -246,24 +220,11 @@ "symbol": "unused-argument", "type": "warning" }, - { - "column": 4, - "endColumn": 27, - "endLine": 35, - "line": 35, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, { "column": 0, "endColumn": 23, - "endLine": 47, - "line": 47, + "endLine": 37, + "line": 37, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", @@ -275,8 +236,8 @@ { "column": 4, "endColumn": 18, - "endLine": 49, - "line": 49, + "endLine": 39, + "line": 39, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -286,10 +247,10 @@ "type": "convention" }, { - "column": 23, - "endColumn": 32, - "endLine": 50, - "line": 50, + "column": 24, + "endColumn": 33, + "endLine": 40, + "line": 40, "message": "Consider using a named constant or an enum instead of '10'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -301,8 +262,8 @@ { "column": 4, "endColumn": 18, - "endLine": 49, - "line": 49, + "endLine": 39, + "line": 39, "message": "Method could be a function", "message-id": "R6301", "module": "ineffcient_code_example_2", @@ -314,8 +275,8 @@ { "column": 4, "endColumn": 29, - "endLine": 53, - "line": 53, + "endLine": 43, + "line": 43, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -325,10 +286,10 @@ "type": "convention" }, { - "column": 30, - "endColumn": 37, - "endLine": 58, - "line": 58, + "column": 44, + "endColumn": 51, + "endLine": 45, + "line": 45, "message": "Consider using a named constant or an enum instead of '50'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -338,10 +299,10 @@ "type": "refactor" }, { - "column": 42, - "endColumn": 47, - "endLine": 58, - "line": 58, + "column": 56, + "endColumn": 61, + "endLine": 45, + "line": 45, "message": "Consider using a named constant or an enum instead of '3'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -353,8 +314,8 @@ { "column": 4, "endColumn": 18, - "endLine": 62, - "line": 62, + "endLine": 47, + "line": 47, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -366,8 +327,8 @@ { "column": 8, "endColumn": 23, - "endLine": 67, - "line": 63, + "endLine": 53, + "line": 48, "message": "try clause contains 2 statements, expected at most 1", "message-id": "W0717", "module": "ineffcient_code_example_2", @@ -379,8 +340,8 @@ { "column": 4, "endColumn": 27, - "endLine": 70, - "line": 70, + "endLine": 56, + "line": 56, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -392,8 +353,8 @@ { "column": 31, "endColumn": 53, - "endLine": 76, - "line": 76, + "endLine": 62, + "line": 62, "message": "Consider using a named constant or an enum instead of '25'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -405,8 +366,8 @@ { "column": 4, "endColumn": 27, - "endLine": 70, - "line": 70, + "endLine": 56, + "line": 56, "message": "Too many branches (6/3)", "message-id": "R0912", "module": "ineffcient_code_example_2", @@ -418,8 +379,8 @@ { "column": 8, "endColumn": 45, - "endLine": 77, - "line": 71, + "endLine": 63, + "line": 57, "message": "Too many nested blocks (6/3)", "message-id": "R1702", "module": "ineffcient_code_example_2", @@ -431,8 +392,8 @@ { "column": 4, "endColumn": 27, - "endLine": 70, - "line": 70, + "endLine": 56, + "line": 56, "message": "Either all return statements in a function should return an expression, or none of them should.", "message-id": "R1710", "module": "ineffcient_code_example_2", @@ -441,19 +402,6 @@ "symbol": "inconsistent-return-statements", "type": "refactor" }, - { - "column": 4, - "endColumn": 27, - "endLine": 70, - "line": 70, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, { "column": 0, "endColumn": 15, @@ -467,26 +415,13 @@ "symbol": "unused-import", "type": "warning" }, - { - "column": 0, - "endColumn": 18, - "endLine": 2, - "line": 2, - "message": "Unused import collections", - "message-id": "W0611", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "unused-import", - "type": "warning" - }, { "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 25, + "line": 20, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index 2e2cf540..df8626de 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 1.8817833333741875e-07, + "cpu_energy": 1.857750001363456e-07, "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", "cpu_power": 7.5, - "duration": 0.0912796999327838, - "emissions": 1.1923300735073934e-08, - "emissions_rate": 1.3062379416073854e-07, - "energy_consumed": 3.018828361991019e-07, + "duration": 0.0899510000599548, + "emissions": 1.2555916317106813e-08, + "emissions_rate": 1.395861781274021e-07, + "energy_consumed": 3.178998595361087e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 1.1370450286168313e-07, + "ram_energy": 1.321248593997631e-07, "ram_power": 6.730809688568115, "ram_total_size": 17.94882583618164, "region": "ontario", - "run_id": "2089b6e1-c373-4b66-87fa-1899c88dee17", - "timestamp": "2024-11-09T19:05:41", + "run_id": "e6dacc1b-4c06-473e-b331-a91e669aa4fc", + "timestamp": "2024-11-09T20:30:45", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index ce512e82..9ec702d7 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 2.313262501653905e-07, + "cpu_energy": 3.206839583678327e-07, "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", "cpu_power": 7.5, - "duration": 0.111857800045982, - "emissions": 1.5186652718459153e-08, - "emissions_rate": 1.3576748972549338e-07, - "energy_consumed": 3.845067651051595e-07, + "duration": 0.1550977999577298, + "emissions": 2.1139604900509435e-08, + "emissions_rate": 1.3629854779546062e-07, + "energy_consumed": 5.352279561918346e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 1.5318051493976906e-07, + "ram_energy": 2.14543997824002e-07, "ram_power": 6.730809688568115, "ram_total_size": 17.94882583618164, "region": "ontario", - "run_id": "1f0dc5c1-ae3f-42d9-b4e3-100bec900593", - "timestamp": "2024-11-09T19:05:23", + "run_id": "f9541537-6822-4be0-96f4-63f743584883", + "timestamp": "2024-11-09T20:30:25", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 04246ff7..26a7b15e 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,61 +1,66 @@ -[2024-11-09 19:05:18] ##################################################################################################### -[2024-11-09 19:05:18] CAPTURE INITIAL EMISSIONS -[2024-11-09 19:05:18] ##################################################################################################### -[2024-11-09 19:05:18] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 19:05:23] CodeCarbon measurement completed successfully. -[2024-11-09 19:05:23] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt -[2024-11-09 19:05:23] Initial Emissions: 1.5186652718459153e-08 kg CO2 -[2024-11-09 19:05:23] ##################################################################################################### - - -[2024-11-09 19:05:23] ##################################################################################################### -[2024-11-09 19:05:23] CAPTURE CODE SMELLS -[2024-11-09 19:05:23] ##################################################################################################### -[2024-11-09 19:05:23] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-09 19:05:24] Pylint analyzer completed successfully. -[2024-11-09 19:05:24] Running custom parsers: -[2024-11-09 19:05:24] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json -[2024-11-09 19:05:24] Filtering pylint smells -[2024-11-09 19:05:24] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json -[2024-11-09 19:05:24] Refactorable code smells: 12 -[2024-11-09 19:05:24] ##################################################################################################### - - -[2024-11-09 19:05:24] ##################################################################################################### -[2024-11-09 19:05:24] REFACTOR CODE SMELLS -[2024-11-09 19:05:24] ##################################################################################################### -[2024-11-09 19:05:24] Refactoring for smell too-many-arguments is not implemented. -[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. -[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. -[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. -[2024-11-09 19:05:24] Refactoring for smell unused-argument is not implemented. -[2024-11-09 19:05:24] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 1 for identified code smell. -[2024-11-09 19:05:24] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp -[2024-11-09 19:05:30] CodeCarbon measurement completed successfully. -[2024-11-09 19:05:30] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.9007551493553634e-08 -[2024-11-09 19:05:30] Initial Emissions: 1.5186652718459153e-08 kg CO2. Final Emissions: 1.9007551493553634e-08 kg CO2. -[2024-11-09 19:05:30] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-09 19:05:30] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 2 for identified code smell. -[2024-11-09 19:05:30] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp -[2024-11-09 19:05:36] CodeCarbon measurement completed successfully. -[2024-11-09 19:05:36] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.395160386463735e-08 -[2024-11-09 19:05:36] Initial Emissions: 1.5186652718459153e-08 kg CO2. Final Emissions: 1.395160386463735e-08 kg CO2. -[2024-11-09 19:05:36] Removed unused import on line 2 and saved changes. - -[2024-11-09 19:05:36] Refactoring for smell long-message-chain is not implemented. -[2024-11-09 19:05:36] Refactoring for smell line-too-long is not implemented. -[2024-11-09 19:05:36] ##################################################################################################### - - -[2024-11-09 19:05:36] ##################################################################################################### -[2024-11-09 19:05:36] CAPTURE FINAL EMISSIONS -[2024-11-09 19:05:36] ##################################################################################################### -[2024-11-09 19:05:36] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 19:05:41] CodeCarbon measurement completed successfully. -[2024-11-09 19:05:41] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt -[2024-11-09 19:05:41] Final Emissions: 1.1923300735073934e-08 kg CO2 -[2024-11-09 19:05:41] ##################################################################################################### - - -[2024-11-09 19:05:41] Saved 3.2633519833852193e-09 kg CO2 +[2024-11-09 20:30:19] ##################################################################################################### +[2024-11-09 20:30:19] CAPTURE INITIAL EMISSIONS +[2024-11-09 20:30:19] ##################################################################################################### +[2024-11-09 20:30:19] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 20:30:25] CodeCarbon measurement completed successfully. +[2024-11-09 20:30:25] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt +[2024-11-09 20:30:25] Initial Emissions: 2.1139604900509435e-08 kg CO2 +[2024-11-09 20:30:25] ##################################################################################################### + + +[2024-11-09 20:30:25] ##################################################################################################### +[2024-11-09 20:30:25] CAPTURE CODE SMELLS +[2024-11-09 20:30:25] ##################################################################################################### +[2024-11-09 20:30:25] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-09 20:30:27] Pylint analyzer completed successfully. +[2024-11-09 20:30:27] Running custom parsers: +[2024-11-09 20:30:27] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json +[2024-11-09 20:30:27] Filtering pylint smells +[2024-11-09 20:30:27] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json +[2024-11-09 20:30:27] Refactorable code smells: 8 +[2024-11-09 20:30:27] ##################################################################################################### + + +[2024-11-09 20:30:27] ##################################################################################################### +[2024-11-09 20:30:27] REFACTOR CODE SMELLS +[2024-11-09 20:30:27] ##################################################################################################### +[2024-11-09 20:30:27] Refactoring for smell too-many-arguments is not implemented. + +[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. + +[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. + +[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. + +[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. + +[2024-11-09 20:30:27] Applying 'Make Method Static' refactor on 'ineffcient_code_example_2.py' at line 39 for identified code smell. +[2024-11-09 20:30:27] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-09 20:30:33] CodeCarbon measurement completed successfully. +[2024-11-09 20:30:33] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.5226976842757694e-08 +[2024-11-09 20:30:33] Initial Emissions: 2.1139604900509435e-08 kg CO2. Final Emissions: 1.5226976842757694e-08 kg CO2. +[2024-11-09 20:30:33] Refactored list comprehension to generator expression on line 39 and saved. + +[2024-11-09 20:30:33] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 1 for identified code smell. +[2024-11-09 20:30:33] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp +[2024-11-09 20:30:39] CodeCarbon measurement completed successfully. +[2024-11-09 20:30:39] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.4380604164174298e-08 +[2024-11-09 20:30:39] Initial Emissions: 2.1139604900509435e-08 kg CO2. Final Emissions: 1.4380604164174298e-08 kg CO2. +[2024-11-09 20:30:39] Removed unused import on line 1 and saved changes. + +[2024-11-09 20:30:39] Refactoring for smell long-message-chain is not implemented. + +[2024-11-09 20:30:39] ##################################################################################################### + + +[2024-11-09 20:30:39] ##################################################################################################### +[2024-11-09 20:30:39] CAPTURE FINAL EMISSIONS +[2024-11-09 20:30:39] ##################################################################################################### +[2024-11-09 20:30:39] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-09 20:30:45] CodeCarbon measurement completed successfully. +[2024-11-09 20:30:45] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt +[2024-11-09 20:30:45] Final Emissions: 1.2555916317106811e-08 kg CO2 +[2024-11-09 20:30:45] ##################################################################################################### + + +[2024-11-09 20:30:45] Saved 8.583688583402624e-09 kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index 48e1887e..a7ea800c 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,43 +1,33 @@ -import datetime # Unused import -import collections # Unused import +import datetime + -# LC: Large Class with too many responsibilities class DataProcessor: + def __init__(self, data): self.data = data self.processed_data = [] - # LM: Long Method - this method does way too much def process_all_data(self): results = [] for item in self.data: try: - # LPL: Long Parameter List - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) + result = self.complex_calculation(item, True, False, + 'multiply', 10, 20, None, 'end') results.append(result) - except Exception as e: # UEH: Unqualified Exception Handling - print("An error occurred:", e) - - # LMC: Long Message Chain + except Exception as e: + print('An error occurred:', e) if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(" ", "_").lower()) - - # LLF: Long Lambda Function - self.processed_data = list( - filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) - ) - + print(self.data[0].upper().strip().replace(' ', '_').lower()) + self.processed_data = list(filter(lambda x: x is not None and x != + 0 and len(str(x)) > 1, results)) return self.processed_data - # Moved the complex_calculation method here - def complex_calculation( - self, item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": + @staticmethod + def complex_calculation(item, flag1, flag2, operation, threshold, + max_value, option, final_stage): + if operation == 'multiply': result = item * threshold - elif operation == "add": + elif operation == 'add': result = item + max_value else: result = item @@ -45,41 +35,36 @@ def complex_calculation( class AdvancedProcessor(DataProcessor): - # LTCE: Long Ternary Conditional Expression + def check_data(self, item): - return True if item > 10 else False if item < -10 else None if item == 0 else item + return (True if item > 10 else False if item < -10 else None if + item == 0 else item) - # Complex List Comprehension def complex_comprehension(self): - # CLC: Complex List Comprehension - self.processed_data = [ - x**2 if x % 2 == 0 else x**3 - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] + self.processed_data = [(x ** 2 if x % 2 == 0 else x ** 3) for x in + range(1, 100) if x % 5 == 0 and x != 50 and x > 3] - # Long Element Chain def long_chain(self): try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + deep_value = self.data[0][1]['details']['info']['more_info'][2][ + 'target'] return deep_value except (KeyError, IndexError, TypeError): return None - # Long Scope Chaining (LSC) - def long_scope_chaining(self): + @staticmethod + def long_scope_chaining(): for a in range(10): for b in range(10): for c in range(10): for d in range(10): for e in range(10): if a + b + c + d + e > 25: - return "Done" + return 'Done' -# Main method to execute the code -if __name__ == "__main__": +if __name__ == '__main__': sample_data = [1, 2, 3, 4, 5] processor = DataProcessor(sample_data) processed = processor.process_all_data() - print("Processed Data:", processed) + print('Processed Data:', processed) diff --git a/src1/refactorers/base_refactorer.py b/src1/refactorers/base_refactorer.py index fe100716..c80e5a59 100644 --- a/src1/refactorers/base_refactorer.py +++ b/src1/refactorers/base_refactorer.py @@ -15,7 +15,7 @@ def __init__(self, logger): self.logger = logger # Store the mandatory logger instance @abstractmethod - def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ Abstract method for refactoring the code smell. Each subclass should implement this method. diff --git a/src1/refactorers/long_lambda_function_refactorer.py b/src1/refactorers/long_lambda_function_refactorer.py index 0133c247..cfc533f9 100644 --- a/src1/refactorers/long_lambda_function_refactorer.py +++ b/src1/refactorers/long_lambda_function_refactorer.py @@ -9,7 +9,7 @@ class LongLambdaFunctionRefactorer(BaseRefactorer): def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emissions): + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ Refactor long lambda functions """ diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index c6ead28d..4ce68450 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -9,7 +9,7 @@ class LongMessageChainRefactorer(BaseRefactorer): def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emissions): + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ Refactor long message chain """ diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src1/refactorers/member_ignoring_method_refactorer.py new file mode 100644 index 00000000..cebad43c --- /dev/null +++ b/src1/refactorers/member_ignoring_method_refactorer.py @@ -0,0 +1,75 @@ +import os +import shutil +import astor +import ast +from ast import NodeTransformer + +from .base_refactorer import BaseRefactorer + + +class MakeStaticRefactor(BaseRefactorer, NodeTransformer): + """ + Refactorer that targets methods that don't use any class attributes and makes them static to improve performance + """ + + def __init__(self, logger): + super().__init__(logger) + self.target_line = None + + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + """ + Perform refactoring + + :param file_path: absolute path to source code + :param pylint_smell: pylint code for smell + :param initial_emission: inital carbon emission prior to refactoring + """ + self.target_line = pylint_smell["line"] + self.logger.log( + f"Applying 'Make Method Static' refactor on '{os.path.basename(file_path)}' at line {self.target_line} for identified code smell." + ) + with open(file_path, "r") as f: + code = f.read() + + # Parse the code into an AST + tree = ast.parse(code) + + # Apply the transformation + modified_tree = self.visit(tree) + + # Convert the modified AST back to source code + modified_code = astor.to_source(modified_tree) + + temp_file_path = f"{os.path.basename(file_path).split(".")[0]}_temp.py" + with open(temp_file_path, "w") as temp_file: + temp_file.write(modified_code) + + # Measure emissions of the modified code + final_emission = self.measure_energy(temp_file_path) + + # Check for improvement in emissions + if self.check_energy_improvement(initial_emissions, final_emission): + # If improved, replace the original file with the modified content + shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored list comprehension to generator expression on line {self.target_line} and saved.\n" + ) + else: + # Remove the temporary file if no improvement + os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + + def visit_FunctionDef(self, node): + if node.lineno == self.target_line: + # Step 1: Add the decorator + decorator = ast.Name(id="staticmethod", ctx=ast.Load()) + node.decorator_list.append(decorator) + + # Step 2: Remove 'self' from the arguments if it exists + if node.args.args and node.args.args[0].arg == 'self': + node.args.args.pop(0) + # Add the decorator to the function's decorator list + return node diff --git a/src1/refactorers/unused_imports_refactor.py b/src1/refactorers/unused_imports_refactor.py index 46b03816..b62c3938 100644 --- a/src1/refactorers/unused_imports_refactor.py +++ b/src1/refactorers/unused_imports_refactor.py @@ -11,7 +11,7 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ Refactors unused imports by removing lines where they appear. Modifies the specified instance in the file if it results in lower emissions. diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactor.py index 9ae9b775..7355c2a6 100644 --- a/src1/refactorers/use_a_generator_refactor.py +++ b/src1/refactorers/use_a_generator_refactor.py @@ -20,7 +20,7 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path: str, pylint_smell: str, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ Refactors an unnecessary list comprehension by converting it to a generator expression. Modifies the specified instance in the file directly if it results in lower emissions. diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 3157f39d..6212208a 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -41,8 +41,6 @@ class PylintSmell(ExtendedEnum): UNUSED_CLASS_ATTRIBUTE = ( "W0615" # Pylint code smell for unused class attribute ) - - USE_A_GENERATOR = ( "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` ) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index f7fd3f84..ced4fde0 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,42 +1,32 @@ -import datetime # Unused import -# LC: Large Class with too many responsibilities + class DataProcessor: + def __init__(self, data): self.data = data self.processed_data = [] - # LM: Long Method - this method does way too much def process_all_data(self): results = [] for item in self.data: try: - # LPL: Long Parameter List - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) + result = self.complex_calculation(item, True, False, + 'multiply', 10, 20, None, 'end') results.append(result) - except Exception as e: # UEH: Unqualified Exception Handling - print("An error occurred:", e) - - # LMC: Long Message Chain + except Exception as e: + print('An error occurred:', e) if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(" ", "_").lower()) - - # LLF: Long Lambda Function - self.processed_data = list( - filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) - ) - + print(self.data[0].upper().strip().replace(' ', '_').lower()) + self.processed_data = list(filter(lambda x: x is not None and x != + 0 and len(str(x)) > 1, results)) return self.processed_data - # Moved the complex_calculation method here - def complex_calculation( - self, item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": + @staticmethod + def complex_calculation(item, flag1, flag2, operation, threshold, + max_value, option, final_stage): + if operation == 'multiply': result = item * threshold - elif operation == "add": + elif operation == 'add': result = item + max_value else: result = item @@ -44,41 +34,37 @@ def complex_calculation( class AdvancedProcessor(DataProcessor): - # LTCE: Long Ternary Conditional Expression - def check_data(self, item): - return True if item > 10 else False if item < -10 else None if item == 0 else item - # Complex List Comprehension + @staticmethod + def check_data(item): + return (True if item > 10 else False if item < -10 else None if + item == 0 else item) + def complex_comprehension(self): - # CLC: Complex List Comprehension - self.processed_data = [ - x**2 if x % 2 == 0 else x**3 - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] + self.processed_data = [(x ** 2 if x % 2 == 0 else x ** 3) for x in + range(1, 100) if x % 5 == 0 and x != 50 and x > 3] - # Long Element Chain def long_chain(self): try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + deep_value = self.data[0][1]['details']['info']['more_info'][2][ + 'target'] return deep_value except (KeyError, IndexError, TypeError): return None - # Long Scope Chaining (LSC) - def long_scope_chaining(self): + @staticmethod + def long_scope_chaining(): for a in range(10): for b in range(10): for c in range(10): for d in range(10): for e in range(10): if a + b + c + d + e > 25: - return "Done" + return 'Done' -# Main method to execute the code -if __name__ == "__main__": +if __name__ == '__main__': sample_data = [1, 2, 3, 4, 5] processor = DataProcessor(sample_data) processed = processor.process_all_data() - print("Processed Data:", processed) + print('Processed Data:', processed) From 795e526a4162620cac5e61f68397751491c7014f Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Sat, 9 Nov 2024 21:13:00 -0500 Subject: [PATCH 059/105] Added framework for long parameter list refactoring --- src1/refactorers/long_parameter_list_refactorer.py | 14 ++++++++++++++ src1/utils/refactorer_factory.py | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 src1/refactorers/long_parameter_list_refactorer.py diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py new file mode 100644 index 00000000..54e65a12 --- /dev/null +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -0,0 +1,14 @@ +from .base_refactorer import BaseRefactorer + + +class LongParameterListRefactorer(BaseRefactorer): + """ + Refactorer that targets methods that take too many arguments + """ + + def __init__(self, logger): + super().__init__(logger) + + def refactor(self, file_path, pylint_smell, initial_emission): + # Logic to identify methods that take too many arguments goes here + pass diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index 6d060703..2aa64a5b 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -1,6 +1,7 @@ # Import specific refactorer classes from refactorers.use_a_generator_refactor import UseAGeneratorRefactor from refactorers.unused_imports_refactor import RemoveUnusedImportsRefactor +from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer from refactorers.member_ignoring_method_refactorer import MakeStaticRefactor from refactorers.base_refactorer import BaseRefactorer @@ -39,6 +40,8 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): selected = RemoveUnusedImportsRefactor(logger) case AllSmells.NO_SELF_USE.value: selected = MakeStaticRefactor(logger) + case AllSmells.LONG_PARAMETER_LIST.value: + selected = LongParameterListRefactorer(logger) case _: selected = None From d46652796889a093c45f5d6692e8b8d4b3aa56b5 Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Sun, 10 Nov 2024 00:38:13 -0500 Subject: [PATCH 060/105] Added refactoring logic for long param list code smell(pending categorization for encapsulated parameters list) --- .../outputs/all_configured_pylint_smells.json | 64 +++---- src1/outputs/all_pylint_smells.json | 156 ++++++++---------- src1/outputs/final_emissions_data.txt | 30 ++-- src1/outputs/initial_emissions_data.txt | 30 ++-- src1/outputs/log.txt | 109 +++++------- .../long_parameter_list_refactorer.py | 91 +++++++++- src1/utils/analyzers_config.py | 1 + 7 files changed, 247 insertions(+), 234 deletions(-) diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index 1b7cbd6d..e7267035 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -2,106 +2,80 @@ { "column": 4, "endColumn": 27, - "endLine": 26, - "line": 26, - "message": "Too many arguments (8/5)", + "endLine": 25, + "line": 25, + "message": "Too many arguments (8/4)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, { "column": 34, "endColumn": 39, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'flag1'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 41, "endColumn": 46, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'flag2'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 19, "endColumn": 25, - "endLine": 27, - "line": 27, + "endLine": 26, + "line": 26, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 27, "endColumn": 38, - "endLine": 27, - "line": 27, + "endLine": 26, + "line": 26, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { - "column": 4, - "endColumn": 18, - "endLine": 39, - "line": 39, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.check_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 15, - "endLine": 1, - "line": 1, - "message": "Unused import datetime", - "message-id": "W0611", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "unused-import", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "absolutePath": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 20, + "line": 19, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" } diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index 5d1e5d4c..0007756c 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -3,12 +3,12 @@ "column": 74, "endColumn": null, "endLine": null, - "line": 21, + "line": 20, "message": "Trailing whitespace", "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "trailing-whitespace", "type": "convention" }, @@ -21,7 +21,7 @@ "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "trailing-whitespace", "type": "convention" }, @@ -34,202 +34,202 @@ "message-id": "C0114", "module": "ineffcient_code_example_2", "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-module-docstring", "type": "convention" }, { "column": 0, "endColumn": 19, - "endLine": 4, - "line": 4, + "endLine": 3, + "line": 3, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", "obj": "DataProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-class-docstring", "type": "convention" }, { "column": 4, "endColumn": 24, - "endLine": 10, - "line": 10, + "endLine": 9, + "line": 9, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, { "column": 19, "endColumn": 28, - "endLine": 17, - "line": 17, + "endLine": 16, + "line": 16, "message": "Catching too general exception Exception", "message-id": "W0718", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "broad-exception-caught", "type": "warning" }, { "column": 12, "endColumn": 46, - "endLine": 18, - "line": 13, + "endLine": 17, + "line": 12, "message": "try clause contains 2 statements, expected at most 1", "message-id": "W0717", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-try-statements", "type": "warning" }, { "column": 35, "endColumn": 43, - "endLine": 22, - "line": 21, + "endLine": 21, + "line": 20, "message": "Used builtin function 'filter'. Using a list comprehension can be clearer.", "message-id": "W0141", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "bad-builtin", "type": "warning" }, { "column": 4, "endColumn": 27, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, { "column": 4, "endColumn": 27, - "endLine": 26, - "line": 26, - "message": "Too many arguments (8/5)", + "endLine": 25, + "line": 25, + "message": "Too many arguments (8/4)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, { "column": 4, "endColumn": 27, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Too many positional arguments (8/5)", "message-id": "R0917", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-positional-arguments", "type": "refactor" }, { "column": 11, "endColumn": 34, - "endLine": 28, - "line": 28, + "endLine": 27, + "line": 27, "message": "Consider using a named constant or an enum instead of ''multiply''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 31, - "endLine": 30, - "line": 30, + "endLine": 29, + "line": 29, "message": "Consider using a named constant or an enum instead of ''add''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 34, "endColumn": 39, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'flag1'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 41, "endColumn": 46, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'flag2'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 19, "endColumn": 25, - "endLine": 27, - "line": 27, + "endLine": 26, + "line": 26, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 27, "endColumn": 38, - "endLine": 27, - "line": 27, + "endLine": 26, + "line": 26, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 0, "endColumn": 23, - "endLine": 37, - "line": 37, + "endLine": 36, + "line": 36, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-class-docstring", "type": "convention" }, @@ -242,7 +242,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.check_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -255,23 +255,10 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.check_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, - { - "column": 4, - "endColumn": 18, - "endLine": 39, - "line": 39, - "message": "Method could be a function", - "message-id": "R6301", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.check_data", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "no-self-use", - "type": "refactor" - }, { "column": 4, "endColumn": 29, @@ -281,7 +268,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -294,7 +281,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -307,7 +294,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -320,7 +307,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_chain", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -333,7 +320,7 @@ "message-id": "W0717", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_chain", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-try-statements", "type": "warning" }, @@ -346,7 +333,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -359,7 +346,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -372,7 +359,7 @@ "message-id": "R0912", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-branches", "type": "refactor" }, @@ -385,7 +372,7 @@ "message-id": "R1702", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "too-many-nested-blocks", "type": "refactor" }, @@ -398,35 +385,22 @@ "message-id": "R1710", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "inconsistent-return-statements", "type": "refactor" }, { - "column": 0, - "endColumn": 15, - "endLine": 1, - "line": 1, - "message": "Unused import datetime", - "message-id": "W0611", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", - "symbol": "unused-import", - "type": "warning" - }, - { - "absolutePath": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "absolutePath": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 20, + "line": 19, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "c:\\Users\\sevhe\\OneDrive - McMaster University\\Year 5\\SFRWENG 4G06 - Capstone\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_2.py", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" } diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index df8626de..0a6940a9 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,30 +5,30 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 1.857750001363456e-07, - "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", - "cpu_power": 7.5, - "duration": 0.0899510000599548, - "emissions": 1.2555916317106813e-08, - "emissions_rate": 1.395861781274021e-07, - "energy_consumed": 3.178998595361087e-07, + "cpu_energy": 5.52654464425157e-07, + "cpu_model": "Apple M2", + "cpu_power": 42.5, + "duration": 0.046882959024515, + "emissions": 2.4893036924510844e-08, + "emissions_rate": 5.309613011306374e-07, + "energy_consumed": 6.302600894964094e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 43.266, - "longitude": -79.9441, + "latitude": 43.251, + "longitude": -79.8989, "on_cloud": "N", - "os": "Windows-11-10.0.22631-SP0", + "os": "macOS-14.1.1-arm64-arm-64bit-Mach-O", "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 1.321248593997631e-07, - "ram_power": 6.730809688568115, - "ram_total_size": 17.94882583618164, + "ram_energy": 7.76056250712524e-08, + "ram_power": 6.0, + "ram_total_size": 16.0, "region": "ontario", - "run_id": "e6dacc1b-4c06-473e-b331-a91e669aa4fc", - "timestamp": "2024-11-09T20:30:45", + "run_id": "eca53493-3f9a-4cf5-806b-75e7bf633a3e", + "timestamp": "2024-11-10T00:31:28", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index 9ec702d7..e54926c7 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -5,30 +5,30 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 3.206839583678327e-07, - "cpu_model": "AMD Ryzen 5 3500U with Radeon Vega Mobile Gfx", - "cpu_power": 7.5, - "duration": 0.1550977999577298, - "emissions": 2.1139604900509435e-08, - "emissions_rate": 1.3629854779546062e-07, - "energy_consumed": 5.352279561918346e-07, + "cpu_energy": 5.697469369705585e-07, + "cpu_model": "Apple M2", + "cpu_power": 42.5, + "duration": 0.0483314170269295, + "emissions": 2.5662251215085788e-08, + "emissions_rate": 5.309641801064339e-07, + "energy_consumed": 6.497356187012176e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, "gpu_model": NaN, "gpu_power": 0.0, - "latitude": 43.266, - "longitude": -79.9441, + "latitude": 43.251, + "longitude": -79.8989, "on_cloud": "N", - "os": "Windows-11-10.0.22631-SP0", + "os": "macOS-14.1.1-arm64-arm-64bit-Mach-O", "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 2.14543997824002e-07, - "ram_power": 6.730809688568115, - "ram_total_size": 17.94882583618164, + "ram_energy": 7.998868173065906e-08, + "ram_power": 6.0, + "ram_total_size": 16.0, "region": "ontario", - "run_id": "f9541537-6822-4be0-96f4-63f743584883", - "timestamp": "2024-11-09T20:30:25", + "run_id": "276a0a64-eca8-4f14-87ed-9d9dbc7a403d", + "timestamp": "2024-11-10T00:31:26", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 26a7b15e..27259079 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,66 +1,43 @@ -[2024-11-09 20:30:19] ##################################################################################################### -[2024-11-09 20:30:19] CAPTURE INITIAL EMISSIONS -[2024-11-09 20:30:19] ##################################################################################################### -[2024-11-09 20:30:19] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 20:30:25] CodeCarbon measurement completed successfully. -[2024-11-09 20:30:25] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt -[2024-11-09 20:30:25] Initial Emissions: 2.1139604900509435e-08 kg CO2 -[2024-11-09 20:30:25] ##################################################################################################### - - -[2024-11-09 20:30:25] ##################################################################################################### -[2024-11-09 20:30:25] CAPTURE CODE SMELLS -[2024-11-09 20:30:25] ##################################################################################################### -[2024-11-09 20:30:25] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-09 20:30:27] Pylint analyzer completed successfully. -[2024-11-09 20:30:27] Running custom parsers: -[2024-11-09 20:30:27] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json -[2024-11-09 20:30:27] Filtering pylint smells -[2024-11-09 20:30:27] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json -[2024-11-09 20:30:27] Refactorable code smells: 8 -[2024-11-09 20:30:27] ##################################################################################################### - - -[2024-11-09 20:30:27] ##################################################################################################### -[2024-11-09 20:30:27] REFACTOR CODE SMELLS -[2024-11-09 20:30:27] ##################################################################################################### -[2024-11-09 20:30:27] Refactoring for smell too-many-arguments is not implemented. - -[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. - -[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. - -[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. - -[2024-11-09 20:30:27] Refactoring for smell unused-argument is not implemented. - -[2024-11-09 20:30:27] Applying 'Make Method Static' refactor on 'ineffcient_code_example_2.py' at line 39 for identified code smell. -[2024-11-09 20:30:27] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-09 20:30:33] CodeCarbon measurement completed successfully. -[2024-11-09 20:30:33] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.5226976842757694e-08 -[2024-11-09 20:30:33] Initial Emissions: 2.1139604900509435e-08 kg CO2. Final Emissions: 1.5226976842757694e-08 kg CO2. -[2024-11-09 20:30:33] Refactored list comprehension to generator expression on line 39 and saved. - -[2024-11-09 20:30:33] Applying 'Remove Unused Imports' refactor on 'ineffcient_code_example_2.py' at line 1 for identified code smell. -[2024-11-09 20:30:33] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py.temp -[2024-11-09 20:30:39] CodeCarbon measurement completed successfully. -[2024-11-09 20:30:39] Measured emissions for 'ineffcient_code_example_2.py.temp': 1.4380604164174298e-08 -[2024-11-09 20:30:39] Initial Emissions: 2.1139604900509435e-08 kg CO2. Final Emissions: 1.4380604164174298e-08 kg CO2. -[2024-11-09 20:30:39] Removed unused import on line 1 and saved changes. - -[2024-11-09 20:30:39] Refactoring for smell long-message-chain is not implemented. - -[2024-11-09 20:30:39] ##################################################################################################### - - -[2024-11-09 20:30:39] ##################################################################################################### -[2024-11-09 20:30:39] CAPTURE FINAL EMISSIONS -[2024-11-09 20:30:39] ##################################################################################################### -[2024-11-09 20:30:39] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-09 20:30:45] CodeCarbon measurement completed successfully. -[2024-11-09 20:30:45] Output saved to c:\Users\sevhe\OneDrive - McMaster University\Year 5\SFRWENG 4G06 - Capstone\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt -[2024-11-09 20:30:45] Final Emissions: 1.2555916317106811e-08 kg CO2 -[2024-11-09 20:30:45] ##################################################################################################### - - -[2024-11-09 20:30:45] Saved 8.583688583402624e-09 kg CO2 +[2024-11-10 00:31:23] ##################################################################################################### +[2024-11-10 00:31:23] CAPTURE INITIAL EMISSIONS +[2024-11-10 00:31:23] ##################################################################################################### +[2024-11-10 00:31:23] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 00:31:26] CodeCarbon measurement completed successfully. +[2024-11-10 00:31:26] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-10 00:31:26] Initial Emissions: 2.5662251215085788e-08 kg CO2 +[2024-11-10 00:31:26] ##################################################################################################### + + +[2024-11-10 00:31:26] ##################################################################################################### +[2024-11-10 00:31:26] CAPTURE CODE SMELLS +[2024-11-10 00:31:26] ##################################################################################################### +[2024-11-10 00:31:26] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-10 00:31:27] Pylint analyzer completed successfully. +[2024-11-10 00:31:27] Running custom parsers: +[2024-11-10 00:31:27] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json +[2024-11-10 00:31:27] Filtering pylint smells +[2024-11-10 00:31:27] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-10 00:31:27] Refactorable code smells: 6 +[2024-11-10 00:31:27] ##################################################################################################### + + +[2024-11-10 00:31:27] ##################################################################################################### +[2024-11-10 00:31:27] REFACTOR CODE SMELLS +[2024-11-10 00:31:27] ##################################################################################################### +[2024-11-10 00:31:27] calling refactoring for +[2024-11-10 00:31:27] R0913 +[2024-11-10 00:31:27] Refactoring functions with long parameter lists in /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py +[2024-11-10 00:31:27] ##################################################################################################### + + +[2024-11-10 00:31:27] ##################################################################################################### +[2024-11-10 00:31:27] CAPTURE FINAL EMISSIONS +[2024-11-10 00:31:27] ##################################################################################################### +[2024-11-10 00:31:27] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 00:31:28] CodeCarbon measurement completed successfully. +[2024-11-10 00:31:28] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt +[2024-11-10 00:31:28] Final Emissions: 2.4893036924510844e-08 kg CO2 +[2024-11-10 00:31:28] ##################################################################################################### + + +[2024-11-10 00:31:28] Saved 7.692142905749442e-10 kg CO2 diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 54e65a12..7606e24c 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -1,6 +1,41 @@ +import ast +import astor from .base_refactorer import BaseRefactorer +def get_used_parameters(function_node, params): + """ + Identify parameters that are used within the function body using AST analysis + """ + used_params = set() + source_code = astor.to_source(function_node) + + # Parse the function's source code into an AST tree + tree = ast.parse(source_code) + + # Define a visitor to track parameter usage + class ParamUsageVisitor(ast.NodeVisitor): + def visit_Name(self, node): + if isinstance(node.ctx, ast.Load) and node.id in params: + used_params.add(node.id) + + # Traverse the AST to collect used parameters + ParamUsageVisitor().visit(tree) + + return used_params + + +def create_parameter_object_class(param_names): + """ + Create a class definition for encapsulating parameters as attributes. + """ + class_name = "ParamsObject" + class_def = f"class {class_name}:\n" + init_method = " def __init__(self, {}):\n".format(", ".join(param_names)) + init_body = "".join([f" self.{param} = {param}\n" for param in param_names]) + return class_def + init_method + init_body + + class LongParameterListRefactorer(BaseRefactorer): """ Refactorer that targets methods that take too many arguments @@ -10,5 +45,57 @@ def __init__(self, logger): super().__init__(logger) def refactor(self, file_path, pylint_smell, initial_emission): - # Logic to identify methods that take too many arguments goes here - pass + self.logger.log(f"Refactoring functions with long parameter lists in {file_path}") + + with open(file_path, 'r') as f: + tree = ast.parse(f.read()) + + modified = False + + # Use ast.walk() to find all function definitions + for node in ast.walk(tree): + if isinstance(node, ast.FunctionDef): + params = [arg.arg for arg in node.args.args] + + # Only consider functions with an initial long parameter list + if len(params) > 4: + # Identify parameters that are actually used in function body + used_params = get_used_parameters(node, params) + + # Remove unused parameters + new_args = [arg for arg in node.args.args if arg.arg in used_params] + if len(new_args) != len(node.args.args): # Check if any parameters were removed + node.args.args[:] = new_args # Update in place + modified = True + + # Encapsulate remaining parameters if 4 or more are still used + if len(used_params) >= 4: + + modified = True + param_names = list(used_params) + param_object_code = create_parameter_object_class(param_names) + param_object_ast = ast.parse(param_object_code).body[0] + + # Insert parameter object class at the beginning of the file + tree.body.insert(0, param_object_ast) + + # Modify function to use a single parameter for the parameter object + node.args.args = [ast.arg(arg="params", annotation=None)] + + # Update all parameter usages within the function to access attributes of the parameter object + class ParamAttributeUpdater(ast.NodeTransformer): + def visit_Name(self, node): + if node.id in param_names and isinstance(node.ctx, ast.Load): + return ast.Attribute(value=ast.Name(id="params", ctx=ast.Load()), attr=node.id, + ctx=node.ctx) + return node + + node.body = [ParamAttributeUpdater().visit(stmt) for stmt in node.body] + + if modified: + # Write back modified code to file + # Using temporary file to retain test contents. To see energy reduction remove temp suffix + temp_file_path = f"{file_path}" + with open(temp_file_path, "w") as temp_file: + temp_file.write(astor.to_source(tree)) + diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 6212208a..2bf967ad 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -72,4 +72,5 @@ class AllSmells(ExtendedEnum): "--max-nested-blocks=3", # Limits maximum nesting of blocks "--max-branches=3", # Limits maximum branches in a function "--max-parents=3", # Limits maximum inheritance levels for a class + "--max-args=4" # Limits max parameters for each function signature ] From 6282d2d8124144c4d84d2e41d59f07800fc139cf Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Sun, 10 Nov 2024 01:36:14 -0500 Subject: [PATCH 061/105] Added long param list function example --- tests/input/ineffcient_code_example_2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index ced4fde0..783e87c4 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -32,6 +32,25 @@ def complex_calculation(item, flag1, flag2, operation, threshold, result = item return result + @staticmethod + def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, + max_value, option, final_stage, min_value): + value = 0 + if operation == 'multiply': + value = item1 * item2 * item3 + elif operation == 'add': + value = item1 + item2 + item3 + elif flag1 == 'true': + value = item1 + elif flag2 == 'true': + value = item2 + elif flag3 == 'true': + value = item3 + elif max_value < threshold: + value = max_value + else: + value = min_value + return value class AdvancedProcessor(DataProcessor): From 4bc67054045476ed7412a6ade354f02fc13fbd7c Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Sun, 10 Nov 2024 02:57:40 -0500 Subject: [PATCH 062/105] Refactorer Code standardarization: refactorer naming, PyLint line number, emission check --- .../outputs/all_configured_pylint_smells.json | 39 ++++ src1/outputs/all_pylint_smells.json | 210 +++++++++++++++--- src1/outputs/final_emissions_data.txt | 16 +- src1/outputs/initial_emissions_data.txt | 16 +- src1/outputs/log.txt | 111 +++++---- src1/outputs/refactored-test-case.py | 23 +- .../long_parameter_list_refactorer.py | 39 +++- .../member_ignoring_method_refactorer.py | 2 +- ...factor.py => unused_imports_refactorer.py} | 2 +- ...actor.py => use_a_generator_refactorer.py} | 4 +- src1/utils/refactorer_factory.py | 12 +- 11 files changed, 368 insertions(+), 106 deletions(-) rename src1/refactorers/{unused_imports_refactor.py => unused_imports_refactorer.py} (97%) rename src1/refactorers/{use_a_generator_refactor.py => use_a_generator_refactorer.py} (98%) diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index e7267035..89f6a04b 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -64,6 +64,45 @@ "symbol": "unused-argument", "type": "warning" }, + { + "column": 4, + "endColumn": 31, + "endLine": 36, + "line": 36, + "message": "Too many arguments (12/4)", + "message-id": "R0913", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "column": 43, + "endColumn": 49, + "endLine": 37, + "line": 37, + "message": "Unused argument 'option'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 51, + "endColumn": 62, + "endLine": 37, + "line": 37, + "message": "Unused argument 'final_stage'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, { "absolutePath": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index 0007756c..3919e7a7 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -12,11 +12,24 @@ "symbol": "trailing-whitespace", "type": "convention" }, + { + "column": 0, + "endColumn": null, + "endLine": null, + "line": 36, + "message": "Line too long (95/80)", + "message-id": "C0301", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "line-too-long", + "type": "convention" + }, { "column": 71, "endColumn": null, "endLine": null, - "line": 40, + "line": 59, "message": "Trailing whitespace", "message-id": "C0303", "module": "ineffcient_code_example_2", @@ -221,10 +234,153 @@ "type": "warning" }, { - "column": 0, - "endColumn": 23, + "column": 4, + "endColumn": 31, + "endLine": 36, + "line": 36, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "missing-function-docstring", + "type": "convention" + }, + { + "column": 4, + "endColumn": 31, + "endLine": 36, + "line": 36, + "message": "Too many arguments (12/4)", + "message-id": "R0913", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "too-many-arguments", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 31, + "endLine": 36, + "line": 36, + "message": "Too many positional arguments (12/5)", + "message-id": "R0917", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "too-many-positional-arguments", + "type": "refactor" + }, + { + "column": 11, + "endColumn": 34, + "endLine": 39, + "line": 39, + "message": "Consider using a named constant or an enum instead of ''multiply''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 13, + "endColumn": 31, + "endLine": 41, + "line": 41, + "message": "Consider using a named constant or an enum instead of ''add''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 13, + "endColumn": 28, + "endLine": 43, + "line": 43, + "message": "Consider using a named constant or an enum instead of ''true''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 13, + "endColumn": 28, + "endLine": 45, + "line": 45, + "message": "Consider using a named constant or an enum instead of ''true''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 13, + "endColumn": 28, + "endLine": 47, + "line": 47, + "message": "Consider using a named constant or an enum instead of ''true''.", + "message-id": "R2004", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "magic-value-comparison", + "type": "refactor" + }, + { + "column": 4, + "endColumn": 31, "endLine": 36, "line": 36, + "message": "Too many branches (7/3)", + "message-id": "R0912", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "too-many-branches", + "type": "refactor" + }, + { + "column": 43, + "endColumn": 49, + "endLine": 37, + "line": 37, + "message": "Unused argument 'option'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 51, + "endColumn": 62, + "endLine": 37, + "line": 37, + "message": "Unused argument 'final_stage'", + "message-id": "W0613", + "module": "ineffcient_code_example_2", + "obj": "DataProcessor.multi_param_calculation", + "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "symbol": "unused-argument", + "type": "warning" + }, + { + "column": 0, + "endColumn": 23, + "endLine": 55, + "line": 55, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", @@ -236,8 +392,8 @@ { "column": 4, "endColumn": 18, - "endLine": 39, - "line": 39, + "endLine": 58, + "line": 58, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -249,8 +405,8 @@ { "column": 24, "endColumn": 33, - "endLine": 40, - "line": 40, + "endLine": 59, + "line": 59, "message": "Consider using a named constant or an enum instead of '10'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -262,8 +418,8 @@ { "column": 4, "endColumn": 29, - "endLine": 43, - "line": 43, + "endLine": 62, + "line": 62, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -275,8 +431,8 @@ { "column": 44, "endColumn": 51, - "endLine": 45, - "line": 45, + "endLine": 64, + "line": 64, "message": "Consider using a named constant or an enum instead of '50'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -288,8 +444,8 @@ { "column": 56, "endColumn": 61, - "endLine": 45, - "line": 45, + "endLine": 64, + "line": 64, "message": "Consider using a named constant or an enum instead of '3'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -301,8 +457,8 @@ { "column": 4, "endColumn": 18, - "endLine": 47, - "line": 47, + "endLine": 66, + "line": 66, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -314,8 +470,8 @@ { "column": 8, "endColumn": 23, - "endLine": 53, - "line": 48, + "endLine": 72, + "line": 67, "message": "try clause contains 2 statements, expected at most 1", "message-id": "W0717", "module": "ineffcient_code_example_2", @@ -327,8 +483,8 @@ { "column": 4, "endColumn": 27, - "endLine": 56, - "line": 56, + "endLine": 75, + "line": 75, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", @@ -340,8 +496,8 @@ { "column": 31, "endColumn": 53, - "endLine": 62, - "line": 62, + "endLine": 81, + "line": 81, "message": "Consider using a named constant or an enum instead of '25'.", "message-id": "R2004", "module": "ineffcient_code_example_2", @@ -353,8 +509,8 @@ { "column": 4, "endColumn": 27, - "endLine": 56, - "line": 56, + "endLine": 75, + "line": 75, "message": "Too many branches (6/3)", "message-id": "R0912", "module": "ineffcient_code_example_2", @@ -366,8 +522,8 @@ { "column": 8, "endColumn": 45, - "endLine": 63, - "line": 57, + "endLine": 82, + "line": 76, "message": "Too many nested blocks (6/3)", "message-id": "R1702", "module": "ineffcient_code_example_2", @@ -379,8 +535,8 @@ { "column": 4, "endColumn": 27, - "endLine": 56, - "line": 56, + "endLine": 75, + "line": 75, "message": "Either all return statements in a function should return an expression, or none of them should.", "message-id": "R1710", "module": "ineffcient_code_example_2", diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index 0a6940a9..d37401ae 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 5.52654464425157e-07, + "cpu_energy": 3.003702256036276e-07, "cpu_model": "Apple M2", "cpu_power": 42.5, - "duration": 0.046882959024515, - "emissions": 2.4893036924510844e-08, - "emissions_rate": 5.309613011306374e-07, - "energy_consumed": 6.302600894964094e-07, + "duration": 0.0254877919796854, + "emissions": 1.3525703072495e-08, + "emissions_rate": 5.306737862297139e-07, + "energy_consumed": 3.424536288932561e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 7.76056250712524e-08, + "ram_energy": 4.2083403289628536e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "eca53493-3f9a-4cf5-806b-75e7bf633a3e", - "timestamp": "2024-11-10T00:31:28", + "run_id": "2edf2d17-eefe-4491-9842-04aca78c93f4", + "timestamp": "2024-11-10T02:53:51", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index e54926c7..1dd1e0c8 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 5.697469369705585e-07, + "cpu_energy": 5.022663815907436e-07, "cpu_model": "Apple M2", "cpu_power": 42.5, - "duration": 0.0483314170269295, - "emissions": 2.5662251215085788e-08, - "emissions_rate": 5.309641801064339e-07, - "energy_consumed": 6.497356187012176e-07, + "duration": 0.0426126250531524, + "emissions": 2.2623199453866972e-08, + "emissions_rate": 5.309036799692144e-07, + "energy_consumed": 5.727906866377453e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 7.998868173065906e-08, + "ram_energy": 7.05243050470017e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "276a0a64-eca8-4f14-87ed-9d9dbc7a403d", - "timestamp": "2024-11-10T00:31:26", + "run_id": "a82a45da-f88f-4f89-bcfd-8cf5b8e6e1dd", + "timestamp": "2024-11-10T02:53:49", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 27259079..83302928 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,43 +1,68 @@ -[2024-11-10 00:31:23] ##################################################################################################### -[2024-11-10 00:31:23] CAPTURE INITIAL EMISSIONS -[2024-11-10 00:31:23] ##################################################################################################### -[2024-11-10 00:31:23] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 00:31:26] CodeCarbon measurement completed successfully. -[2024-11-10 00:31:26] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-10 00:31:26] Initial Emissions: 2.5662251215085788e-08 kg CO2 -[2024-11-10 00:31:26] ##################################################################################################### - - -[2024-11-10 00:31:26] ##################################################################################################### -[2024-11-10 00:31:26] CAPTURE CODE SMELLS -[2024-11-10 00:31:26] ##################################################################################################### -[2024-11-10 00:31:26] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-10 00:31:27] Pylint analyzer completed successfully. -[2024-11-10 00:31:27] Running custom parsers: -[2024-11-10 00:31:27] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json -[2024-11-10 00:31:27] Filtering pylint smells -[2024-11-10 00:31:27] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-10 00:31:27] Refactorable code smells: 6 -[2024-11-10 00:31:27] ##################################################################################################### - - -[2024-11-10 00:31:27] ##################################################################################################### -[2024-11-10 00:31:27] REFACTOR CODE SMELLS -[2024-11-10 00:31:27] ##################################################################################################### -[2024-11-10 00:31:27] calling refactoring for -[2024-11-10 00:31:27] R0913 -[2024-11-10 00:31:27] Refactoring functions with long parameter lists in /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py -[2024-11-10 00:31:27] ##################################################################################################### - - -[2024-11-10 00:31:27] ##################################################################################################### -[2024-11-10 00:31:27] CAPTURE FINAL EMISSIONS -[2024-11-10 00:31:27] ##################################################################################################### -[2024-11-10 00:31:27] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 00:31:28] CodeCarbon measurement completed successfully. -[2024-11-10 00:31:28] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt -[2024-11-10 00:31:28] Final Emissions: 2.4893036924510844e-08 kg CO2 -[2024-11-10 00:31:28] ##################################################################################################### - - -[2024-11-10 00:31:28] Saved 7.692142905749442e-10 kg CO2 +[2024-11-10 02:53:46] ##################################################################################################### +[2024-11-10 02:53:46] CAPTURE INITIAL EMISSIONS +[2024-11-10 02:53:46] ##################################################################################################### +[2024-11-10 02:53:46] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 02:53:49] CodeCarbon measurement completed successfully. +[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-10 02:53:49] Initial Emissions: 2.262319945386697e-08 kg CO2 +[2024-11-10 02:53:49] ##################################################################################################### + + +[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 02:53:49] CAPTURE CODE SMELLS +[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 02:53:49] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-10 02:53:49] Pylint analyzer completed successfully. +[2024-11-10 02:53:49] Running custom parsers: +[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json +[2024-11-10 02:53:49] Filtering pylint smells +[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-10 02:53:49] Refactorable code smells: 9 +[2024-11-10 02:53:49] ##################################################################################################### + + +[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 02:53:49] REFACTOR CODE SMELLS +[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 02:53:49] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 25 for identified code smell. +[2024-11-10 02:53:49] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. +[2024-11-10 02:53:51] Measured emissions for 'ineffcient_code_example_2_temp.py': 2.4512068473223318e-08 +[2024-11-10 02:53:51] Initial Emissions: 2.262319945386697e-08 kg CO2. Final Emissions: 2.4512068473223318e-08 kg CO2. +[2024-11-10 02:53:51] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 36 for identified code smell. +[2024-11-10 02:53:51] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. +[2024-11-10 02:53:51] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.3771534919678223e-08 +[2024-11-10 02:53:51] Initial Emissions: 2.262319945386697e-08 kg CO2. Final Emissions: 1.3771534919678223e-08 kg CO2. +[2024-11-10 02:53:51] Refactored list comprehension to generator expression on line 36 and saved. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. + +[2024-11-10 02:53:51] Refactoring for smell long-message-chain is not implemented. + +[2024-11-10 02:53:51] ##################################################################################################### + + +[2024-11-10 02:53:51] ##################################################################################################### +[2024-11-10 02:53:51] CAPTURE FINAL EMISSIONS +[2024-11-10 02:53:51] ##################################################################################################### +[2024-11-10 02:53:51] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. +[2024-11-10 02:53:51] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt +[2024-11-10 02:53:51] Final Emissions: 1.3525703072495e-08 kg CO2 +[2024-11-10 02:53:51] ##################################################################################################### + + +[2024-11-10 02:53:51] Saved 9.097496381371968e-09 kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index a7ea800c..783e87c4 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,4 +1,3 @@ -import datetime class DataProcessor: @@ -33,10 +32,30 @@ def complex_calculation(item, flag1, flag2, operation, threshold, result = item return result + @staticmethod + def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, + max_value, option, final_stage, min_value): + value = 0 + if operation == 'multiply': + value = item1 * item2 * item3 + elif operation == 'add': + value = item1 + item2 + item3 + elif flag1 == 'true': + value = item1 + elif flag2 == 'true': + value = item2 + elif flag3 == 'true': + value = item3 + elif max_value < threshold: + value = max_value + else: + value = min_value + return value class AdvancedProcessor(DataProcessor): - def check_data(self, item): + @staticmethod + def check_data(item): return (True if item > 10 else False if item < -10 else None if item == 0 else item) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 7606e24c..71828085 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -1,11 +1,14 @@ import ast +import os +import shutil + import astor from .base_refactorer import BaseRefactorer def get_used_parameters(function_node, params): """ - Identify parameters that are used within the function body using AST analysis + Identifies parameters that are used within the function body using AST analysis """ used_params = set() source_code = astor.to_source(function_node) @@ -38,23 +41,28 @@ def create_parameter_object_class(param_names): class LongParameterListRefactorer(BaseRefactorer): """ - Refactorer that targets methods that take too many arguments + Refactorer that targets methods in source code that take too many parameters """ def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path, pylint_smell, initial_emission): - self.logger.log(f"Refactoring functions with long parameter lists in {file_path}") - + def refactor(self, file_path, pylint_smell, initial_emissions): + """ + Identifies methods with too many parameters, encapsulating related ones & removing unused ones + """ + target_line = pylint_smell["line"] + self.logger.log( + f"Applying 'Fix Too Many Parameters' refactor on '{os.path.basename(file_path)}' at line {target_line} for identified code smell." + ) with open(file_path, 'r') as f: tree = ast.parse(f.read()) modified = False - # Use ast.walk() to find all function definitions + # Find function definitions at the specific line number for node in ast.walk(tree): - if isinstance(node, ast.FunctionDef): + if isinstance(node, ast.FunctionDef) and node.lineno == target_line: params = [arg.arg for arg in node.args.args] # Only consider functions with an initial long parameter list @@ -95,7 +103,22 @@ def visit_Name(self, node): if modified: # Write back modified code to file # Using temporary file to retain test contents. To see energy reduction remove temp suffix - temp_file_path = f"{file_path}" + temp_file_path = f"{os.path.basename(file_path).split(".")[0]}_temp.py" with open(temp_file_path, "w") as temp_file: temp_file.write(astor.to_source(tree)) + # Measure emissions of the modified code + final_emission = self.measure_energy(temp_file_path) + + if self.check_energy_improvement(initial_emissions, final_emission): + # If improved, replace the original file with the modified content + shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored list comprehension to generator expression on line {target_line} and saved.\n" + ) + else: + # Remove the temporary file if no improvement + os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) \ No newline at end of file diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src1/refactorers/member_ignoring_method_refactorer.py index cebad43c..baacfd73 100644 --- a/src1/refactorers/member_ignoring_method_refactorer.py +++ b/src1/refactorers/member_ignoring_method_refactorer.py @@ -7,7 +7,7 @@ from .base_refactorer import BaseRefactorer -class MakeStaticRefactor(BaseRefactorer, NodeTransformer): +class MakeStaticRefactorer(BaseRefactorer, NodeTransformer): """ Refactorer that targets methods that don't use any class attributes and makes them static to improve performance """ diff --git a/src1/refactorers/unused_imports_refactor.py b/src1/refactorers/unused_imports_refactorer.py similarity index 97% rename from src1/refactorers/unused_imports_refactor.py rename to src1/refactorers/unused_imports_refactorer.py index b62c3938..d7f16bce 100644 --- a/src1/refactorers/unused_imports_refactor.py +++ b/src1/refactorers/unused_imports_refactorer.py @@ -2,7 +2,7 @@ import shutil from refactorers.base_refactorer import BaseRefactorer -class RemoveUnusedImportsRefactor(BaseRefactorer): +class RemoveUnusedImportsRefactorer(BaseRefactorer): def __init__(self, logger): """ Initializes the RemoveUnusedImportsRefactor with the specified logger. diff --git a/src1/refactorers/use_a_generator_refactor.py b/src1/refactorers/use_a_generator_refactorer.py similarity index 98% rename from src1/refactorers/use_a_generator_refactor.py rename to src1/refactorers/use_a_generator_refactorer.py index 7355c2a6..dcf991f9 100644 --- a/src1/refactorers/use_a_generator_refactor.py +++ b/src1/refactorers/use_a_generator_refactorer.py @@ -1,4 +1,4 @@ -# refactorers/use_a_generator_refactor.py +# refactorers/use_a_generator_refactorer.py import ast import astor # For converting AST back to source code @@ -7,7 +7,7 @@ from .base_refactorer import BaseRefactorer -class UseAGeneratorRefactor(BaseRefactorer): +class UseAGeneratorRefactorer(BaseRefactorer): def __init__(self, logger): """ Initializes the UseAGeneratorRefactor with a file path, pylint diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index 2aa64a5b..b38ce1db 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -1,8 +1,8 @@ # Import specific refactorer classes -from refactorers.use_a_generator_refactor import UseAGeneratorRefactor -from refactorers.unused_imports_refactor import RemoveUnusedImportsRefactor +from refactorers.use_a_generator_refactorer import UseAGeneratorRefactorer +from refactorers.unused_imports_refactorer import RemoveUnusedImportsRefactorer from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer -from refactorers.member_ignoring_method_refactorer import MakeStaticRefactor +from refactorers.member_ignoring_method_refactorer import MakeStaticRefactorer from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells @@ -35,11 +35,11 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): # Use match statement to select the appropriate refactorer based on smell message ID match smell_messageID: case AllSmells.USE_A_GENERATOR.value: - selected = UseAGeneratorRefactor(logger) + selected = UseAGeneratorRefactorer(logger) case AllSmells.UNUSED_IMPORT.value: - selected = RemoveUnusedImportsRefactor(logger) + selected = RemoveUnusedImportsRefactorer(logger) case AllSmells.NO_SELF_USE.value: - selected = MakeStaticRefactor(logger) + selected = MakeStaticRefactorer(logger) case AllSmells.LONG_PARAMETER_LIST.value: selected = LongParameterListRefactorer(logger) case _: From 0e9bb17d5fe538f4ae1df4c33090f19ff46a73ea Mon Sep 17 00:00:00 2001 From: tbrar06 Date: Sun, 10 Nov 2024 14:42:33 -0500 Subject: [PATCH 063/105] Added parameter grouping for Long Parameter List refactoring. Updated threshold for PyLint smell detection --- .../outputs/all_configured_pylint_smells.json | 4 +- src1/outputs/all_pylint_smells.json | 4 +- src1/outputs/final_emissions_data.txt | 16 +-- src1/outputs/initial_emissions_data.txt | 16 +-- src1/outputs/log.txt | 102 +++++++++--------- .../long_parameter_list_refactorer.py | 70 ++++++++---- src1/utils/analyzers_config.py | 2 +- 7 files changed, 121 insertions(+), 93 deletions(-) diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index 89f6a04b..5e793930 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -4,7 +4,7 @@ "endColumn": 27, "endLine": 25, "line": 25, - "message": "Too many arguments (8/4)", + "message": "Too many arguments (8/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", @@ -69,7 +69,7 @@ "endColumn": 31, "endLine": 36, "line": 36, - "message": "Too many arguments (12/4)", + "message": "Too many arguments (12/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index 3919e7a7..e9e3af86 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -134,7 +134,7 @@ "endColumn": 27, "endLine": 25, "line": 25, - "message": "Too many arguments (8/4)", + "message": "Too many arguments (8/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", @@ -251,7 +251,7 @@ "endColumn": 31, "endLine": 36, "line": 36, - "message": "Too many arguments (12/4)", + "message": "Too many arguments (12/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index d37401ae..eb1e3741 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 3.003702256036276e-07, + "cpu_energy": 3.2149725892749204e-07, "cpu_model": "Apple M2", "cpu_power": 42.5, - "duration": 0.0254877919796854, - "emissions": 1.3525703072495e-08, - "emissions_rate": 5.306737862297139e-07, - "energy_consumed": 3.424536288932561e-07, + "duration": 0.0272803339757956, + "emissions": 1.4478415866039985e-08, + "emissions_rate": 5.307272219939055e-07, + "energy_consumed": 3.665751072144809e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 4.2083403289628536e-08, + "ram_energy": 4.507784828698883e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "2edf2d17-eefe-4491-9842-04aca78c93f4", - "timestamp": "2024-11-10T02:53:51", + "run_id": "245d27f5-0cbb-4ba2-88d2-224d2dd50971", + "timestamp": "2024-11-10T14:37:26", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index 1dd1e0c8..4681b3a1 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -5,13 +5,13 @@ "country_iso_code": "CAN", "country_name": "Canada", "cpu_count": 8, - "cpu_energy": 5.022663815907436e-07, + "cpu_energy": 5.288313370935308e-07, "cpu_model": "Apple M2", "cpu_power": 42.5, - "duration": 0.0426126250531524, - "emissions": 2.2623199453866972e-08, - "emissions_rate": 5.309036799692144e-07, - "energy_consumed": 5.727906866377453e-07, + "duration": 0.0448683750000782, + "emissions": 2.3819676859384504e-08, + "emissions_rate": 5.308789734271182e-07, + "energy_consumed": 6.030839754384942e-07, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": NaN, "gpu_energy": 0, @@ -24,11 +24,11 @@ "project_name": "codecarbon", "pue": 1.0, "python_version": "3.13.0", - "ram_energy": 7.05243050470017e-08, + "ram_energy": 7.42526383449634e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "a82a45da-f88f-4f89-bcfd-8cf5b8e6e1dd", - "timestamp": "2024-11-10T02:53:49", + "run_id": "2925eed2-f0e4-4409-99cd-3da5a7d75c64", + "timestamp": "2024-11-10T14:37:24", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 83302928..1ca88c70 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,68 +1,68 @@ -[2024-11-10 02:53:46] ##################################################################################################### -[2024-11-10 02:53:46] CAPTURE INITIAL EMISSIONS -[2024-11-10 02:53:46] ##################################################################################################### -[2024-11-10 02:53:46] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 02:53:49] CodeCarbon measurement completed successfully. -[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-10 02:53:49] Initial Emissions: 2.262319945386697e-08 kg CO2 -[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 14:37:21] ##################################################################################################### +[2024-11-10 14:37:21] CAPTURE INITIAL EMISSIONS +[2024-11-10 14:37:21] ##################################################################################################### +[2024-11-10 14:37:21] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 14:37:24] CodeCarbon measurement completed successfully. +[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-10 14:37:24] Initial Emissions: 2.3819676859384504e-08 kg CO2 +[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 02:53:49] ##################################################################################################### -[2024-11-10 02:53:49] CAPTURE CODE SMELLS -[2024-11-10 02:53:49] ##################################################################################################### -[2024-11-10 02:53:49] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-10 02:53:49] Pylint analyzer completed successfully. -[2024-11-10 02:53:49] Running custom parsers: -[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json -[2024-11-10 02:53:49] Filtering pylint smells -[2024-11-10 02:53:49] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-10 02:53:49] Refactorable code smells: 9 -[2024-11-10 02:53:49] ##################################################################################################### +[2024-11-10 14:37:24] ##################################################################################################### +[2024-11-10 14:37:24] CAPTURE CODE SMELLS +[2024-11-10 14:37:24] ##################################################################################################### +[2024-11-10 14:37:24] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-10 14:37:24] Pylint analyzer completed successfully. +[2024-11-10 14:37:24] Running custom parsers: +[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json +[2024-11-10 14:37:24] Filtering pylint smells +[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-10 14:37:24] Refactorable code smells: 9 +[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 02:53:49] ##################################################################################################### -[2024-11-10 02:53:49] REFACTOR CODE SMELLS -[2024-11-10 02:53:49] ##################################################################################################### -[2024-11-10 02:53:49] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 25 for identified code smell. -[2024-11-10 02:53:49] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. -[2024-11-10 02:53:51] Measured emissions for 'ineffcient_code_example_2_temp.py': 2.4512068473223318e-08 -[2024-11-10 02:53:51] Initial Emissions: 2.262319945386697e-08 kg CO2. Final Emissions: 2.4512068473223318e-08 kg CO2. -[2024-11-10 02:53:51] No emission improvement after refactoring. Discarded refactored changes. +[2024-11-10 14:37:24] ##################################################################################################### +[2024-11-10 14:37:24] REFACTOR CODE SMELLS +[2024-11-10 14:37:24] ##################################################################################################### +[2024-11-10 14:37:24] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 25 for identified code smell. +[2024-11-10 14:37:24] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. +[2024-11-10 14:37:26] Measured emissions for 'ineffcient_code_example_2_temp.py': 2.9212009369852857e-08 +[2024-11-10 14:37:26] Initial Emissions: 2.3819676859384504e-08 kg CO2. Final Emissions: 2.9212009369852857e-08 kg CO2. +[2024-11-10 14:37:26] No emission improvement after refactoring. Discarded refactored changes. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 36 for identified code smell. -[2024-11-10 02:53:51] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. -[2024-11-10 02:53:51] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.3771534919678223e-08 -[2024-11-10 02:53:51] Initial Emissions: 2.262319945386697e-08 kg CO2. Final Emissions: 1.3771534919678223e-08 kg CO2. -[2024-11-10 02:53:51] Refactored list comprehension to generator expression on line 36 and saved. +[2024-11-10 14:37:26] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 36 for identified code smell. +[2024-11-10 14:37:26] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. +[2024-11-10 14:37:26] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.3589692780774065e-08 +[2024-11-10 14:37:26] Initial Emissions: 2.3819676859384504e-08 kg CO2. Final Emissions: 1.3589692780774065e-08 kg CO2. +[2024-11-10 14:37:26] Refactored list comprehension to generator expression on line 36 and saved. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Refactoring for smell unused-argument is not implemented. +[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. -[2024-11-10 02:53:51] Refactoring for smell long-message-chain is not implemented. +[2024-11-10 14:37:26] Refactoring for smell long-message-chain is not implemented. -[2024-11-10 02:53:51] ##################################################################################################### +[2024-11-10 14:37:26] ##################################################################################################### -[2024-11-10 02:53:51] ##################################################################################################### -[2024-11-10 02:53:51] CAPTURE FINAL EMISSIONS -[2024-11-10 02:53:51] ##################################################################################################### -[2024-11-10 02:53:51] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 02:53:51] CodeCarbon measurement completed successfully. -[2024-11-10 02:53:51] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt -[2024-11-10 02:53:51] Final Emissions: 1.3525703072495e-08 kg CO2 -[2024-11-10 02:53:51] ##################################################################################################### +[2024-11-10 14:37:26] ##################################################################################################### +[2024-11-10 14:37:26] CAPTURE FINAL EMISSIONS +[2024-11-10 14:37:26] ##################################################################################################### +[2024-11-10 14:37:26] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. +[2024-11-10 14:37:26] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt +[2024-11-10 14:37:26] Final Emissions: 1.4478415866039985e-08 kg CO2 +[2024-11-10 14:37:26] ##################################################################################################### -[2024-11-10 02:53:51] Saved 9.097496381371968e-09 kg CO2 +[2024-11-10 14:37:26] Saved 9.34126099334452e-09 kg CO2 diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 71828085..f6d1f082 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -28,11 +28,26 @@ def visit_Name(self, node): return used_params -def create_parameter_object_class(param_names): +def classify_parameters(params): """ - Create a class definition for encapsulating parameters as attributes. + Classifies parameters into 'data' and 'config' groups based on naming conventions + """ + data_params = [] + config_params = [] + + for param in params: + if param.startswith(('config', 'flag', 'option', 'setting')): + config_params.append(param) + else: + data_params.append(param) + + return data_params, config_params + + +def create_parameter_object_class(param_names, class_name="ParamsObject"): + """ + Creates a class definition for encapsulating parameters as attributes """ - class_name = "ParamsObject" class_def = f"class {class_name}:\n" init_method = " def __init__(self, {}):\n".format(", ".join(param_names)) init_body = "".join([f" self.{param} = {param}\n" for param in param_names]) @@ -58,6 +73,7 @@ def refactor(self, file_path, pylint_smell, initial_emissions): with open(file_path, 'r') as f: tree = ast.parse(f.read()) + # Flag indicating if a refactoring has been made modified = False # Find function definitions at the specific line number @@ -66,43 +82,55 @@ def refactor(self, file_path, pylint_smell, initial_emissions): params = [arg.arg for arg in node.args.args] # Only consider functions with an initial long parameter list - if len(params) > 4: + if len(params) > 6: # Identify parameters that are actually used in function body used_params = get_used_parameters(node, params) # Remove unused parameters - new_args = [arg for arg in node.args.args if arg.arg in used_params] - if len(new_args) != len(node.args.args): # Check if any parameters were removed - node.args.args[:] = new_args # Update in place + new_params = [arg for arg in node.args.args if arg.arg in used_params] + if len(new_params) != len(node.args.args): # Check if any parameters were removed + node.args.args[:] = new_params # Update in place modified = True # Encapsulate remaining parameters if 4 or more are still used - if len(used_params) >= 4: - + if len(used_params) >= 6: modified = True param_names = list(used_params) - param_object_code = create_parameter_object_class(param_names) - param_object_ast = ast.parse(param_object_code).body[0] - # Insert parameter object class at the beginning of the file - tree.body.insert(0, param_object_ast) + # Classify parameters into data and configuration groups + data_params, config_params = classify_parameters(param_names) + + # Create parameter object classes for each group + if data_params: + data_param_object_code = create_parameter_object_class(data_params, class_name="DataParams") + data_param_object_ast = ast.parse(data_param_object_code).body[0] + tree.body.insert(0, data_param_object_ast) - # Modify function to use a single parameter for the parameter object - node.args.args = [ast.arg(arg="params", annotation=None)] + if config_params: + config_param_object_code = create_parameter_object_class(config_params, + class_name="ConfigParams") + config_param_object_ast = ast.parse(config_param_object_code).body[0] + tree.body.insert(0, config_param_object_ast) - # Update all parameter usages within the function to access attributes of the parameter object + # Modify function to use two parameters for the parameter objects + node.args.args = [ast.arg(arg="data_params", annotation=None), + ast.arg(arg="config_params", annotation=None)] + + # Update all parameter usages within the function to access attributes of the parameter objects class ParamAttributeUpdater(ast.NodeTransformer): def visit_Name(self, node): - if node.id in param_names and isinstance(node.ctx, ast.Load): - return ast.Attribute(value=ast.Name(id="params", ctx=ast.Load()), attr=node.id, + if node.id in data_params and isinstance(node.ctx, ast.Load): + return ast.Attribute(value=ast.Name(id="data_params", ctx=ast.Load()), attr=node.id, ctx=node.ctx) + elif node.id in config_params and isinstance(node.ctx, ast.Load): + return ast.Attribute(value=ast.Name(id="config_params", ctx=ast.Load()), + attr=node.id, ctx=node.ctx) return node node.body = [ParamAttributeUpdater().visit(stmt) for stmt in node.body] if modified: - # Write back modified code to file - # Using temporary file to retain test contents. To see energy reduction remove temp suffix + # Write back modified code to temporary file temp_file_path = f"{os.path.basename(file_path).split(".")[0]}_temp.py" with open(temp_file_path, "w") as temp_file: temp_file.write(astor.to_source(tree)) @@ -121,4 +149,4 @@ def visit_Name(self, node): os.remove(temp_file_path) self.logger.log( "No emission improvement after refactoring. Discarded refactored changes.\n" - ) \ No newline at end of file + ) diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index 2bf967ad..f6eff7ac 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -72,5 +72,5 @@ class AllSmells(ExtendedEnum): "--max-nested-blocks=3", # Limits maximum nesting of blocks "--max-branches=3", # Limits maximum branches in a function "--max-parents=3", # Limits maximum inheritance levels for a class - "--max-args=4" # Limits max parameters for each function signature + "--max-args=6" # Limits max parameters for each function signature ] From 14169c300f439ed9a585b4c0a4ce7736323206d0 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sun, 10 Nov 2024 15:42:00 -0500 Subject: [PATCH 064/105] added correct success message to long param list refactor --- src1/refactorers/long_parameter_list_refactorer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index f6d1f082..770df6b2 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -142,7 +142,7 @@ def visit_Name(self, node): # If improved, replace the original file with the modified content shutil.move(temp_file_path, file_path) self.logger.log( - f"Refactored list comprehension to generator expression on line {target_line} and saved.\n" + f"Refactored long parameter list into data groups on line {target_line} and saved.\n" ) else: # Remove the temporary file if no improvement From b04614b74bf183030bc6df0cf41ebdd6b78e5689 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 13:05:40 -0800 Subject: [PATCH 065/105] renamed and added refactor for unused variables and class attributes --- ...rts_refactorer.py => unused_refactorer.py} | 31 +++++++++++++------ src1/utils/analyzers_config.py | 3 -- src1/utils/refactorer_factory.py | 6 ++-- 3 files changed, 25 insertions(+), 15 deletions(-) rename src1/refactorers/{unused_imports_refactorer.py => unused_refactorer.py} (67%) diff --git a/src1/refactorers/unused_imports_refactorer.py b/src1/refactorers/unused_refactorer.py similarity index 67% rename from src1/refactorers/unused_imports_refactorer.py rename to src1/refactorers/unused_refactorer.py index d7f16bce..3bca8690 100644 --- a/src1/refactorers/unused_imports_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -2,10 +2,10 @@ import shutil from refactorers.base_refactorer import BaseRefactorer -class RemoveUnusedImportsRefactorer(BaseRefactorer): +class RemoveUnusedRefactorer(BaseRefactorer): def __init__(self, logger): """ - Initializes the RemoveUnusedImportsRefactor with the specified logger. + Initializes the RemoveUnusedRefactor with the specified logger. :param logger: Logger instance to handle log messages. """ @@ -13,7 +13,7 @@ def __init__(self, logger): def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ - Refactors unused imports by removing lines where they appear. + Refactors unused imports, variables and class attributes by removing lines where they appear. Modifies the specified instance in the file if it results in lower emissions. :param file_path: Path to the file to be refactored. @@ -21,6 +21,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa :param initial_emission: Initial emission value before refactoring. """ line_number = pylint_smell.get("line") + code_type = pylint_smell.get("code") self.logger.log( f"Applying 'Remove Unused Imports' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." ) @@ -34,10 +35,24 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa self.logger.log("Specified line number is out of bounds.\n") return - # Remove the specified line if it's an unused import + # remove specified line modified_lines = original_lines[:] del modified_lines[line_number - 1] + # for logging purpose to see what was removed + if code_type == "W0611": # UNUSED_IMPORT + self.logger.log("Removed unused import.") + + elif code_type == "W0612": # UNUSED_VARIABLE + self.logger.log("Removed unused variable.") + + elif code_type == "W0615": # UNUSED_CLASS_ATTRIBUTE + self.logger.log("Removed unused class attribute.") + + else: + self.logger.log("No matching refactor type found for this code smell but line was removed.") + return + # Write the modified content to a temporary file temp_file_path = f"{file_path}.temp" with open(temp_file_path, "w") as temp_file: @@ -46,16 +61,14 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Measure emissions of the modified code final_emissions = self.measure_energy(temp_file_path) - # Check for improvement in emissions + shutil.move(temp_file_path, file_path) + + # check for improvement in emissions (for logging purposes only) if self.check_energy_improvement(initial_emissions, final_emissions): - # Replace the original file with the modified content if improved - shutil.move(temp_file_path, file_path) self.logger.log( f"Removed unused import on line {line_number} and saved changes.\n" ) else: - # Remove the temporary file if no improvement - os.remove(temp_file_path) self.logger.log( "No emission improvement after refactoring. Discarded refactored changes.\n" ) \ No newline at end of file diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index f6eff7ac..daf12127 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -35,9 +35,6 @@ class PylintSmell(ExtendedEnum): UNUSED_VARIABLE = ( "W0612" # Pylint code smell for unused variable ) - UNUSED_ARGUMENT = ( - "W0613" # Pylint code smell for unused function or method argument - ) UNUSED_CLASS_ATTRIBUTE = ( "W0615" # Pylint code smell for unused class attribute ) diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index b38ce1db..35050975 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -1,6 +1,6 @@ # Import specific refactorer classes from refactorers.use_a_generator_refactorer import UseAGeneratorRefactorer -from refactorers.unused_imports_refactorer import RemoveUnusedImportsRefactorer +from refactorers.unused_refactorer import RemoveUnusedRefactorer from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer from refactorers.member_ignoring_method_refactorer import MakeStaticRefactorer from refactorers.base_refactorer import BaseRefactorer @@ -36,8 +36,8 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): match smell_messageID: case AllSmells.USE_A_GENERATOR.value: selected = UseAGeneratorRefactorer(logger) - case AllSmells.UNUSED_IMPORT.value: - selected = RemoveUnusedImportsRefactorer(logger) + case (AllSmells.UNUSED_IMPORT.value, AllSmells.UNUSED_VARIABLE.value, AllSmells.UNUSED_CLASS_ATTRIBUTE.value): + selected = RemoveUnusedRefactorer(logger) case AllSmells.NO_SELF_USE.value: selected = MakeStaticRefactorer(logger) case AllSmells.LONG_PARAMETER_LIST.value: From 55b8c4b3f536996773134e1698cb722134a63d7b Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 13:15:34 -0800 Subject: [PATCH 066/105] fixed silly issues and added to test case --- src1/refactorers/unused_refactorer.py | 3 +- src1/utils/refactorer_factory.py | 6 +++- tests/input/ineffcient_code_example_2.py | 37 +++++++++++++----------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index 3bca8690..8b40564b 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -21,7 +21,8 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa :param initial_emission: Initial emission value before refactoring. """ line_number = pylint_smell.get("line") - code_type = pylint_smell.get("code") + code_type = pylint_smell.get("message-id") + print(code_type) self.logger.log( f"Applying 'Remove Unused Imports' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." ) diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index 35050975..0f24aaed 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -36,7 +36,11 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): match smell_messageID: case AllSmells.USE_A_GENERATOR.value: selected = UseAGeneratorRefactorer(logger) - case (AllSmells.UNUSED_IMPORT.value, AllSmells.UNUSED_VARIABLE.value, AllSmells.UNUSED_CLASS_ATTRIBUTE.value): + case AllSmells.UNUSED_IMPORT.value: + selected = RemoveUnusedRefactorer(logger) + case AllSmells.UNUSED_VARIABLE.value: + selected = RemoveUnusedRefactorer(logger) + case AllSmells.UNUSED_CLASS_ATTRIBUTE.value: selected = RemoveUnusedRefactorer(logger) case AllSmells.NO_SELF_USE.value: selected = MakeStaticRefactorer(logger) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 783e87c4..7b3a3ba9 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,13 +1,17 @@ +import datetime class DataProcessor: + unused_variable = 'unused' def __init__(self, data): self.data = data self.processed_data = [] + self.unused = True def process_all_data(self): results = [] + unused_variable = 2 for item in self.data: try: result = self.complex_calculation(item, True, False, @@ -22,8 +26,7 @@ def process_all_data(self): return self.processed_data @staticmethod - def complex_calculation(item, flag1, flag2, operation, threshold, - max_value, option, final_stage): + def complex_calculation(item, operation, threshold, max_value): if operation == 'multiply': result = item * threshold elif operation == 'add': @@ -33,25 +36,25 @@ def complex_calculation(item, flag1, flag2, operation, threshold, return result @staticmethod - def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, - max_value, option, final_stage, min_value): + def multi_param_calculation(data_params, config_params): value = 0 - if operation == 'multiply': - value = item1 * item2 * item3 - elif operation == 'add': - value = item1 + item2 + item3 - elif flag1 == 'true': - value = item1 - elif flag2 == 'true': - value = item2 - elif flag3 == 'true': - value = item3 - elif max_value < threshold: - value = max_value + if data_params.operation == 'multiply': + value = data_params.item1 * data_params.item2 * data_params.item3 + elif data_params.operation == 'add': + value = data_params.item1 + data_params.item2 + data_params.item3 + elif config_params.flag1 == 'true': + value = data_params.item1 + elif config_params.flag2 == 'true': + value = data_params.item2 + elif config_params.flag3 == 'true': + value = data_params.item3 + elif data_params.max_value < data_params.threshold: + value = data_params.max_value else: - value = min_value + value = data_params.min_value return value + class AdvancedProcessor(DataProcessor): @staticmethod From 628dc2f13efe1c56eae0441db9120cadd1ceba74 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 13:31:51 -0800 Subject: [PATCH 067/105] returned test case file to before --- tests/input/ineffcient_code_example_2.py | 37 +++++++++++------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 7b3a3ba9..720f7c53 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,17 +1,12 @@ -import datetime - class DataProcessor: - unused_variable = 'unused' def __init__(self, data): self.data = data self.processed_data = [] - self.unused = True def process_all_data(self): results = [] - unused_variable = 2 for item in self.data: try: result = self.complex_calculation(item, True, False, @@ -26,7 +21,8 @@ def process_all_data(self): return self.processed_data @staticmethod - def complex_calculation(item, operation, threshold, max_value): + def complex_calculation(item, flag1, flag2, operation, threshold, + max_value, option, final_stage): if operation == 'multiply': result = item * threshold elif operation == 'add': @@ -36,22 +32,23 @@ def complex_calculation(item, operation, threshold, max_value): return result @staticmethod - def multi_param_calculation(data_params, config_params): + def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, + max_value, option, final_stage, min_value): value = 0 - if data_params.operation == 'multiply': - value = data_params.item1 * data_params.item2 * data_params.item3 - elif data_params.operation == 'add': - value = data_params.item1 + data_params.item2 + data_params.item3 - elif config_params.flag1 == 'true': - value = data_params.item1 - elif config_params.flag2 == 'true': - value = data_params.item2 - elif config_params.flag3 == 'true': - value = data_params.item3 - elif data_params.max_value < data_params.threshold: - value = data_params.max_value + if operation == 'multiply': + value = item1 * item2 * item3 + elif operation == 'add': + value = item1 + item2 + item3 + elif flag1 == 'true': + value = item1 + elif flag2 == 'true': + value = item2 + elif flag3 == 'true': + value = item3 + elif max_value < threshold: + value = max_value else: - value = data_params.min_value + value = min_value return value From 5ef01b795932d9b8c3a6ca3f15b860d57bd3cc1d Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sun, 10 Nov 2024 17:21:31 -0500 Subject: [PATCH 068/105] made config changes --- .gitignore | 6 +++++- pyproject.toml | 30 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fedc55da..f49f5833 100644 --- a/.gitignore +++ b/.gitignore @@ -292,5 +292,9 @@ TSWLatexianTemp* __pycache__/ *.py[cod] +.venv/ + # Rope -.ropeproject \ No newline at end of file +.ropeproject + +*.egg-info/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 85a19af8..a496d4d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,9 @@ name = "ecooptimizer" version = "0.0.1" dependencies = [ "pylint", - "flake8", - "radon", - "rope" + "rope", + "astor", + "codecarbon" ] requires-python = ">=3.8" authors = [ @@ -24,7 +24,7 @@ description = "A source code eco optimizer" readme = "README.md" license = {file = "LICENSE"} -[dependency-groups] +[project.optional-dependencies] dev = ["pytest", "mypy", "ruff", "coverage"] [project.urls] @@ -33,16 +33,22 @@ Repository = "https://github.com/ssm-lab/capstone--source-code-optimizer" "Bug Tracker" = "https://github.com/ssm-lab/capstone--source-code-optimizer/issues" [tool.pytest.ini_options] -testpaths = ["test"] +testpaths = ["tests"] [tool.ruff] -line-length = 100 +extend-exclude = ["*tests/input/**/*.py"] [tool.ruff.lint] -ignore = ["E402"] +# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults. +select = ["E4", "E7", "E9", "F", "B"] -[tool.ruff.format] -quote-style = "single" -indent-style = "tab" -docstring-code-format = true -docstring-code-line-length = 50 \ No newline at end of file +# 2. Avoid enforcing line-length violations (`E501`) +ignore = ["E501"] + +# 3. Avoid trying to fix flake8-bugbear (`B`) violations. +unfixable = ["B"] + +# 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories. +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["E402"] +"**/{tests,docs,tools}/*" = ["E402"] \ No newline at end of file From 8c3c0a3df3eb8262715b4a080f3affe0f2d5754f Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 14:31:45 -0800 Subject: [PATCH 069/105] added test case for unused imports, variables, and class attributes --- src1/refactorers/unused_refactorer.py | 2 +- tests/input/ineffcient_code_example_2.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index 8b40564b..accb3f97 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -67,7 +67,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # check for improvement in emissions (for logging purposes only) if self.check_energy_improvement(initial_emissions, final_emissions): self.logger.log( - f"Removed unused import on line {line_number} and saved changes.\n" + f"Removed unused stuff on line {line_number} and saved changes.\n" ) else: self.logger.log( diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 720f7c53..110413a9 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,3 +1,16 @@ +import datetime # unused import + +# test case for unused variable and class attribute +class Temp: + def __init__(self) -> None: + self.unused_class_attribute = True + self.a = 3 + + def temp_function(self): + unused_var = 3 + b = 4 + return self.a + b + class DataProcessor: From 955aacc76c3c6a45cb449568b186a9d1724da263 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 15:19:45 -0800 Subject: [PATCH 070/105] changed deleting to replace with empty line --- src1/refactorers/unused_refactorer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index accb3f97..1540c995 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -38,7 +38,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # remove specified line modified_lines = original_lines[:] - del modified_lines[line_number - 1] + modified_lines[line_number - 1] = "\n" # for logging purpose to see what was removed if code_type == "W0611": # UNUSED_IMPORT From 410388b5e4a4a8dd59697a9eced14f5b550e28e9 Mon Sep 17 00:00:00 2001 From: mya Date: Sun, 10 Nov 2024 19:09:25 -0500 Subject: [PATCH 071/105] Long message chain refactorer done --- src1/main.py | 10 +- .../outputs/all_configured_pylint_smells.json | 96 +------- src1/outputs/all_pylint_smells.json | 207 ++++++++++-------- src1/outputs/final_emissions_data.txt | 38 ++-- src1/outputs/initial_emissions_data.txt | 38 ++-- src1/outputs/log.txt | 112 ++++------ src1/outputs/refactored-test-case.py | 4 +- .../long_message_chain_refactorer.py | 77 ++++++- .../long_parameter_list_refactorer.py | 67 ++++-- .../member_ignoring_method_refactorer.py | 5 +- src1/utils/refactorer_factory.py | 12 +- 11 files changed, 340 insertions(+), 326 deletions(-) diff --git a/src1/main.py b/src1/main.py index cd84e652..ab829f23 100644 --- a/src1/main.py +++ b/src1/main.py @@ -62,9 +62,7 @@ def main(): pylint_analyzer.analyze() # analyze all smells # Save code smells - save_json_files( - "all_pylint_smells.json", pylint_analyzer.smells_data, logger - ) + save_json_files("all_pylint_smells.json", pylint_analyzer.smells_data, logger) pylint_analyzer.configure_smells() # get all configured smells @@ -76,7 +74,7 @@ def main(): logger.log( "#####################################################################################################\n\n" ) - + # Log start of refactoring codes logger.log( "#####################################################################################################" @@ -92,7 +90,9 @@ def main(): copy_file_to_output(TEST_FILE, "refactored-test-case.py") for pylint_smell in pylint_analyzer.smells_data: - refactoring_class = RefactorerFactory.build_refactorer_class(pylint_smell["message-id"],logger) + refactoring_class = RefactorerFactory.build_refactorer_class( + pylint_smell["message-id"], logger + ) if refactoring_class: refactoring_class.refactor(TEST_FILE, pylint_smell, initial_emissions) else: diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json index 5e793930..cb023984 100644 --- a/src1/outputs/all_configured_pylint_smells.json +++ b/src1/outputs/all_configured_pylint_smells.json @@ -2,119 +2,41 @@ { "column": 4, "endColumn": 27, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Too many arguments (8/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, - { - "column": 34, - "endColumn": 39, - "endLine": 25, - "line": 25, - "message": "Unused argument 'flag1'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 41, - "endColumn": 46, - "endLine": 25, - "line": 25, - "message": "Unused argument 'flag2'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 19, - "endColumn": 25, - "endLine": 26, - "line": 26, - "message": "Unused argument 'option'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 27, - "endColumn": 38, - "endLine": 26, - "line": 26, - "message": "Unused argument 'final_stage'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, { "column": 4, "endColumn": 31, - "endLine": 36, - "line": 36, + "endLine": 35, + "line": 35, "message": "Too many arguments (12/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, { - "column": 43, - "endColumn": 49, - "endLine": 37, - "line": 37, - "message": "Unused argument 'option'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 51, - "endColumn": 62, - "endLine": 37, - "line": 37, - "message": "Unused argument 'final_stage'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "absolutePath": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 19, + "line": 18, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" } diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index e9e3af86..e9f2780d 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -3,12 +3,25 @@ "column": 74, "endColumn": null, "endLine": null, - "line": 20, + "line": 19, + "message": "Trailing whitespace", + "message-id": "C0303", + "module": "ineffcient_code_example_2", + "obj": "", + "path": "tests/input/ineffcient_code_example_2.py", + "symbol": "trailing-whitespace", + "type": "convention" + }, + { + "column": 95, + "endColumn": null, + "endLine": null, + "line": 35, "message": "Trailing whitespace", "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "trailing-whitespace", "type": "convention" }, @@ -16,12 +29,12 @@ "column": 0, "endColumn": null, "endLine": null, - "line": 36, + "line": 35, "message": "Line too long (95/80)", "message-id": "C0301", "module": "ineffcient_code_example_2", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "line-too-long", "type": "convention" }, @@ -34,7 +47,7 @@ "message-id": "C0303", "module": "ineffcient_code_example_2", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "trailing-whitespace", "type": "convention" }, @@ -47,332 +60,332 @@ "message-id": "C0114", "module": "ineffcient_code_example_2", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-module-docstring", "type": "convention" }, { "column": 0, "endColumn": 19, - "endLine": 3, - "line": 3, + "endLine": 2, + "line": 2, "message": "Missing class docstring", "message-id": "C0115", "module": "ineffcient_code_example_2", "obj": "DataProcessor", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-class-docstring", "type": "convention" }, { "column": 4, "endColumn": 24, - "endLine": 9, - "line": 9, + "endLine": 8, + "line": 8, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, { "column": 19, "endColumn": 28, - "endLine": 16, - "line": 16, + "endLine": 15, + "line": 15, "message": "Catching too general exception Exception", "message-id": "W0718", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "broad-exception-caught", "type": "warning" }, { "column": 12, "endColumn": 46, - "endLine": 17, - "line": 12, + "endLine": 16, + "line": 11, "message": "try clause contains 2 statements, expected at most 1", "message-id": "W0717", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-try-statements", "type": "warning" }, { "column": 35, "endColumn": 43, - "endLine": 21, - "line": 20, + "endLine": 20, + "line": 19, "message": "Used builtin function 'filter'. Using a list comprehension can be clearer.", "message-id": "W0141", "module": "ineffcient_code_example_2", "obj": "DataProcessor.process_all_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "bad-builtin", "type": "warning" }, { "column": 4, "endColumn": 27, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, { "column": 4, "endColumn": 27, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Too many arguments (8/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, { "column": 4, "endColumn": 27, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Too many positional arguments (8/5)", "message-id": "R0917", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-positional-arguments", "type": "refactor" }, { "column": 11, "endColumn": 34, - "endLine": 27, - "line": 27, + "endLine": 26, + "line": 26, "message": "Consider using a named constant or an enum instead of ''multiply''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 31, - "endLine": 29, - "line": 29, + "endLine": 28, + "line": 28, "message": "Consider using a named constant or an enum instead of ''add''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 34, "endColumn": 39, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Unused argument 'flag1'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 41, "endColumn": 46, - "endLine": 25, - "line": 25, + "endLine": 24, + "line": 24, "message": "Unused argument 'flag2'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 19, "endColumn": 25, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 27, "endColumn": 38, - "endLine": 26, - "line": 26, + "endLine": 25, + "line": 25, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.complex_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 4, "endColumn": 31, - "endLine": 36, - "line": 36, + "endLine": 35, + "line": 35, "message": "Missing function or method docstring", "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, { "column": 4, "endColumn": 31, - "endLine": 36, - "line": 36, + "endLine": 35, + "line": 35, "message": "Too many arguments (12/6)", "message-id": "R0913", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-arguments", "type": "refactor" }, { "column": 4, "endColumn": 31, - "endLine": 36, - "line": 36, + "endLine": 35, + "line": 35, "message": "Too many positional arguments (12/5)", "message-id": "R0917", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-positional-arguments", "type": "refactor" }, { "column": 11, "endColumn": 34, - "endLine": 39, - "line": 39, + "endLine": 38, + "line": 38, "message": "Consider using a named constant or an enum instead of ''multiply''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 31, - "endLine": 41, - "line": 41, + "endLine": 40, + "line": 40, "message": "Consider using a named constant or an enum instead of ''add''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 28, - "endLine": 43, - "line": 43, + "endLine": 42, + "line": 42, "message": "Consider using a named constant or an enum instead of ''true''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 28, - "endLine": 45, - "line": 45, + "endLine": 44, + "line": 44, "message": "Consider using a named constant or an enum instead of ''true''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 13, "endColumn": 28, - "endLine": 47, - "line": 47, + "endLine": 46, + "line": 46, "message": "Consider using a named constant or an enum instead of ''true''.", "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, { "column": 4, "endColumn": 31, - "endLine": 36, - "line": 36, + "endLine": 35, + "line": 35, "message": "Too many branches (7/3)", "message-id": "R0912", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-branches", "type": "refactor" }, { "column": 43, "endColumn": 49, - "endLine": 37, - "line": 37, + "endLine": 36, + "line": 36, "message": "Unused argument 'option'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, { "column": 51, "endColumn": 62, - "endLine": 37, - "line": 37, + "endLine": 36, + "line": 36, "message": "Unused argument 'final_stage'", "message-id": "W0613", "module": "ineffcient_code_example_2", "obj": "DataProcessor.multi_param_calculation", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "unused-argument", "type": "warning" }, @@ -385,7 +398,7 @@ "message-id": "C0115", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-class-docstring", "type": "convention" }, @@ -398,7 +411,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.check_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -411,7 +424,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.check_data", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -424,7 +437,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -437,7 +450,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -450,7 +463,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.complex_comprehension", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -463,7 +476,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_chain", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -476,7 +489,7 @@ "message-id": "W0717", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_chain", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-try-statements", "type": "warning" }, @@ -489,7 +502,7 @@ "message-id": "C0116", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "missing-function-docstring", "type": "convention" }, @@ -502,7 +515,7 @@ "message-id": "R2004", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "magic-value-comparison", "type": "refactor" }, @@ -515,7 +528,7 @@ "message-id": "R0912", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-branches", "type": "refactor" }, @@ -528,7 +541,7 @@ "message-id": "R1702", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "too-many-nested-blocks", "type": "refactor" }, @@ -541,22 +554,22 @@ "message-id": "R1710", "module": "ineffcient_code_example_2", "obj": "AdvancedProcessor.long_scope_chaining", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "tests/input/ineffcient_code_example_2.py", "symbol": "inconsistent-return-statements", "type": "refactor" }, { - "absolutePath": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "column": 18, "confidence": "UNDEFINED", "endColumn": null, "endLine": null, - "line": 19, + "line": 18, "message": "Method chain too long (3/3)", "message-id": "LMC001", "module": "ineffcient_code_example_2.py", "obj": "", - "path": "/Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", + "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", "symbol": "long-message-chain", "type": "convention" } diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index eb1e3741..bbb58bfe 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 8, - "cpu_energy": 3.2149725892749204e-07, - "cpu_model": "Apple M2", - "cpu_power": 42.5, - "duration": 0.0272803339757956, - "emissions": 1.4478415866039985e-08, - "emissions_rate": 5.307272219939055e-07, - "energy_consumed": 3.665751072144809e-07, + "cpu_count": 16, + "cpu_energy": NaN, + "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "cpu_power": NaN, + "duration": 4.9795035580173135, + "emissions": NaN, + "emissions_rate": NaN, + "energy_consumed": NaN, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": NaN, - "gpu_energy": 0, - "gpu_model": NaN, - "gpu_power": 0.0, - "latitude": 43.251, - "longitude": -79.8989, + "gpu_count": 1, + "gpu_energy": NaN, + "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "gpu_power": NaN, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "macOS-14.1.1-arm64-arm-64bit-Mach-O", + "os": "macOS-14.4-x86_64-i386-64bit", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 4.507784828698883e-08, + "python_version": "3.10.10", + "ram_energy": 6.903137672149266e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "245d27f5-0cbb-4ba2-88d2-224d2dd50971", - "timestamp": "2024-11-10T14:37:26", + "run_id": "ffca42c2-b044-4cec-a165-6c539f80634d", + "timestamp": "2024-11-10T19:03:14", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index 4681b3a1..d5a09a0e 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 8, - "cpu_energy": 5.288313370935308e-07, - "cpu_model": "Apple M2", - "cpu_power": 42.5, - "duration": 0.0448683750000782, - "emissions": 2.3819676859384504e-08, - "emissions_rate": 5.308789734271182e-07, - "energy_consumed": 6.030839754384942e-07, + "cpu_count": 16, + "cpu_energy": NaN, + "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "cpu_power": NaN, + "duration": 5.134236281970516, + "emissions": NaN, + "emissions_rate": NaN, + "energy_consumed": NaN, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": NaN, - "gpu_energy": 0, - "gpu_model": NaN, - "gpu_power": 0.0, - "latitude": 43.251, - "longitude": -79.8989, + "gpu_count": 1, + "gpu_energy": NaN, + "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", + "gpu_power": NaN, + "latitude": 43.266, + "longitude": -79.9441, "on_cloud": "N", - "os": "macOS-14.1.1-arm64-arm-64bit-Mach-O", + "os": "macOS-14.4-x86_64-i386-64bit", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 7.42526383449634e-08, + "python_version": "3.10.10", + "ram_energy": 8.0895381688606e-08, "ram_power": 6.0, "ram_total_size": 16.0, "region": "ontario", - "run_id": "2925eed2-f0e4-4409-99cd-3da5a7d75c64", - "timestamp": "2024-11-10T14:37:24", + "run_id": "28b554a1-c4d4-4657-b8ba-1e06fa8652b5", + "timestamp": "2024-11-10T19:02:47", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index 1ca88c70..aec37f4e 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,68 +1,44 @@ -[2024-11-10 14:37:21] ##################################################################################################### -[2024-11-10 14:37:21] CAPTURE INITIAL EMISSIONS -[2024-11-10 14:37:21] ##################################################################################################### -[2024-11-10 14:37:21] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 14:37:24] CodeCarbon measurement completed successfully. -[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-10 14:37:24] Initial Emissions: 2.3819676859384504e-08 kg CO2 -[2024-11-10 14:37:24] ##################################################################################################### - - -[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 14:37:24] CAPTURE CODE SMELLS -[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 14:37:24] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-10 14:37:24] Pylint analyzer completed successfully. -[2024-11-10 14:37:24] Running custom parsers: -[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json -[2024-11-10 14:37:24] Filtering pylint smells -[2024-11-10 14:37:24] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-10 14:37:24] Refactorable code smells: 9 -[2024-11-10 14:37:24] ##################################################################################################### - - -[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 14:37:24] REFACTOR CODE SMELLS -[2024-11-10 14:37:24] ##################################################################################################### -[2024-11-10 14:37:24] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 25 for identified code smell. -[2024-11-10 14:37:24] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. -[2024-11-10 14:37:26] Measured emissions for 'ineffcient_code_example_2_temp.py': 2.9212009369852857e-08 -[2024-11-10 14:37:26] Initial Emissions: 2.3819676859384504e-08 kg CO2. Final Emissions: 2.9212009369852857e-08 kg CO2. -[2024-11-10 14:37:26] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Applying 'Fix Too Many Parameters' refactor on 'ineffcient_code_example_2.py' at line 36 for identified code smell. -[2024-11-10 14:37:26] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. -[2024-11-10 14:37:26] Measured emissions for 'ineffcient_code_example_2_temp.py': 1.3589692780774065e-08 -[2024-11-10 14:37:26] Initial Emissions: 2.3819676859384504e-08 kg CO2. Final Emissions: 1.3589692780774065e-08 kg CO2. -[2024-11-10 14:37:26] Refactored list comprehension to generator expression on line 36 and saved. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Refactoring for smell unused-argument is not implemented. - -[2024-11-10 14:37:26] Refactoring for smell long-message-chain is not implemented. - -[2024-11-10 14:37:26] ##################################################################################################### - - -[2024-11-10 14:37:26] ##################################################################################################### -[2024-11-10 14:37:26] CAPTURE FINAL EMISSIONS -[2024-11-10 14:37:26] ##################################################################################################### -[2024-11-10 14:37:26] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 14:37:26] CodeCarbon measurement completed successfully. -[2024-11-10 14:37:26] Output saved to /Users/tanveerbrar/2024-25/4g06/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt -[2024-11-10 14:37:26] Final Emissions: 1.4478415866039985e-08 kg CO2 -[2024-11-10 14:37:26] ##################################################################################################### - - -[2024-11-10 14:37:26] Saved 9.34126099334452e-09 kg CO2 +[2024-11-10 19:02:34] ##################################################################################################### +[2024-11-10 19:02:34] CAPTURE INITIAL EMISSIONS +[2024-11-10 19:02:34] ##################################################################################################### +[2024-11-10 19:02:34] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 19:02:42] CodeCarbon measurement completed successfully. +[2024-11-10 19:02:47] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt +[2024-11-10 19:02:47] Initial Emissions: nan kg CO2 +[2024-11-10 19:02:47] ##################################################################################################### + + +[2024-11-10 19:02:47] ##################################################################################################### +[2024-11-10 19:02:47] CAPTURE CODE SMELLS +[2024-11-10 19:02:47] ##################################################################################################### +[2024-11-10 19:02:47] Running Pylint analysis on ineffcient_code_example_2.py +[2024-11-10 19:02:48] Pylint analyzer completed successfully. +[2024-11-10 19:02:48] Running custom parsers: +[2024-11-10 19:02:48] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json +[2024-11-10 19:02:48] Filtering pylint smells +[2024-11-10 19:02:48] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json +[2024-11-10 19:02:48] Refactorable code smells: 3 +[2024-11-10 19:02:48] ##################################################################################################### + + +[2024-11-10 19:02:48] ##################################################################################################### +[2024-11-10 19:02:48] REFACTOR CODE SMELLS +[2024-11-10 19:02:48] ##################################################################################################### +[2024-11-10 19:02:48] Refactored long message chain and saved to ineffcient_code_example_2_temp.py +[2024-11-10 19:02:48] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py +[2024-11-10 19:02:55] CodeCarbon measurement completed successfully. +[2024-11-10 19:03:00] Measured emissions for 'ineffcient_code_example_2_temp.py': nan +[2024-11-10 19:03:00] ##################################################################################################### + + +[2024-11-10 19:03:00] ##################################################################################################### +[2024-11-10 19:03:00] CAPTURE FINAL EMISSIONS +[2024-11-10 19:03:00] ##################################################################################################### +[2024-11-10 19:03:00] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py +[2024-11-10 19:03:09] CodeCarbon measurement completed successfully. +[2024-11-10 19:03:14] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt +[2024-11-10 19:03:14] Final Emissions: nan kg CO2 +[2024-11-10 19:03:14] ##################################################################################################### + + +[2024-11-10 19:03:14] Saved nan kg CO2 diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index 783e87c4..720f7c53 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,5 +1,4 @@ - class DataProcessor: def __init__(self, data): @@ -33,7 +32,7 @@ def complex_calculation(item, flag1, flag2, operation, threshold, return result @staticmethod - def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, + def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, max_value, option, final_stage, min_value): value = 0 if operation == 'multiply': @@ -52,6 +51,7 @@ def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, value = min_value return value + class AdvancedProcessor(DataProcessor): @staticmethod diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index 4ce68450..54378350 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -1,3 +1,6 @@ +import os +import re +import shutil from .base_refactorer import BaseRefactorer @@ -11,7 +14,75 @@ def __init__(self, logger): def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): """ - Refactor long message chain + Refactor long message chains by breaking them into separate statements + and writing the refactored code to a new file. """ - # Logic to identify long methods goes here - pass + # Extract details from pylint_smell + line_number = pylint_smell["line"] + original_filename = os.path.basename(file_path) + temp_filename = f"{os.path.splitext(original_filename)[0]}_temp.py" + + # Read the original file + with open(file_path, "r") as f: + lines = f.readlines() + + # Identify the line with the long method chain + line_with_chain = lines[line_number - 1].rstrip() + + # Extract leading whitespace for correct indentation + leading_whitespace = re.match(r"^\s*", line_with_chain).group() + + # Remove the function call wrapper if present (e.g., `print(...)`) + chain_content = re.sub(r"^\s*print\((.*)\)\s*$", r"\1", line_with_chain) + + # Split the chain into individual method calls + method_calls = re.split(r"\.(?![^()]*\))", chain_content) + + # Refactor if it's a long chain + if len(method_calls) > 2: + refactored_lines = [] + base_var = method_calls[0].strip() # Initial part, e.g., `self.data[0]` + refactored_lines.append(f"{leading_whitespace}intermediate_0 = {base_var}") + + # Generate intermediate variables for each method in the chain + for i, method in enumerate(method_calls[1:], start=1): + if i < len(method_calls) - 1: + refactored_lines.append( + f"{leading_whitespace}intermediate_{i} = intermediate_{i-1}.{method.strip()}" + ) + else: + # Final result to pass to function + refactored_lines.append( + f"{leading_whitespace}result = intermediate_{i-1}.{method.strip()}" + ) + + # Add final function call with result + refactored_lines.append(f"{leading_whitespace}print(result)\n") + + # Replace the original line with the refactored lines + lines[line_number - 1] = "\n".join(refactored_lines) + "\n" + + temp_file_path = temp_filename + # Write the refactored code to a new temporary file + with open(temp_filename, "w") as temp_file: + temp_file.writelines(lines) + + # Log completion + self.logger.log(f"Refactored long message chain and saved to {temp_filename}") + + # Measure emissions of the modified code + final_emission = self.measure_energy(temp_file_path) + + #Check for improvement in emissions + if self.check_energy_improvement(initial_emissions, final_emission): + # If improved, replace the original file with the modified content + shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored list comprehension to generator expression on line {self.target_line} and saved.\n" + ) + else: + # Remove the temporary file if no improvement + os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 770df6b2..599d739d 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -36,7 +36,7 @@ def classify_parameters(params): config_params = [] for param in params: - if param.startswith(('config', 'flag', 'option', 'setting')): + if param.startswith(("config", "flag", "option", "setting")): config_params.append(param) else: data_params.append(param) @@ -70,7 +70,7 @@ def refactor(self, file_path, pylint_smell, initial_emissions): self.logger.log( f"Applying 'Fix Too Many Parameters' refactor on '{os.path.basename(file_path)}' at line {target_line} for identified code smell." ) - with open(file_path, 'r') as f: + with open(file_path, "r") as f: tree = ast.parse(f.read()) # Flag indicating if a refactoring has been made @@ -87,8 +87,12 @@ def refactor(self, file_path, pylint_smell, initial_emissions): used_params = get_used_parameters(node, params) # Remove unused parameters - new_params = [arg for arg in node.args.args if arg.arg in used_params] - if len(new_params) != len(node.args.args): # Check if any parameters were removed + new_params = [ + arg for arg in node.args.args if arg.arg in used_params + ] + if len(new_params) != len( + node.args.args + ): # Check if any parameters were removed node.args.args[:] = new_params # Update in place modified = True @@ -102,36 +106,61 @@ def refactor(self, file_path, pylint_smell, initial_emissions): # Create parameter object classes for each group if data_params: - data_param_object_code = create_parameter_object_class(data_params, class_name="DataParams") - data_param_object_ast = ast.parse(data_param_object_code).body[0] + data_param_object_code = create_parameter_object_class( + data_params, class_name="DataParams" + ) + data_param_object_ast = ast.parse( + data_param_object_code + ).body[0] tree.body.insert(0, data_param_object_ast) if config_params: - config_param_object_code = create_parameter_object_class(config_params, - class_name="ConfigParams") - config_param_object_ast = ast.parse(config_param_object_code).body[0] + config_param_object_code = create_parameter_object_class( + config_params, class_name="ConfigParams" + ) + config_param_object_ast = ast.parse( + config_param_object_code + ).body[0] tree.body.insert(0, config_param_object_ast) # Modify function to use two parameters for the parameter objects - node.args.args = [ast.arg(arg="data_params", annotation=None), - ast.arg(arg="config_params", annotation=None)] + node.args.args = [ + ast.arg(arg="data_params", annotation=None), + ast.arg(arg="config_params", annotation=None), + ] # Update all parameter usages within the function to access attributes of the parameter objects class ParamAttributeUpdater(ast.NodeTransformer): def visit_Name(self, node): - if node.id in data_params and isinstance(node.ctx, ast.Load): - return ast.Attribute(value=ast.Name(id="data_params", ctx=ast.Load()), attr=node.id, - ctx=node.ctx) - elif node.id in config_params and isinstance(node.ctx, ast.Load): - return ast.Attribute(value=ast.Name(id="config_params", ctx=ast.Load()), - attr=node.id, ctx=node.ctx) + if node.id in data_params and isinstance( + node.ctx, ast.Load + ): + return ast.Attribute( + value=ast.Name( + id="data_params", ctx=ast.Load() + ), + attr=node.id, + ctx=node.ctx, + ) + elif node.id in config_params and isinstance( + node.ctx, ast.Load + ): + return ast.Attribute( + value=ast.Name( + id="config_params", ctx=ast.Load() + ), + attr=node.id, + ctx=node.ctx, + ) return node - node.body = [ParamAttributeUpdater().visit(stmt) for stmt in node.body] + node.body = [ + ParamAttributeUpdater().visit(stmt) for stmt in node.body + ] if modified: # Write back modified code to temporary file - temp_file_path = f"{os.path.basename(file_path).split(".")[0]}_temp.py" + temp_file_path = f"{os.path.basename(file_path).split('.')[0]}_temp.py" with open(temp_file_path, "w") as temp_file: temp_file.write(astor.to_source(tree)) diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src1/refactorers/member_ignoring_method_refactorer.py index baacfd73..e5d1ac53 100644 --- a/src1/refactorers/member_ignoring_method_refactorer.py +++ b/src1/refactorers/member_ignoring_method_refactorer.py @@ -40,7 +40,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Convert the modified AST back to source code modified_code = astor.to_source(modified_tree) - temp_file_path = f"{os.path.basename(file_path).split(".")[0]}_temp.py" + temp_file_path = f"{os.path.basename(file_path).split('.')[0]}_temp.py" with open(temp_file_path, "w") as temp_file: temp_file.write(modified_code) @@ -60,7 +60,6 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa self.logger.log( "No emission improvement after refactoring. Discarded refactored changes.\n" ) - def visit_FunctionDef(self, node): if node.lineno == self.target_line: @@ -69,7 +68,7 @@ def visit_FunctionDef(self, node): node.decorator_list.append(decorator) # Step 2: Remove 'self' from the arguments if it exists - if node.args.args and node.args.args[0].arg == 'self': + if node.args.args and node.args.args[0].arg == "self": node.args.args.pop(0) # Add the decorator to the function's decorator list return node diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index 0f24aaed..d479d341 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -3,15 +3,17 @@ from refactorers.unused_refactorer import RemoveUnusedRefactorer from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer from refactorers.member_ignoring_method_refactorer import MakeStaticRefactorer +from refactorers.long_message_chain_refactorer import LongMessageChainRefactorer from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells from utils.logger import Logger from utils.analyzers_config import AllSmells -class RefactorerFactory(): + +class RefactorerFactory: """ - Factory class for creating appropriate refactorer instances based on + Factory class for creating appropriate refactorer instances based on the specific code smell detected by Pylint. """ @@ -26,10 +28,10 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): - smell_data (dict): Additional data related to the smell, passed to the refactorer. Returns: - - BaseRefactorer: An instance of a specific refactorer class if one exists for the smell; + - BaseRefactorer: An instance of a specific refactorer class if one exists for the smell; otherwise, None. """ - + selected = None # Initialize variable to hold the selected refactorer instance # Use match statement to select the appropriate refactorer based on smell message ID @@ -46,6 +48,8 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): selected = MakeStaticRefactorer(logger) case AllSmells.LONG_PARAMETER_LIST.value: selected = LongParameterListRefactorer(logger) + case AllSmells.LONG_MESSAGE_CHAIN.value: + selected = LongMessageChainRefactorer(logger) case _: selected = None From d70725f6222e74faadbe37f1316456765c202349 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sun, 10 Nov 2024 21:10:36 -0500 Subject: [PATCH 072/105] added copy of input test file --- tests/_input_copies/test_2_copy.py | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/_input_copies/test_2_copy.py diff --git a/tests/_input_copies/test_2_copy.py b/tests/_input_copies/test_2_copy.py new file mode 100644 index 00000000..f8f32921 --- /dev/null +++ b/tests/_input_copies/test_2_copy.py @@ -0,0 +1,90 @@ +# LC: Large Class with too many responsibilities +class DataProcessor: + def __init__(self, data): + self.data = data + self.processed_data = [] + + # LM: Long Method - this method does way too much + def process_all_data(self): + results = [] + for item in self.data: + try: + # LPL: Long Parameter List + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) + results.append(result) + except ( + Exception + ) as e: # UEH: Unqualified Exception Handling, catching generic exceptions + print("An error occurred:", e) + + # LMC: Long Message Chain + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + # LLF: Long Lambda Function + self.processed_data = list( + filter(lambda x: x != None and x != 0 and len(str(x)) > 1, results) + ) + + return self.processed_data + + # LBCL: Long Base Class List + + +class AdvancedProcessor(DataProcessor, object, dict, list, set, tuple): + pass + + # LTCE: Long Ternary Conditional Expression + def check_data(self, item): + return ( + True if item > 10 else False if item < -10 else None if item == 0 else item + ) + + # Complex List Comprehension + def complex_comprehension(self): + # CLC: Complex List Comprehension + self.processed_data = [ + x**2 if x % 2 == 0 else x**3 + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] + + # Long Element Chain + def long_chain(self): + # LEC: Long Element Chain accessing deeply nested elements + try: + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + return deep_value + except KeyError: + return None + + # Long Scope Chaining (LSC) + def long_scope_chaining(self): + for a in range(10): + for b in range(10): + for c in range(10): + for d in range(10): + for e in range(10): + if a + b + c + d + e > 25: + return "Done" + + # LPL: Long Parameter List + def complex_calculation( + self, item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": + result = item * threshold + elif operation == "add": + result = item + max_value + else: + result = item + return result + + +# Main method to execute the code +if __name__ == "__main__": + sample_data = [1, 2, 3, 4, 5] + processor = DataProcessor(sample_data) + processed = processor.process_all_data() + print("Processed Data:", processed) From 9c46dc6a89cd8170547ddcf0692dc0cc60dec117 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sun, 10 Nov 2024 21:34:19 -0500 Subject: [PATCH 073/105] fixed lmc refactorer --- src1/refactorers/long_message_chain_refactorer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index 54378350..f456f24d 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -78,7 +78,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # If improved, replace the original file with the modified content shutil.move(temp_file_path, file_path) self.logger.log( - f"Refactored list comprehension to generator expression on line {self.target_line} and saved.\n" + f"Refactored list comprehension to generator expression on line {pylint_smell["line"]} and saved.\n" ) else: # Remove the temporary file if no improvement From deae8250fb3936b3de5e82e51c4da70cc6a0579b Mon Sep 17 00:00:00 2001 From: mya Date: Sun, 10 Nov 2024 22:21:18 -0500 Subject: [PATCH 074/105] added tests for example 2 --- .../input/inefficent_code_example_2_tests.py | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/input/inefficent_code_example_2_tests.py diff --git a/tests/input/inefficent_code_example_2_tests.py b/tests/input/inefficent_code_example_2_tests.py new file mode 100644 index 00000000..b4286d2c --- /dev/null +++ b/tests/input/inefficent_code_example_2_tests.py @@ -0,0 +1,84 @@ +import unittest +from datetime import datetime + +from tests.input.ineffcient_code_example_2 import ( + AdvancedProcessor, + DataProcessor, +) # Just to show the unused import issue + +# Assuming the classes DataProcessor and AdvancedProcessor are already defined +# and imported + + +class TestDataProcessor(unittest.TestCase): + + def test_process_all_data(self): + # Test valid data processing + data = [1, 2, 3, 4, 5] + processor = DataProcessor(data) + processed_data = processor.process_all_data() + # Expecting [10, 20] after filtering out None, 0, and single character numbers + self.assertEqual(processed_data, [10, 20]) + + def test_process_all_data_empty(self): + # Test with empty data list + processor = DataProcessor([]) + processed_data = processor.process_all_data() + self.assertEqual(processed_data, []) + + def test_complex_calculation_multiply(self): + # Test multiplication operation + result = DataProcessor.complex_calculation( + 5, True, False, "multiply", 10, 20, None, "end" + ) + self.assertEqual(result, 50) # 5 * 10 + + def test_complex_calculation_add(self): + # Test addition operation + result = DataProcessor.complex_calculation( + 5, True, False, "add", 10, 20, None, "end" + ) + self.assertEqual(result, 25) # 5 + 20 + + def test_complex_calculation_default(self): + # Test default operation + result = DataProcessor.complex_calculation( + 5, True, False, "unknown", 10, 20, None, "end" + ) + self.assertEqual(result, 5) # Default value is item itself + + +class TestAdvancedProcessor(unittest.TestCase): + + def test_complex_comprehension(self): + # Test complex list comprehension + processor = AdvancedProcessor([1, 2, 3, 4, 5]) + processor.complex_comprehension() + expected_result = [4, 64, 256, 1296, 1024, 4096, 7776, 15625] + self.assertEqual(processor.processed_data, expected_result) + + def test_long_chain_valid(self): + # Test valid deep chain access + data = [ + {"details": {"info": {"more_info": [{}, {}, {"target": "Valid Value"}]}}} + ] + processor = AdvancedProcessor(data) + result = processor.long_chain() + self.assertEqual(result, "Valid Value") + + def test_long_chain_invalid(self): + # Test invalid deep chain access, should return None + data = [{"details": {"info": {"more_info": [{}]}}}] + processor = AdvancedProcessor(data) + result = processor.long_chain() + self.assertIsNone(result) + + def test_long_scope_chaining(self): + # Test long scope chaining, expecting 'Done' when the sum exceeds 25 + processor = AdvancedProcessor([1, 2, 3, 4, 5]) + result = processor.long_scope_chaining() + self.assertEqual(result, "Done") + + +if __name__ == "__main__": + unittest.main() From bc78f6c81c59711b64aab664ce18b2a546ff1a12 Mon Sep 17 00:00:00 2001 From: mya Date: Sun, 10 Nov 2024 22:27:22 -0500 Subject: [PATCH 075/105] testing --- tests/input/ineffcient_code_example_2.py | 79 ++++++++++++------- .../input/inefficent_code_example_2_tests.py | 37 +++++++-- 2 files changed, 84 insertions(+), 32 deletions(-) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 110413a9..52ec6c1f 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,4 +1,5 @@ -import datetime # unused import +import datetime # unused import + # test case for unused variable and class attribute class Temp: @@ -19,44 +20,65 @@ def __init__(self, data): self.processed_data = [] def process_all_data(self): + if not self.data: # Check for empty data + return [] + results = [] for item in self.data: try: - result = self.complex_calculation(item, True, False, - 'multiply', 10, 20, None, 'end') + result = self.complex_calculation( + item, True, False, "multiply", 10, 20, None, "end" + ) results.append(result) except Exception as e: - print('An error occurred:', e) + print("An error occurred:", e) + + # Check if the list is not empty before accessing self.data[0] if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(' ', '_').lower()) - self.processed_data = list(filter(lambda x: x is not None and x != - 0 and len(str(x)) > 1, results)) + print(self.data[0].upper().strip().replace(" ", "_").lower()) + + self.processed_data = list( + filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) + ) return self.processed_data @staticmethod - def complex_calculation(item, flag1, flag2, operation, threshold, - max_value, option, final_stage): - if operation == 'multiply': + def complex_calculation( + item, flag1, flag2, operation, threshold, max_value, option, final_stage + ): + if operation == "multiply": result = item * threshold - elif operation == 'add': + elif operation == "add": result = item + max_value else: result = item return result @staticmethod - def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, - max_value, option, final_stage, min_value): + def multi_param_calculation( + item1, + item2, + item3, + flag1, + flag2, + flag3, + operation, + threshold, + max_value, + option, + final_stage, + min_value, + ): value = 0 - if operation == 'multiply': + if operation == "multiply": value = item1 * item2 * item3 - elif operation == 'add': + elif operation == "add": value = item1 + item2 + item3 - elif flag1 == 'true': + elif flag1 == "true": value = item1 - elif flag2 == 'true': + elif flag2 == "true": value = item2 - elif flag3 == 'true': + elif flag3 == "true": value = item3 elif max_value < threshold: value = max_value @@ -69,17 +91,20 @@ class AdvancedProcessor(DataProcessor): @staticmethod def check_data(item): - return (True if item > 10 else False if item < -10 else None if - item == 0 else item) + return ( + True if item > 10 else False if item < -10 else None if item == 0 else item + ) def complex_comprehension(self): - self.processed_data = [(x ** 2 if x % 2 == 0 else x ** 3) for x in - range(1, 100) if x % 5 == 0 and x != 50 and x > 3] + self.processed_data = [ + (x**2 if x % 2 == 0 else x**3) + for x in range(1, 100) + if x % 5 == 0 and x != 50 and x > 3 + ] def long_chain(self): try: - deep_value = self.data[0][1]['details']['info']['more_info'][2][ - 'target'] + deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] return deep_value except (KeyError, IndexError, TypeError): return None @@ -92,11 +117,11 @@ def long_scope_chaining(): for d in range(10): for e in range(10): if a + b + c + d + e > 25: - return 'Done' + return "Done" -if __name__ == '__main__': +if __name__ == "__main__": sample_data = [1, 2, 3, 4, 5] processor = DataProcessor(sample_data) processed = processor.process_all_data() - print('Processed Data:', processed) + print("Processed Data:", processed) diff --git a/tests/input/inefficent_code_example_2_tests.py b/tests/input/inefficent_code_example_2_tests.py index b4286d2c..110caabb 100644 --- a/tests/input/inefficent_code_example_2_tests.py +++ b/tests/input/inefficent_code_example_2_tests.py @@ -1,11 +1,12 @@ import unittest from datetime import datetime -from tests.input.ineffcient_code_example_2 import ( +from ineffcient_code_example_2 import ( AdvancedProcessor, DataProcessor, ) # Just to show the unused import issue + # Assuming the classes DataProcessor and AdvancedProcessor are already defined # and imported @@ -17,8 +18,8 @@ def test_process_all_data(self): data = [1, 2, 3, 4, 5] processor = DataProcessor(data) processed_data = processor.process_all_data() - # Expecting [10, 20] after filtering out None, 0, and single character numbers - self.assertEqual(processed_data, [10, 20]) + # Expecting values [10, 20, 30, 40, 50] (because all are greater than 1 character in length) + self.assertEqual(processed_data, [10, 20, 30, 40, 50]) def test_process_all_data_empty(self): # Test with empty data list @@ -54,13 +55,39 @@ def test_complex_comprehension(self): # Test complex list comprehension processor = AdvancedProcessor([1, 2, 3, 4, 5]) processor.complex_comprehension() - expected_result = [4, 64, 256, 1296, 1024, 4096, 7776, 15625] + expected_result = [ + 125, + 100, + 3375, + 400, + 15625, + 900, + 42875, + 1600, + 91125, + 166375, + 3600, + 274625, + 4900, + 421875, + 6400, + 614125, + 8100, + 857375, + ] self.assertEqual(processor.processed_data, expected_result) def test_long_chain_valid(self): # Test valid deep chain access data = [ - {"details": {"info": {"more_info": [{}, {}, {"target": "Valid Value"}]}}} + [ + None, + { + "details": { + "info": {"more_info": [{}, {}, {"target": "Valid Value"}]} + } + }, + ] ] processor = AdvancedProcessor(data) result = processor.long_chain() From 4fdcfb3d18133a34ea4e654fb4fc20b229c7e0ff Mon Sep 17 00:00:00 2001 From: Nivetha Kuruparan Date: Sun, 10 Nov 2024 22:35:40 -0500 Subject: [PATCH 076/105] Changed ending message --- src1/main.py | 2 +- src1/outputs/all_pylint_smells.json | 638 ++++++----------------- src1/outputs/final_emissions_data.txt | 40 +- src1/outputs/initial_emissions_data.txt | 40 +- src1/outputs/log.txt | 140 +++-- src1/outputs/refactored-test-case.py | 106 +--- tests/input/ineffcient_code_example_1.py | 6 +- tests/input/ineffcient_code_example_2.py | 81 ++- 8 files changed, 356 insertions(+), 697 deletions(-) diff --git a/src1/main.py b/src1/main.py index ab829f23..208cfee6 100644 --- a/src1/main.py +++ b/src1/main.py @@ -132,7 +132,7 @@ def main(): # The emissions from codecarbon are so inconsistent that this could be a possibility :( if final_emission >= initial_emissions: logger.log( - "Final emissions are greater than initial emissions; we are going to fail" + "Final emissions are greater than initial emissions. No optimal refactorings found." ) else: logger.log(f"Saved {initial_emissions - final_emission} kg CO2") diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json index e9f2780d..ff83e649 100644 --- a/src1/outputs/all_pylint_smells.json +++ b/src1/outputs/all_pylint_smells.json @@ -1,54 +1,15 @@ [ - { - "column": 74, - "endColumn": null, - "endLine": null, - "line": 19, - "message": "Trailing whitespace", - "message-id": "C0303", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "trailing-whitespace", - "type": "convention" - }, - { - "column": 95, - "endColumn": null, - "endLine": null, - "line": 35, - "message": "Trailing whitespace", - "message-id": "C0303", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "trailing-whitespace", - "type": "convention" - }, { "column": 0, "endColumn": null, "endLine": null, - "line": 35, - "message": "Line too long (95/80)", - "message-id": "C0301", - "module": "ineffcient_code_example_2", - "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "line-too-long", - "type": "convention" - }, - { - "column": 71, - "endColumn": null, - "endLine": null, - "line": 59, - "message": "Trailing whitespace", - "message-id": "C0303", - "module": "ineffcient_code_example_2", + "line": 33, + "message": "Final newline missing", + "message-id": "C0304", + "module": "ineffcient_code_example_1", "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "trailing-whitespace", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "missing-final-newline", "type": "convention" }, { @@ -58,519 +19,244 @@ "line": 1, "message": "Missing module docstring", "message-id": "C0114", - "module": "ineffcient_code_example_2", + "module": "ineffcient_code_example_1", "obj": "", - "path": "tests/input/ineffcient_code_example_2.py", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-module-docstring", "type": "convention" }, { "column": 0, - "endColumn": 19, - "endLine": 2, - "line": 2, - "message": "Missing class docstring", - "message-id": "C0115", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 24, - "endLine": 8, - "line": 8, + "endColumn": 16, + "endLine": 3, + "line": 3, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.process_all_data", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "has_positive", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, { - "column": 19, - "endColumn": 28, - "endLine": 15, - "line": 15, - "message": "Catching too general exception Exception", - "message-id": "W0718", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.process_all_data", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "broad-exception-caught", - "type": "warning" - }, - { - "column": 12, - "endColumn": 46, - "endLine": 16, - "line": 11, - "message": "try clause contains 2 statements, expected at most 1", - "message-id": "W0717", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.process_all_data", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-try-statements", - "type": "warning" - }, - { - "column": 35, - "endColumn": 43, - "endLine": 20, - "line": 19, - "message": "Used builtin function 'filter'. Using a list comprehension can be clearer.", - "message-id": "W0141", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.process_all_data", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "bad-builtin", - "type": "warning" + "column": 11, + "endColumn": 44, + "endLine": 5, + "line": 5, + "message": "Use a generator instead 'any(num > 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "has_positive", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" }, { - "column": 4, - "endColumn": 27, - "endLine": 24, - "line": 24, + "column": 0, + "endColumn": 20, + "endLine": 7, + "line": 7, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "all_non_negative", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, - { - "column": 4, - "endColumn": 27, - "endLine": 24, - "line": 24, - "message": "Too many arguments (8/6)", - "message-id": "R0913", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 24, - "line": 24, - "message": "Too many positional arguments (8/5)", - "message-id": "R0917", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-positional-arguments", - "type": "refactor" - }, { "column": 11, - "endColumn": 34, - "endLine": 26, - "line": 26, - "message": "Consider using a named constant or an enum instead of ''multiply''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 13, - "endColumn": 31, - "endLine": 28, - "line": 28, - "message": "Consider using a named constant or an enum instead of ''add''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", + "endColumn": 45, + "endLine": 9, + "line": 9, + "message": "Use a generator instead 'all(num >= 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_non_negative", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" }, { - "column": 34, - "endColumn": 39, - "endLine": 24, - "line": 24, - "message": "Unused argument 'flag1'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 41, - "endColumn": 46, - "endLine": 24, - "line": 24, - "message": "Unused argument 'flag2'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 19, - "endColumn": 25, - "endLine": 25, - "line": 25, - "message": "Unused argument 'option'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 27, - "endColumn": 38, - "endLine": 25, - "line": 25, - "message": "Unused argument 'final_stage'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 4, - "endColumn": 31, - "endLine": 35, - "line": 35, + "column": 0, + "endColumn": 26, + "endLine": 11, + "line": 11, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "contains_large_strings", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, - { - "column": 4, - "endColumn": 31, - "endLine": 35, - "line": 35, - "message": "Too many arguments (12/6)", - "message-id": "R0913", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 31, - "endLine": 35, - "line": 35, - "message": "Too many positional arguments (12/5)", - "message-id": "R0917", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-positional-arguments", - "type": "refactor" - }, { "column": 11, - "endColumn": 34, - "endLine": 38, - "line": 38, - "message": "Consider using a named constant or an enum instead of ''multiply''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 13, - "endColumn": 31, - "endLine": 40, - "line": 40, - "message": "Consider using a named constant or an enum instead of ''add''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 13, - "endColumn": 28, - "endLine": 42, - "line": 42, - "message": "Consider using a named constant or an enum instead of ''true''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 13, - "endColumn": 28, - "endLine": 44, - "line": 44, - "message": "Consider using a named constant or an enum instead of ''true''.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", + "endColumn": 46, + "endLine": 13, + "line": 13, + "message": "Use a generator instead 'any(len(s) > 10 for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "contains_large_strings", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" }, { - "column": 13, - "endColumn": 28, - "endLine": 46, - "line": 46, - "message": "Consider using a named constant or an enum instead of ''true''.", + "column": 16, + "endColumn": 27, + "endLine": 13, + "line": 13, + "message": "Consider using a named constant or an enum instead of '10'.", "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "contains_large_strings", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "magic-value-comparison", "type": "refactor" }, - { - "column": 4, - "endColumn": 31, - "endLine": 35, - "line": 35, - "message": "Too many branches (7/3)", - "message-id": "R0912", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-branches", - "type": "refactor" - }, - { - "column": 43, - "endColumn": 49, - "endLine": 36, - "line": 36, - "message": "Unused argument 'option'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, - { - "column": 51, - "endColumn": 62, - "endLine": 36, - "line": 36, - "message": "Unused argument 'final_stage'", - "message-id": "W0613", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "unused-argument", - "type": "warning" - }, { "column": 0, - "endColumn": 23, - "endLine": 55, - "line": 55, - "message": "Missing class docstring", - "message-id": "C0115", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "missing-class-docstring", - "type": "convention" - }, - { - "column": 4, - "endColumn": 18, - "endLine": 58, - "line": 58, + "endColumn": 17, + "endLine": 15, + "line": 15, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.check_data", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "all_uppercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, { - "column": 24, - "endColumn": 33, - "endLine": 59, - "line": 59, - "message": "Consider using a named constant or an enum instead of '10'.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.check_data", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", + "column": 11, + "endColumn": 46, + "endLine": 17, + "line": 17, + "message": "Use a generator instead 'all(s.isupper() for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_uppercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" }, { - "column": 4, - "endColumn": 29, - "endLine": 62, - "line": 62, + "column": 0, + "endColumn": 28, + "endLine": 19, + "line": 19, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.complex_comprehension", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "contains_special_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, { - "column": 44, - "endColumn": 51, - "endLine": 64, - "line": 64, - "message": "Consider using a named constant or an enum instead of '50'.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.complex_comprehension", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", + "column": 11, + "endColumn": 63, + "endLine": 21, + "line": 21, + "message": "Use a generator instead 'any(num % 5 == 0 and num > 100 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "contains_special_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" }, { - "column": 56, - "endColumn": 61, - "endLine": 64, - "line": 64, - "message": "Consider using a named constant or an enum instead of '3'.", + "column": 33, + "endColumn": 42, + "endLine": 21, + "line": 21, + "message": "Consider using a named constant or an enum instead of '100'.", "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.complex_comprehension", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "contains_special_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "magic-value-comparison", "type": "refactor" }, { - "column": 4, - "endColumn": 18, - "endLine": 66, - "line": 66, + "column": 0, + "endColumn": 17, + "endLine": 23, + "line": 23, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_chain", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "all_lowercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, { - "column": 8, - "endColumn": 23, - "endLine": 72, - "line": 67, - "message": "try clause contains 2 statements, expected at most 1", - "message-id": "W0717", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_chain", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-try-statements", - "type": "warning" + "column": 11, + "endColumn": 46, + "endLine": 25, + "line": 25, + "message": "Use a generator instead 'all(s.islower() for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_lowercase", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", + "type": "refactor" }, { - "column": 4, - "endColumn": 27, - "endLine": 75, - "line": 75, + "column": 0, + "endColumn": 20, + "endLine": 27, + "line": 27, "message": "Missing function or method docstring", "message-id": "C0116", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "tests/input/ineffcient_code_example_2.py", + "module": "ineffcient_code_example_1", + "obj": "any_even_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", "symbol": "missing-function-docstring", "type": "convention" }, { - "column": 31, - "endColumn": 53, - "endLine": 81, - "line": 81, - "message": "Consider using a named constant or an enum instead of '25'.", - "message-id": "R2004", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 27, - "endLine": 75, - "line": 75, - "message": "Too many branches (6/3)", - "message-id": "R0912", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-branches", + "column": 11, + "endColumn": 49, + "endLine": 29, + "line": 29, + "message": "Use a generator instead 'any(num % 2 == 0 for num in numbers)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "any_even_numbers", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" }, { - "column": 8, - "endColumn": 45, - "endLine": 82, - "line": 76, - "message": "Too many nested blocks (6/3)", - "message-id": "R1702", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-nested-blocks", - "type": "refactor" + "column": 0, + "endColumn": 28, + "endLine": 31, + "line": 31, + "message": "Missing function or method docstring", + "message-id": "C0116", + "module": "ineffcient_code_example_1", + "obj": "all_strings_start_with_a", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "missing-function-docstring", + "type": "convention" }, { - "column": 4, - "endColumn": 27, - "endLine": 75, - "line": 75, - "message": "Either all return statements in a function should return an expression, or none of them should.", - "message-id": "R1710", - "module": "ineffcient_code_example_2", - "obj": "AdvancedProcessor.long_scope_chaining", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "inconsistent-return-statements", + "column": 11, + "endColumn": 52, + "endLine": 33, + "line": 33, + "message": "Use a generator instead 'all(s.startswith('A') for s in strings)'", + "message-id": "R1729", + "module": "ineffcient_code_example_1", + "obj": "all_strings_start_with_a", + "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", + "symbol": "use-a-generator", "type": "refactor" - }, - { - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "column": 18, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 18, - "message": "Method chain too long (3/3)", - "message-id": "LMC001", - "module": "ineffcient_code_example_2.py", - "obj": "", - "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "long-message-chain", - "type": "convention" } ] \ No newline at end of file diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt index bbb58bfe..da2a02df 100644 --- a/src1/outputs/final_emissions_data.txt +++ b/src1/outputs/final_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 16, - "cpu_energy": NaN, - "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "cpu_power": NaN, - "duration": 4.9795035580173135, - "emissions": NaN, - "emissions_rate": NaN, - "energy_consumed": NaN, + "cpu_count": 12, + "cpu_energy": 5.891369538386888e-06, + "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", + "cpu_power": 47.99377777777777, + "duration": 2.7314686000026995, + "emissions": 2.77266175958425e-07, + "emissions_rate": 1.0150809566624745e-07, + "energy_consumed": 7.020027544402079e-06, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": 1, - "gpu_energy": NaN, - "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "gpu_power": NaN, - "latitude": 43.266, - "longitude": -79.9441, + "gpu_energy": 4.2333367200000005e-07, + "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_power": 3.4636462191974235, + "latitude": 43.2642, + "longitude": -79.9143, "on_cloud": "N", - "os": "macOS-14.4-x86_64-i386-64bit", + "os": "Windows-10-10.0.19045-SP0", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.10.10", - "ram_energy": 6.903137672149266e-08, - "ram_power": 6.0, - "ram_total_size": 16.0, + "python_version": "3.13.0", + "ram_energy": 7.05324334015191e-07, + "ram_power": 5.91276741027832, + "ram_total_size": 15.767379760742188, "region": "ontario", - "run_id": "ffca42c2-b044-4cec-a165-6c539f80634d", - "timestamp": "2024-11-10T19:03:14", + "run_id": "463da52e-39ac-460f-a23f-e447b0b7c653", + "timestamp": "2024-11-10T22:32:38", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt index d5a09a0e..8be8f489 100644 --- a/src1/outputs/initial_emissions_data.txt +++ b/src1/outputs/initial_emissions_data.txt @@ -4,31 +4,31 @@ "codecarbon_version": "2.7.2", "country_iso_code": "CAN", "country_name": "Canada", - "cpu_count": 16, - "cpu_energy": NaN, - "cpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "cpu_power": NaN, - "duration": 5.134236281970516, - "emissions": NaN, - "emissions_rate": NaN, - "energy_consumed": NaN, + "cpu_count": 12, + "cpu_energy": 2.849305427399163e-06, + "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", + "cpu_power": 25.30654545454545, + "duration": 2.812684600008652, + "emissions": 1.5001510415414538e-07, + "emissions_rate": 5.3335203013407164e-08, + "energy_consumed": 3.798191970579047e-06, "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", "gpu_count": 1, - "gpu_energy": NaN, - "gpu_model": "Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz", - "gpu_power": NaN, - "latitude": 43.266, - "longitude": -79.9441, + "gpu_energy": 2.97778016e-07, + "gpu_model": "1 x NVIDIA GeForce RTX 2060", + "gpu_power": 2.650454217767624, + "latitude": 43.2642, + "longitude": -79.9143, "on_cloud": "N", - "os": "macOS-14.4-x86_64-i386-64bit", + "os": "Windows-10-10.0.19045-SP0", "project_name": "codecarbon", "pue": 1.0, - "python_version": "3.10.10", - "ram_energy": 8.0895381688606e-08, - "ram_power": 6.0, - "ram_total_size": 16.0, + "python_version": "3.13.0", + "ram_energy": 6.511085271798837e-07, + "ram_power": 5.91276741027832, + "ram_total_size": 15.767379760742188, "region": "ontario", - "run_id": "28b554a1-c4d4-4657-b8ba-1e06fa8652b5", - "timestamp": "2024-11-10T19:02:47", + "run_id": "34062555-0738-4d57-93a2-98b97fbb4d69", + "timestamp": "2024-11-10T22:31:23", "tracking_mode": "machine" } \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt index aec37f4e..4db6d938 100644 --- a/src1/outputs/log.txt +++ b/src1/outputs/log.txt @@ -1,44 +1,96 @@ -[2024-11-10 19:02:34] ##################################################################################################### -[2024-11-10 19:02:34] CAPTURE INITIAL EMISSIONS -[2024-11-10 19:02:34] ##################################################################################################### -[2024-11-10 19:02:34] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 19:02:42] CodeCarbon measurement completed successfully. -[2024-11-10 19:02:47] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/initial_emissions_data.txt -[2024-11-10 19:02:47] Initial Emissions: nan kg CO2 -[2024-11-10 19:02:47] ##################################################################################################### - - -[2024-11-10 19:02:47] ##################################################################################################### -[2024-11-10 19:02:47] CAPTURE CODE SMELLS -[2024-11-10 19:02:47] ##################################################################################################### -[2024-11-10 19:02:47] Running Pylint analysis on ineffcient_code_example_2.py -[2024-11-10 19:02:48] Pylint analyzer completed successfully. -[2024-11-10 19:02:48] Running custom parsers: -[2024-11-10 19:02:48] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_pylint_smells.json -[2024-11-10 19:02:48] Filtering pylint smells -[2024-11-10 19:02:48] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/all_configured_pylint_smells.json -[2024-11-10 19:02:48] Refactorable code smells: 3 -[2024-11-10 19:02:48] ##################################################################################################### - - -[2024-11-10 19:02:48] ##################################################################################################### -[2024-11-10 19:02:48] REFACTOR CODE SMELLS -[2024-11-10 19:02:48] ##################################################################################################### -[2024-11-10 19:02:48] Refactored long message chain and saved to ineffcient_code_example_2_temp.py -[2024-11-10 19:02:48] Starting CodeCarbon energy measurement on ineffcient_code_example_2_temp.py -[2024-11-10 19:02:55] CodeCarbon measurement completed successfully. -[2024-11-10 19:03:00] Measured emissions for 'ineffcient_code_example_2_temp.py': nan -[2024-11-10 19:03:00] ##################################################################################################### - - -[2024-11-10 19:03:00] ##################################################################################################### -[2024-11-10 19:03:00] CAPTURE FINAL EMISSIONS -[2024-11-10 19:03:00] ##################################################################################################### -[2024-11-10 19:03:00] Starting CodeCarbon energy measurement on ineffcient_code_example_2.py -[2024-11-10 19:03:09] CodeCarbon measurement completed successfully. -[2024-11-10 19:03:14] Output saved to /Users/mya/Code/Capstone/capstone--source-code-optimizer/src1/outputs/final_emissions_data.txt -[2024-11-10 19:03:14] Final Emissions: nan kg CO2 -[2024-11-10 19:03:14] ##################################################################################################### - - -[2024-11-10 19:03:14] Saved nan kg CO2 +[2024-11-10 22:31:14] ##################################################################################################### +[2024-11-10 22:31:14] CAPTURE INITIAL EMISSIONS +[2024-11-10 22:31:14] ##################################################################################################### +[2024-11-10 22:31:14] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-10 22:31:20] CodeCarbon measurement completed successfully. +[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt +[2024-11-10 22:31:23] Initial Emissions: 1.5001510415414535e-07 kg CO2 +[2024-11-10 22:31:23] ##################################################################################################### + + +[2024-11-10 22:31:23] ##################################################################################################### +[2024-11-10 22:31:23] CAPTURE CODE SMELLS +[2024-11-10 22:31:23] ##################################################################################################### +[2024-11-10 22:31:23] Running Pylint analysis on ineffcient_code_example_1.py +[2024-11-10 22:31:23] Pylint analyzer completed successfully. +[2024-11-10 22:31:23] Running custom parsers: +[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json +[2024-11-10 22:31:23] Filtering pylint smells +[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json +[2024-11-10 22:31:23] Refactorable code smells: 8 +[2024-11-10 22:31:23] ##################################################################################################### + + +[2024-11-10 22:31:23] ##################################################################################################### +[2024-11-10 22:31:23] REFACTOR CODE SMELLS +[2024-11-10 22:31:23] ##################################################################################################### +[2024-11-10 22:31:23] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 5 for identified code smell. +[2024-11-10 22:31:23] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:31:29] CodeCarbon measurement completed successfully. +[2024-11-10 22:31:32] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.606659214506875e-07 +[2024-11-10 22:31:32] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.606659214506875e-07 kg CO2. +[2024-11-10 22:31:32] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 22:31:32] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 9 for identified code smell. +[2024-11-10 22:31:32] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:31:38] CodeCarbon measurement completed successfully. +[2024-11-10 22:31:40] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.5569213706053624e-07 +[2024-11-10 22:31:40] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.5569213706053624e-07 kg CO2. +[2024-11-10 22:31:40] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 22:31:40] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 13 for identified code smell. +[2024-11-10 22:31:40] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:31:46] CodeCarbon measurement completed successfully. +[2024-11-10 22:31:48] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.9193877464710126e-07 +[2024-11-10 22:31:48] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.9193877464710126e-07 kg CO2. +[2024-11-10 22:31:48] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 22:31:48] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 17 for identified code smell. +[2024-11-10 22:31:48] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:31:54] CodeCarbon measurement completed successfully. +[2024-11-10 22:31:57] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.8302076101856833e-07 +[2024-11-10 22:31:57] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.8302076101856833e-07 kg CO2. +[2024-11-10 22:31:57] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 22:31:57] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 21 for identified code smell. +[2024-11-10 22:31:57] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:32:03] CodeCarbon measurement completed successfully. +[2024-11-10 22:32:05] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.9562061607657285e-07 +[2024-11-10 22:32:05] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.9562061607657285e-07 kg CO2. +[2024-11-10 22:32:05] No emission improvement after refactoring. Discarded refactored changes. + +[2024-11-10 22:32:05] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 25 for identified code smell. +[2024-11-10 22:32:05] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:32:11] CodeCarbon measurement completed successfully. +[2024-11-10 22:32:13] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.066947119830384e-07 +[2024-11-10 22:32:13] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.066947119830384e-07 kg CO2. +[2024-11-10 22:32:13] Refactored list comprehension to generator expression on line 25 and saved. + +[2024-11-10 22:32:13] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 29 for identified code smell. +[2024-11-10 22:32:13] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:32:19] CodeCarbon measurement completed successfully. +[2024-11-10 22:32:21] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.1866016806014599e-07 +[2024-11-10 22:32:21] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.1866016806014599e-07 kg CO2. +[2024-11-10 22:32:21] Refactored list comprehension to generator expression on line 29 and saved. + +[2024-11-10 22:32:21] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 33 for identified code smell. +[2024-11-10 22:32:21] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp +[2024-11-10 22:32:27] CodeCarbon measurement completed successfully. +[2024-11-10 22:32:29] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.3302157130404294e-07 +[2024-11-10 22:32:29] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.3302157130404294e-07 kg CO2. +[2024-11-10 22:32:29] Refactored list comprehension to generator expression on line 33 and saved. + +[2024-11-10 22:32:29] ##################################################################################################### + + +[2024-11-10 22:32:29] ##################################################################################################### +[2024-11-10 22:32:29] CAPTURE FINAL EMISSIONS +[2024-11-10 22:32:29] ##################################################################################################### +[2024-11-10 22:32:29] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py +[2024-11-10 22:32:36] CodeCarbon measurement completed successfully. +[2024-11-10 22:32:38] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt +[2024-11-10 22:32:38] Final Emissions: 2.77266175958425e-07 kg CO2 +[2024-11-10 22:32:38] ##################################################################################################### + + +[2024-11-10 22:32:38] Final emissions are greater than initial emissions; we are going to fail diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py index 720f7c53..2053b7ed 100644 --- a/src1/outputs/refactored-test-case.py +++ b/src1/outputs/refactored-test-case.py @@ -1,89 +1,33 @@ +# Should trigger Use A Generator code smells -class DataProcessor: +def has_positive(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num > 0 for num in numbers]) - def __init__(self, data): - self.data = data - self.processed_data = [] +def all_non_negative(numbers): + # List comprehension inside `all()` - triggers R1729 + return all([num >= 0 for num in numbers]) - def process_all_data(self): - results = [] - for item in self.data: - try: - result = self.complex_calculation(item, True, False, - 'multiply', 10, 20, None, 'end') - results.append(result) - except Exception as e: - print('An error occurred:', e) - if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(' ', '_').lower()) - self.processed_data = list(filter(lambda x: x is not None and x != - 0 and len(str(x)) > 1, results)) - return self.processed_data +def contains_large_strings(strings): + # List comprehension inside `any()` - triggers R1729 + return any([len(s) > 10 for s in strings]) - @staticmethod - def complex_calculation(item, flag1, flag2, operation, threshold, - max_value, option, final_stage): - if operation == 'multiply': - result = item * threshold - elif operation == 'add': - result = item + max_value - else: - result = item - return result +def all_uppercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.isupper() for s in strings]) - @staticmethod - def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, operation, threshold, - max_value, option, final_stage, min_value): - value = 0 - if operation == 'multiply': - value = item1 * item2 * item3 - elif operation == 'add': - value = item1 + item2 + item3 - elif flag1 == 'true': - value = item1 - elif flag2 == 'true': - value = item2 - elif flag3 == 'true': - value = item3 - elif max_value < threshold: - value = max_value - else: - value = min_value - return value +def contains_special_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 5 == 0 and num > 100 for num in numbers]) +def all_lowercase(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.islower() for s in strings]) -class AdvancedProcessor(DataProcessor): +def any_even_numbers(numbers): + # List comprehension inside `any()` - triggers R1729 + return any([num % 2 == 0 for num in numbers]) - @staticmethod - def check_data(item): - return (True if item > 10 else False if item < -10 else None if - item == 0 else item) - - def complex_comprehension(self): - self.processed_data = [(x ** 2 if x % 2 == 0 else x ** 3) for x in - range(1, 100) if x % 5 == 0 and x != 50 and x > 3] - - def long_chain(self): - try: - deep_value = self.data[0][1]['details']['info']['more_info'][2][ - 'target'] - return deep_value - except (KeyError, IndexError, TypeError): - return None - - @staticmethod - def long_scope_chaining(): - for a in range(10): - for b in range(10): - for c in range(10): - for d in range(10): - for e in range(10): - if a + b + c + d + e > 25: - return 'Done' - - -if __name__ == '__main__': - sample_data = [1, 2, 3, 4, 5] - processor = DataProcessor(sample_data) - processed = processor.process_all_data() - print('Processed Data:', processed) +def all_strings_start_with_a(strings): + # List comprehension inside `all()` - triggers R1729 + return all([s.startswith('A') for s in strings]) \ No newline at end of file diff --git a/tests/input/ineffcient_code_example_1.py b/tests/input/ineffcient_code_example_1.py index 2053b7ed..dae6717c 100644 --- a/tests/input/ineffcient_code_example_1.py +++ b/tests/input/ineffcient_code_example_1.py @@ -22,12 +22,12 @@ def contains_special_numbers(numbers): def all_lowercase(strings): # List comprehension inside `all()` - triggers R1729 - return all([s.islower() for s in strings]) + return all(s.islower() for s in strings) def any_even_numbers(numbers): # List comprehension inside `any()` - triggers R1729 - return any([num % 2 == 0 for num in numbers]) + return any(num % 2 == 0 for num in numbers) def all_strings_start_with_a(strings): # List comprehension inside `all()` - triggers R1729 - return all([s.startswith('A') for s in strings]) \ No newline at end of file + return all(s.startswith('A') for s in strings) diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 52ec6c1f..85811496 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,9 +1,9 @@ -import datetime # unused import -# test case for unused variable and class attribute + class Temp: - def __init__(self) -> None: + + def __init__(self) ->None: self.unused_class_attribute = True self.a = 3 @@ -20,65 +20,45 @@ def __init__(self, data): self.processed_data = [] def process_all_data(self): - if not self.data: # Check for empty data + if not self.data: return [] - results = [] for item in self.data: try: - result = self.complex_calculation( - item, True, False, "multiply", 10, 20, None, "end" - ) + result = self.complex_calculation(item, True, False, + 'multiply', 10, 20, None, 'end') results.append(result) except Exception as e: - print("An error occurred:", e) - - # Check if the list is not empty before accessing self.data[0] + print('An error occurred:', e) if isinstance(self.data[0], str): - print(self.data[0].upper().strip().replace(" ", "_").lower()) - - self.processed_data = list( - filter(lambda x: x is not None and x != 0 and len(str(x)) > 1, results) - ) + print(self.data[0].upper().strip().replace(' ', '_').lower()) + self.processed_data = list(filter(lambda x: x is not None and x != + 0 and len(str(x)) > 1, results)) return self.processed_data @staticmethod - def complex_calculation( - item, flag1, flag2, operation, threshold, max_value, option, final_stage - ): - if operation == "multiply": + def complex_calculation(item, operation, threshold, max_value): + if operation == 'multiply': result = item * threshold - elif operation == "add": + elif operation == 'add': result = item + max_value else: result = item return result @staticmethod - def multi_param_calculation( - item1, - item2, - item3, - flag1, - flag2, - flag3, - operation, - threshold, - max_value, - option, - final_stage, - min_value, - ): + def multi_param_calculation(item1, item2, item3, flag1, flag2, flag3, + operation, threshold, max_value, option, final_stage, min_value): value = 0 - if operation == "multiply": + if operation == 'multiply': value = item1 * item2 * item3 - elif operation == "add": + elif operation == 'add': value = item1 + item2 + item3 - elif flag1 == "true": + elif flag1 == 'true': value = item1 - elif flag2 == "true": + elif flag2 == 'true': value = item2 - elif flag3 == "true": + elif flag3 == 'true': value = item3 elif max_value < threshold: value = max_value @@ -91,20 +71,17 @@ class AdvancedProcessor(DataProcessor): @staticmethod def check_data(item): - return ( - True if item > 10 else False if item < -10 else None if item == 0 else item - ) + return (True if item > 10 else False if item < -10 else None if + item == 0 else item) def complex_comprehension(self): - self.processed_data = [ - (x**2 if x % 2 == 0 else x**3) - for x in range(1, 100) - if x % 5 == 0 and x != 50 and x > 3 - ] + self.processed_data = [(x ** 2 if x % 2 == 0 else x ** 3) for x in + range(1, 100) if x % 5 == 0 and x != 50 and x > 3] def long_chain(self): try: - deep_value = self.data[0][1]["details"]["info"]["more_info"][2]["target"] + deep_value = self.data[0][1]['details']['info']['more_info'][2][ + 'target'] return deep_value except (KeyError, IndexError, TypeError): return None @@ -117,11 +94,11 @@ def long_scope_chaining(): for d in range(10): for e in range(10): if a + b + c + d + e > 25: - return "Done" + return 'Done' -if __name__ == "__main__": +if __name__ == '__main__': sample_data = [1, 2, 3, 4, 5] processor = DataProcessor(sample_data) processed = processor.process_all_data() - print("Processed Data:", processed) + print('Processed Data:', processed) From 96a96543e6d379cfde0fe492baac36e03e64b2fb Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 22:17:16 -0800 Subject: [PATCH 077/105] Added custom pylint smell for unused vars --- src1/analyzers/pylint_analyzer.py | 132 +++++++++++++++++++++++++- src1/refactorers/unused_refactorer.py | 11 +-- src1/utils/analyzers_config.py | 1 + src1/utils/refactorer_factory.py | 4 +- 4 files changed, 132 insertions(+), 16 deletions(-) diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index 03056eb1..bdf85f7d 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -4,11 +4,8 @@ from pylint.lint import Run from pylint.reporters.json_reporter import JSONReporter - from io import StringIO - from utils.logger import Logger - from .base_analyzer import Analyzer from utils.analyzers_config import ( PylintSmell, @@ -16,7 +13,6 @@ IntermediateSmells, EXTRA_PYLINT_OPTIONS, ) - from utils.ast_parser import parse_line @@ -67,8 +63,17 @@ def analyze(self): self.file_path, os.path.basename(self.file_path), ) - print("THIS IS LMC DATA:", lmc_data) + # print("THIS IS LMC DATA:", lmc_data) + self.smells_data += lmc_data + lmc_data = PylintAnalyzer.detect_unused_variables_and_attributes( + PylintAnalyzer.read_code_from_path(self.file_path), + self.file_path, + os.path.basename(self.file_path), + ) + # print("THIS IS LMC DATA FOR UNUSED:", lmc_data) self.smells_data += lmc_data + print(self.smells_data) + def configure_smells(self): """ @@ -182,6 +187,123 @@ def check_chain(node, chain_length=0): return results + def detect_unused_variables_and_attributes(code, file_path, module_name): + """ + Detects unused variables and class attributes in the given Python code and returns a list of results. + + Args: + - code (str): Python source code to be analyzed. + - file_path (str): The path to the file being analyzed (for reporting purposes). + - module_name (str): The name of the module (for reporting purposes). + + Returns: + - List of dictionaries: Each dictionary contains details about the detected unused variable or attribute. + """ + # Parse the code into an Abstract Syntax Tree (AST) + tree = ast.parse(code) + + # Store variable and attribute declarations and usage + declared_vars = set() + used_vars = set() + results = [] + used_lines = set() + + # Helper function to gather declared variables (including class attributes) + def gather_declarations(node): + # For assignment statements (variables or class attributes) + if isinstance(node, ast.Assign): + for target in node.targets: + if isinstance(target, ast.Name): # Simple variable + declared_vars.add(target.id) + elif isinstance(target, ast.Attribute): # Class attribute + declared_vars.add(f'{target.value.id}.{target.attr}') + + # For class attribute assignments (e.g., self.attribute) + elif isinstance(node, ast.ClassDef): + for class_node in ast.walk(node): + if isinstance(class_node, ast.Assign): + for target in class_node.targets: + if isinstance(target, ast.Name): + declared_vars.add(target.id) + elif isinstance(target, ast.Attribute): + declared_vars.add(f'{target.value.id}.{target.attr}') + + # Helper function to gather used variables and class attributes + def gather_usages(node): + if isinstance(node, ast.Name): # variable usage + if isinstance(node.ctx, ast.Load): # 'Load' means accessing the value + used_vars.add(node.id) + elif isinstance(node, ast.Attribute): + # Only add to used_vars if it's accessed (i.e., part of an expression) + if isinstance(node.ctx, ast.Load): # 'Load' means accessing the attribute + used_vars.add(f'{node.value}.{node.attr}') + + # Gather declared and used variables + for node in ast.walk(tree): + gather_declarations(node) + gather_usages(node) + + # Detect unused variables by finding declared variables not in used variables + unused_vars = declared_vars - used_vars + # print("Declared Vars: ", declared_vars) + # print("Used Vars: ", used_vars) + # print("Unused: ", unused_vars) + + for var in unused_vars: + print("var again") + # Locate the line number for each unused variable or attribute + line_no, column_no = None, None + for node in ast.walk(tree): + print("node: ", node) + if isinstance(node, ast.Name) and node.id == var: + line_no = node.lineno + column_no = node.col_offset + print(node.lineno) + result = { + "type": "convention", + "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", + "message": f"Unused variable or attribute '{var}'", + "message-id": "UV001", + "confidence": "UNDEFINED", + "module": module_name, + "obj": '', + "line": line_no, + "column": column_no, + "endLine": None, + "endColumn": None, + "path": file_path, + "absolutePath": file_path, # Assuming file_path is the absolute path + } + + results.append(result) + break + elif isinstance(node, ast.Attribute) and f'{node.value}.{node.attr}' == var: + line_no = node.lineno + column_no = node.col_offset + print(node.lineno) + result = { + "type": "convention", + "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", + "message": f"Unused variable or attribute '{var}'", + "message-id": "UV001", + "confidence": "UNDEFINED", + "module": module_name, + "obj": '', + "line": line_no, + "column": column_no, + "endLine": None, + "endColumn": None, + "path": file_path, + "absolutePath": file_path, # Assuming file_path is the absolute path + } + + results.append(result) + break + + return results + + + @staticmethod def read_code_from_path(file_path): """ diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index 1540c995..312927e9 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -24,7 +24,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa code_type = pylint_smell.get("message-id") print(code_type) self.logger.log( - f"Applying 'Remove Unused Imports' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." + f"Applying 'Remove Unused Stuff' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." ) # Load the source code as a list of lines @@ -43,13 +43,8 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # for logging purpose to see what was removed if code_type == "W0611": # UNUSED_IMPORT self.logger.log("Removed unused import.") - - elif code_type == "W0612": # UNUSED_VARIABLE - self.logger.log("Removed unused variable.") - - elif code_type == "W0615": # UNUSED_CLASS_ATTRIBUTE - self.logger.log("Removed unused class attribute.") - + elif code_type == "UV001": # UNUSED_VARIABLE + self.logger.log("Removed unused variable or class attribute") else: self.logger.log("No matching refactor type found for this code smell but line was removed.") return diff --git a/src1/utils/analyzers_config.py b/src1/utils/analyzers_config.py index daf12127..3fbf10d1 100644 --- a/src1/utils/analyzers_config.py +++ b/src1/utils/analyzers_config.py @@ -48,6 +48,7 @@ class PylintSmell(ExtendedEnum): class CustomSmell(ExtendedEnum): LONG_TERN_EXPR = "CUST-1" # Custom code smell for long ternary expressions LONG_MESSAGE_CHAIN = "LMC001" # CUSTOM CODE + UNUSED_VAR_OR_ATTRIBUTE = "UV001" # CUSTOM CODE class IntermediateSmells(ExtendedEnum): diff --git a/src1/utils/refactorer_factory.py b/src1/utils/refactorer_factory.py index d479d341..b7a09acc 100644 --- a/src1/utils/refactorer_factory.py +++ b/src1/utils/refactorer_factory.py @@ -40,9 +40,7 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): selected = UseAGeneratorRefactorer(logger) case AllSmells.UNUSED_IMPORT.value: selected = RemoveUnusedRefactorer(logger) - case AllSmells.UNUSED_VARIABLE.value: - selected = RemoveUnusedRefactorer(logger) - case AllSmells.UNUSED_CLASS_ATTRIBUTE.value: + case AllSmells.UNUSED_VAR_OR_ATTRIBUTE.value: selected = RemoveUnusedRefactorer(logger) case AllSmells.NO_SELF_USE.value: selected = MakeStaticRefactorer(logger) From 182b910fc94a2561a6b9c62362d0f851c963f645 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 22:21:14 -0800 Subject: [PATCH 078/105] fixed test copy for my test cases --- tests/_input_copies/test_2_copy.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/_input_copies/test_2_copy.py b/tests/_input_copies/test_2_copy.py index f8f32921..f28a83aa 100644 --- a/tests/_input_copies/test_2_copy.py +++ b/tests/_input_copies/test_2_copy.py @@ -1,3 +1,16 @@ +import datetime # unused import + +class Temp: + + def __init__(self) ->None: + self.unused_class_attribute = True + self.a = 3 + + def temp_function(self): + unused_var = 3 + b = 4 + return self.a + b + # LC: Large Class with too many responsibilities class DataProcessor: def __init__(self, data): From 7a0d4fd51dd4f76d6670459c6f9175b595a41822 Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 22:41:24 -0800 Subject: [PATCH 079/105] updated custom smell for unused vars to include unused class attributes --- src1/analyzers/pylint_analyzer.py | 68 ++++++++---------------- tests/input/ineffcient_code_example_2.py | 2 +- 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index bdf85f7d..45a36fac 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -63,14 +63,12 @@ def analyze(self): self.file_path, os.path.basename(self.file_path), ) - # print("THIS IS LMC DATA:", lmc_data) self.smells_data += lmc_data lmc_data = PylintAnalyzer.detect_unused_variables_and_attributes( PylintAnalyzer.read_code_from_path(self.file_path), self.file_path, os.path.basename(self.file_path), ) - # print("THIS IS LMC DATA FOR UNUSED:", lmc_data) self.smells_data += lmc_data print(self.smells_data) @@ -206,7 +204,6 @@ def detect_unused_variables_and_attributes(code, file_path, module_name): declared_vars = set() used_vars = set() results = [] - used_lines = set() # Helper function to gather declared variables (including class attributes) def gather_declarations(node): @@ -236,7 +233,7 @@ def gather_usages(node): elif isinstance(node, ast.Attribute): # Only add to used_vars if it's accessed (i.e., part of an expression) if isinstance(node.ctx, ast.Load): # 'Load' means accessing the attribute - used_vars.add(f'{node.value}.{node.attr}') + used_vars.add(f'{node.value.id}.{node.attr}') # Gather declared and used variables for node in ast.walk(tree): @@ -245,60 +242,37 @@ def gather_usages(node): # Detect unused variables by finding declared variables not in used variables unused_vars = declared_vars - used_vars - # print("Declared Vars: ", declared_vars) - # print("Used Vars: ", used_vars) - # print("Unused: ", unused_vars) for var in unused_vars: - print("var again") # Locate the line number for each unused variable or attribute line_no, column_no = None, None for node in ast.walk(tree): - print("node: ", node) if isinstance(node, ast.Name) and node.id == var: line_no = node.lineno column_no = node.col_offset - print(node.lineno) - result = { - "type": "convention", - "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", - "message": f"Unused variable or attribute '{var}'", - "message-id": "UV001", - "confidence": "UNDEFINED", - "module": module_name, - "obj": '', - "line": line_no, - "column": column_no, - "endLine": None, - "endColumn": None, - "path": file_path, - "absolutePath": file_path, # Assuming file_path is the absolute path - } - - results.append(result) break - elif isinstance(node, ast.Attribute) and f'{node.value}.{node.attr}' == var: + elif isinstance(node, ast.Attribute) and f'self.{node.attr}' == var and isinstance(node.value, ast.Name) and node.value.id == "self": line_no = node.lineno column_no = node.col_offset - print(node.lineno) - result = { - "type": "convention", - "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", - "message": f"Unused variable or attribute '{var}'", - "message-id": "UV001", - "confidence": "UNDEFINED", - "module": module_name, - "obj": '', - "line": line_no, - "column": column_no, - "endLine": None, - "endColumn": None, - "path": file_path, - "absolutePath": file_path, # Assuming file_path is the absolute path - } - - results.append(result) - break + break + + result = { + "type": "convention", + "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", + "message": f"Unused variable or attribute '{var}'", + "message-id": "UV001", + "confidence": "UNDEFINED", + "module": module_name, + "obj": '', + "line": line_no, + "column": column_no, + "endLine": None, + "endColumn": None, + "path": file_path, + "absolutePath": file_path, # Assuming file_path is the absolute path + } + + results.append(result) return results diff --git a/tests/input/ineffcient_code_example_2.py b/tests/input/ineffcient_code_example_2.py index 85811496..f587cf58 100644 --- a/tests/input/ineffcient_code_example_2.py +++ b/tests/input/ineffcient_code_example_2.py @@ -1,4 +1,4 @@ - +import datetime # unused import class Temp: From 49e1831597d9b157382aa340b2ffcdca4750d1ae Mon Sep 17 00:00:00 2001 From: Ayushi Amin Date: Sun, 10 Nov 2024 22:51:38 -0800 Subject: [PATCH 080/105] fixed small bug for unused attribute refactorer --- src1/analyzers/pylint_analyzer.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src1/analyzers/pylint_analyzer.py b/src1/analyzers/pylint_analyzer.py index 45a36fac..d88d3798 100644 --- a/src1/analyzers/pylint_analyzer.py +++ b/src1/analyzers/pylint_analyzer.py @@ -227,13 +227,13 @@ def gather_declarations(node): # Helper function to gather used variables and class attributes def gather_usages(node): - if isinstance(node, ast.Name): # variable usage - if isinstance(node.ctx, ast.Load): # 'Load' means accessing the value - used_vars.add(node.id) - elif isinstance(node, ast.Attribute): - # Only add to used_vars if it's accessed (i.e., part of an expression) - if isinstance(node.ctx, ast.Load): # 'Load' means accessing the attribute - used_vars.add(f'{node.value.id}.{node.attr}') + if isinstance(node, ast.Name) and isinstance(node.ctx, ast.Load): # Variable usage + used_vars.add(node.id) + elif isinstance(node, ast.Attribute) and isinstance(node.ctx, ast.Load): # Attribute usage + # Check if the attribute is accessed as `self.attribute` + if isinstance(node.value, ast.Name) and node.value.id == "self": + # Only add to used_vars if it’s in the form of `self.attribute` + used_vars.add(f'self.{node.attr}') # Gather declared and used variables for node in ast.walk(tree): From 2c28c441fef8f93514dbfa5f7a6abcad64c61607 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 02:32:44 -0500 Subject: [PATCH 081/105] added functionality testing + implement isolated refactorings --- src1/main.py | 4 +- .../long_message_chain_refactorer.py | 32 ++++---- .../long_parameter_list_refactorer.py | 26 ++++--- .../member_ignoring_method_refactorer.py | 31 +++++--- src1/refactorers/unused_refactorer.py | 23 +++--- .../refactorers/use_a_generator_refactorer.py | 28 ++++--- src1/testing/run_tests.py | 12 +++ tests/input/__init__.py | 0 tests/input/car_stuff.py | 73 +++++++++++++++++++ tests/input/car_stuff_tests.py | 34 +++++++++ 10 files changed, 207 insertions(+), 56 deletions(-) create mode 100644 src1/testing/run_tests.py create mode 100644 tests/input/__init__.py create mode 100644 tests/input/car_stuff.py create mode 100644 tests/input/car_stuff_tests.py diff --git a/src1/main.py b/src1/main.py index 208cfee6..80767359 100644 --- a/src1/main.py +++ b/src1/main.py @@ -13,7 +13,7 @@ def main(): # Path to the file to be analyzed TEST_FILE = os.path.abspath( - os.path.join(DIRNAME, "../tests/input/ineffcient_code_example_2.py") + os.path.join(DIRNAME, "../tests/input/car_stuff.py") ) # Set up logging @@ -103,6 +103,8 @@ def main(): "#####################################################################################################\n\n" ) + return + # Log start of emissions capture logger.log( "#####################################################################################################" diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index f456f24d..fc5cb7ee 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -1,6 +1,8 @@ import os import re import shutil + +from testing.run_tests import run_tests from .base_refactorer import BaseRefactorer @@ -20,8 +22,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Extract details from pylint_smell line_number = pylint_smell["line"] original_filename = os.path.basename(file_path) - temp_filename = f"{os.path.splitext(original_filename)[0]}_temp.py" + temp_filename = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LMCR_line_{line_number}.py" + self.logger.log( + f"Applying 'Separate Statements' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." + ) # Read the original file with open(file_path, "r") as f: lines = f.readlines() @@ -68,21 +73,22 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa temp_file.writelines(lines) # Log completion - self.logger.log(f"Refactored long message chain and saved to {temp_filename}") - # Measure emissions of the modified code final_emission = self.measure_energy(temp_file_path) #Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content - shutil.move(temp_file_path, file_path) - self.logger.log( - f"Refactored list comprehension to generator expression on line {pylint_smell["line"]} and saved.\n" - ) - else: - # Remove the temporary file if no improvement - os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) + if run_tests() == 0: + self.logger.log("All test pass! Functionality maintained.") + # shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored long message chain on line {pylint_smell["line"]} and saved.\n" + ) + return + + # Remove the temporary file if no improvement + # os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 599d739d..4ddafb4b 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -4,6 +4,7 @@ import astor from .base_refactorer import BaseRefactorer +from testing.run_tests import run_tests def get_used_parameters(function_node, params): @@ -160,7 +161,8 @@ def visit_Name(self, node): if modified: # Write back modified code to temporary file - temp_file_path = f"{os.path.basename(file_path).split('.')[0]}_temp.py" + original_filename = os.path.basename(file_path) + temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LPLR_line_{target_line}.py" with open(temp_file_path, "w") as temp_file: temp_file.write(astor.to_source(tree)) @@ -169,13 +171,15 @@ def visit_Name(self, node): if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content - shutil.move(temp_file_path, file_path) - self.logger.log( - f"Refactored long parameter list into data groups on line {target_line} and saved.\n" - ) - else: - # Remove the temporary file if no improvement - os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) + if run_tests() == 0: + self.logger.log("All test pass! Functionality maintained.") + # shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored long parameter list into data groups on line {target_line} and saved.\n" + ) + return + # Remove the temporary file if no improvement + # os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src1/refactorers/member_ignoring_method_refactorer.py index e5d1ac53..9ac115a3 100644 --- a/src1/refactorers/member_ignoring_method_refactorer.py +++ b/src1/refactorers/member_ignoring_method_refactorer.py @@ -4,6 +4,8 @@ import ast from ast import NodeTransformer +from testing.run_tests import run_tests + from .base_refactorer import BaseRefactorer @@ -40,7 +42,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Convert the modified AST back to source code modified_code = astor.to_source(modified_tree) - temp_file_path = f"{os.path.basename(file_path).split('.')[0]}_temp.py" + original_filename = os.path.basename(file_path) + temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_MIMR_line_{self.target_line}.py" + + print(os.path.abspath(temp_file_path)) + with open(temp_file_path, "w") as temp_file: temp_file.write(modified_code) @@ -50,16 +56,19 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content - shutil.move(temp_file_path, file_path) - self.logger.log( - f"Refactored list comprehension to generator expression on line {self.target_line} and saved.\n" - ) - else: - # Remove the temporary file if no improvement - os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) + + if run_tests() == 0: + self.logger.log("All test pass! Functionality maintained.") + # shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored 'Member Ignoring Method' to static method on line {self.target_line} and saved.\n" + ) + return + # Remove the temporary file if no improvement + # os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) def visit_FunctionDef(self, node): if node.lineno == self.target_line: diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index 1540c995..95733bdb 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -1,6 +1,7 @@ import os import shutil from refactorers.base_refactorer import BaseRefactorer +from testing.run_tests import run_tests class RemoveUnusedRefactorer(BaseRefactorer): def __init__(self, logger): @@ -55,21 +56,25 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa return # Write the modified content to a temporary file - temp_file_path = f"{file_path}.temp" + original_filename = os.path.basename(file_path) + temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UNSDR_line_{line_number}.py" + with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) # Measure emissions of the modified code final_emissions = self.measure_energy(temp_file_path) - shutil.move(temp_file_path, file_path) + # shutil.move(temp_file_path, file_path) # check for improvement in emissions (for logging purposes only) if self.check_energy_improvement(initial_emissions, final_emissions): - self.logger.log( - f"Removed unused stuff on line {line_number} and saved changes.\n" - ) - else: - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) \ No newline at end of file + if run_tests() == 0: + self.logger.log("All test pass! Functionality maintained.") + self.logger.log( + f"Removed unused stuff on line {line_number} and saved changes.\n" + ) + return + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) \ No newline at end of file diff --git a/src1/refactorers/use_a_generator_refactorer.py b/src1/refactorers/use_a_generator_refactorer.py index dcf991f9..01a7b491 100644 --- a/src1/refactorers/use_a_generator_refactorer.py +++ b/src1/refactorers/use_a_generator_refactorer.py @@ -4,6 +4,8 @@ import astor # For converting AST back to source code import shutil import os + +from testing.run_tests import run_tests from .base_refactorer import BaseRefactorer @@ -72,7 +74,9 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa modified_lines[line_number - 1] = indentation + modified_line + "\n" # Temporarily write the modified content to a temporary file - temp_file_path = f"{file_path}.temp" + original_filename = os.path.basename(file_path) + temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UGENR_line_{line_number}.py" + with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) @@ -82,16 +86,18 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content - shutil.move(temp_file_path, file_path) - self.logger.log( - f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" - ) - else: - # Remove the temporary file if no improvement - os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) + if run_tests() == 0: + self.logger.log("All test pass! Functionality maintained.") + # shutil.move(temp_file_path, file_path) + self.logger.log( + f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" + ) + return + # Remove the temporary file if no improvement + # os.remove(temp_file_path) + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) else: self.logger.log( "No applicable list comprehension found on the specified line.\n" diff --git a/src1/testing/run_tests.py b/src1/testing/run_tests.py new file mode 100644 index 00000000..41d40c35 --- /dev/null +++ b/src1/testing/run_tests.py @@ -0,0 +1,12 @@ +import os +import sys +import pytest + +REFACTOR_DIR = os.path.dirname(os.path.abspath(__file__)) +sys.path.append(os.path.dirname(REFACTOR_DIR)) + +def run_tests(): + TEST_FILE = os.path.abspath("tests/input/car_stuff_tests.py") + print("TEST_FILE PATH:",TEST_FILE) + # Run the tests and store the result + return pytest.main([TEST_FILE, "--maxfail=1", "--disable-warnings", "--capture=no"]) diff --git a/tests/input/__init__.py b/tests/input/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/input/car_stuff.py b/tests/input/car_stuff.py new file mode 100644 index 00000000..65d56c52 --- /dev/null +++ b/tests/input/car_stuff.py @@ -0,0 +1,73 @@ +import math # Unused import + +# Code Smell: Long Parameter List +class Vehicle: + def __init__(self, make, model, year, color, fuel_type, mileage, transmission, price): + # Code Smell: Long Parameter List in __init__ + self.make = make + self.model = model + self.year = year + self.color = color + self.fuel_type = fuel_type + self.mileage = mileage + self.transmission = transmission + self.price = price + self.owner = None # Unused class attribute + + def display_info(self): + # Code Smell: Long Message Chain + print(f"Make: {self.make}, Model: {self.model}, Year: {self.year}".upper().replace(",", "")[::2]) + + def calculate_price(self): + # Code Smell: List Comprehension in an All Statement + condition = all([isinstance(attribute, str) for attribute in [self.make, self.model, self.year, self.color]]) + if condition: + return self.price * 0.9 # Apply a 10% discount if all attributes are strings (totally arbitrary condition) + + return self.price + + def unused_method(self): + # Code Smell: Member Ignoring Method + print("This method doesn't interact with instance attributes, it just prints a statement.") + +class Car(Vehicle): + def __init__(self, make, model, year, color, fuel_type, mileage, transmission, price, sunroof=False): + super().__init__(make, model, year, color, fuel_type, mileage, transmission, price) + self.sunroof = sunroof + self.engine_size = 2.0 # Unused variable + + def add_sunroof(self): + # Code Smell: Long Parameter List + self.sunroof = True + print("Sunroof added!") + + def show_details(self): + # Code Smell: Long Message Chain + details = f"Car: {self.make} {self.model} ({self.year}) | Mileage: {self.mileage} | Transmission: {self.transmission} | Sunroof: {self.sunroof}" + print(details.upper().lower().upper().capitalize().upper().replace("|", "-")) + +def process_vehicle(vehicle): + # Code Smell: Unused Variables + temp_discount = 0.05 + temp_shipping = 100 + + vehicle.display_info() + price_after_discount = vehicle.calculate_price() + print(f"Price after discount: {price_after_discount}") + + vehicle.unused_method() # Calls a method that doesn't actually use the class attributes + +def is_all_string(attributes): + # Code Smell: List Comprehension in an All Statement + return all(isinstance(attribute, str) for attribute in attributes) + +# Main loop: Arbitrary use of the classes and demonstrating code smells +if __name__ == "__main__": + car1 = Car(make="Toyota", model="Camry", year=2020, color="Blue", fuel_type="Gas", mileage=25000, transmission="Automatic", price=20000) + process_vehicle(car1) + car1.add_sunroof() + car1.show_details() + + # Testing with another vehicle object + car2 = Vehicle(make="Honda", model="Civic", year=2018, color="Red", fuel_type="Gas", mileage=30000, transmission="Manual", price=15000) + process_vehicle(car2) diff --git a/tests/input/car_stuff_tests.py b/tests/input/car_stuff_tests.py new file mode 100644 index 00000000..a1c36189 --- /dev/null +++ b/tests/input/car_stuff_tests.py @@ -0,0 +1,34 @@ +import pytest +from .car_stuff import Vehicle, Car, process_vehicle + +# Fixture to create a car instance +@pytest.fixture +def car1(): + return Car(make="Toyota", model="Camry", year=2020, color="Blue", fuel_type="Gas", mileage=25000, transmission="Automatic", price=20000) + +# Test the price after applying discount +def test_vehicle_price_after_discount(car1): + assert car1.calculate_price() == 20000, "Price after discount should be 18000" + +# Test the add_sunroof method to confirm it works as expected +def test_car_add_sunroof(car1): + car1.add_sunroof() + assert car1.sunroof is True, "Car should have sunroof after add_sunroof() is called" + +# Test that show_details method runs without error +def test_car_show_details(car1, capsys): + car1.show_details() + captured = capsys.readouterr() + assert "CAR: TOYOTA CAMRY" in captured.out # Checking if the output contains car details + +# Test the is_all_string function indirectly through the calculate_price method +def test_is_all_string(car1): + price_after_discount = car1.calculate_price() + assert price_after_discount > 0, "Price calculation should return a valid price" + +# Test the process_vehicle function to check its behavior with a Vehicle object +def test_process_vehicle(car1, capsys): + process_vehicle(car1) + captured = capsys.readouterr() + assert "Price after discount" in captured.out, "The process_vehicle function should output the price after discount" + From e7515cb0a2a8d4b704c4ddb2dc63017028793d24 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 03:48:42 -0500 Subject: [PATCH 082/105] fixed long param list refactor --- .../long_parameter_list_refactorer.py | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 4ddafb4b..6b994922 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -45,7 +45,7 @@ def classify_parameters(params): return data_params, config_params -def create_parameter_object_class(param_names, class_name="ParamsObject"): +def create_parameter_object_class(param_names: list, class_name="ParamsObject"): """ Creates a class definition for encapsulating parameters as attributes """ @@ -74,6 +74,8 @@ def refactor(self, file_path, pylint_smell, initial_emissions): with open(file_path, "r") as f: tree = ast.parse(f.read()) + print(ast.dump(tree, indent=4), file=open("ast.txt", "w")) + # Flag indicating if a refactoring has been made modified = False @@ -104,6 +106,7 @@ def refactor(self, file_path, pylint_smell, initial_emissions): # Classify parameters into data and configuration groups data_params, config_params = classify_parameters(param_names) + data_params.remove("self") # Create parameter object classes for each group if data_params: @@ -126,34 +129,48 @@ def refactor(self, file_path, pylint_smell, initial_emissions): # Modify function to use two parameters for the parameter objects node.args.args = [ + ast.arg(arg="self", annotation=None), ast.arg(arg="data_params", annotation=None), ast.arg(arg="config_params", annotation=None), ] # Update all parameter usages within the function to access attributes of the parameter objects class ParamAttributeUpdater(ast.NodeTransformer): - def visit_Name(self, node): - if node.id in data_params and isinstance( + def visit_Attribute(self, node): + if node.attr in data_params and isinstance( node.ctx, ast.Load ): return ast.Attribute( value=ast.Name( - id="data_params", ctx=ast.Load() + id="self", ctx=ast.Load() ), - attr=node.id, + attr="data_params", ctx=node.ctx, ) - elif node.id in config_params and isinstance( + elif node.attr in config_params and isinstance( node.ctx, ast.Load ): return ast.Attribute( value=ast.Name( - id="config_params", ctx=ast.Load() + id="self", ctx=ast.Load() ), - attr=node.id, + attr="config_params", ctx=node.ctx, ) return node + def visit_Name(self, node): + if node.id in data_params and isinstance(node.ctx, ast.Load): + return ast.Attribute( + value=ast.Name(id="data_params", ctx=ast.Load()), + attr=node.id, + ctx=ast.Load() + ) + elif node.id in config_params and isinstance(node.ctx, ast.Load): + return ast.Attribute( + value=ast.Name(id="config_params", ctx=ast.Load()), + attr=node.id, + ctx=ast.Load() + ) node.body = [ ParamAttributeUpdater().visit(stmt) for stmt in node.body From be289b38667e5d106cd964d3736bdc86382b8134 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:35:51 -0500 Subject: [PATCH 083/105] minor fixes for source testing --- .gitignore | 5 ++++- src1/main.py | 6 ++++++ src1/refactorers/long_message_chain_refactorer.py | 12 ++++++++---- src1/refactorers/long_parameter_list_refactorer.py | 13 +++++++++---- .../member_ignoring_method_refactorer.py | 13 +++++++++---- src1/refactorers/unused_refactorer.py | 13 ++++++++++--- src1/refactorers/use_a_generator_refactorer.py | 13 +++++++++---- src1/testing/run_tests.py | 2 -- 8 files changed, 55 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index f49f5833..f626a011 100644 --- a/.gitignore +++ b/.gitignore @@ -297,4 +297,7 @@ __pycache__/ # Rope .ropeproject -*.egg-info/ \ No newline at end of file +*.egg-info/ + +# Package files +src/ecooptimizer/outputs/ \ No newline at end of file diff --git a/src1/main.py b/src1/main.py index 80767359..a0dbbb0a 100644 --- a/src1/main.py +++ b/src1/main.py @@ -86,6 +86,12 @@ def main(): "#####################################################################################################" ) + SOURCE_CODE_OUTPUT = os.path.abspath("src1/outputs/refactored_source") + print(SOURCE_CODE_OUTPUT) + # Ensure the output directory exists; if not, create it + if not os.path.exists(SOURCE_CODE_OUTPUT): + os.makedirs(SOURCE_CODE_OUTPUT) + # Refactor code smells copy_file_to_output(TEST_FILE, "refactored-test-case.py") diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src1/refactorers/long_message_chain_refactorer.py index fc5cb7ee..eed09034 100644 --- a/src1/refactorers/long_message_chain_refactorer.py +++ b/src1/refactorers/long_message_chain_refactorer.py @@ -86,9 +86,13 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa f"Refactored long message chain on line {pylint_smell["line"]} and saved.\n" ) return + + self.logger.log("Tests Fail! Discarded refactored changes") - # Remove the temporary file if no improvement + else: + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + # Remove the temporary file if no energy improvement or failing tests # os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src1/refactorers/long_parameter_list_refactorer.py index 6b994922..9490fa44 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src1/refactorers/long_parameter_list_refactorer.py @@ -195,8 +195,13 @@ def visit_Name(self, node): f"Refactored long parameter list into data groups on line {target_line} and saved.\n" ) return - # Remove the temporary file if no improvement + + self.logger.log("Tests Fail! Discarded refactored changes") + + else: + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + # Remove the temporary file if no energy improvement or failing tests # os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src1/refactorers/member_ignoring_method_refactorer.py index 9ac115a3..3eb0e956 100644 --- a/src1/refactorers/member_ignoring_method_refactorer.py +++ b/src1/refactorers/member_ignoring_method_refactorer.py @@ -64,11 +64,16 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa f"Refactored 'Member Ignoring Method' to static method on line {self.target_line} and saved.\n" ) return - # Remove the temporary file if no improvement + + self.logger.log("Tests Fail! Discarded refactored changes") + + else: + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + # Remove the temporary file if no energy improvement or failing tests # os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) def visit_FunctionDef(self, node): if node.lineno == self.target_line: diff --git a/src1/refactorers/unused_refactorer.py b/src1/refactorers/unused_refactorer.py index 6a8096ec..e94e06db 100644 --- a/src1/refactorers/unused_refactorer.py +++ b/src1/refactorers/unused_refactorer.py @@ -70,6 +70,13 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa f"Removed unused stuff on line {line_number} and saved changes.\n" ) return - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) \ No newline at end of file + + self.logger.log("Tests Fail! Discarded refactored changes") + + else: + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + # Remove the temporary file if no energy improvement or failing tests + # os.remove(temp_file_path) \ No newline at end of file diff --git a/src1/refactorers/use_a_generator_refactorer.py b/src1/refactorers/use_a_generator_refactorer.py index 01a7b491..144cea3e 100644 --- a/src1/refactorers/use_a_generator_refactorer.py +++ b/src1/refactorers/use_a_generator_refactorer.py @@ -93,11 +93,16 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" ) return - # Remove the temporary file if no improvement + + self.logger.log("Tests Fail! Discarded refactored changes") + + else: + self.logger.log( + "No emission improvement after refactoring. Discarded refactored changes.\n" + ) + + # Remove the temporary file if no energy improvement or failing tests # os.remove(temp_file_path) - self.logger.log( - "No emission improvement after refactoring. Discarded refactored changes.\n" - ) else: self.logger.log( "No applicable list comprehension found on the specified line.\n" diff --git a/src1/testing/run_tests.py b/src1/testing/run_tests.py index 41d40c35..18c15b02 100644 --- a/src1/testing/run_tests.py +++ b/src1/testing/run_tests.py @@ -7,6 +7,4 @@ def run_tests(): TEST_FILE = os.path.abspath("tests/input/car_stuff_tests.py") - print("TEST_FILE PATH:",TEST_FILE) - # Run the tests and store the result return pytest.main([TEST_FILE, "--maxfail=1", "--disable-warnings", "--capture=no"]) From 413884fda26fbed9de27d3d52f6f9ff5046c9c03 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:39:55 -0500 Subject: [PATCH 084/105] made final restructuring changes --- {src1 => src/ecooptimizer}/README.md | 0 {src1 => src/ecooptimizer}/__init__.py | 0 .../ecooptimizer}/analyzers/__init__.py | 0 .../ecooptimizer}/analyzers/base_analyzer.py | 0 .../analyzers/pylint_analyzer.py | 0 {src1 => src/ecooptimizer}/main.py | 0 .../ecooptimizer}/measurements/__init__.py | 0 .../measurements/base_energy_meter.py | 0 .../measurements/codecarbon_energy_meter.py | 0 .../ecooptimizer/refactorers}/__init__.py | 0 .../refactorers/base_refactorer.py | 0 .../long_lambda_function_refactorer.py | 0 .../long_message_chain_refactorer.py | 0 .../long_parameter_list_refactorer.py | 2 - .../member_ignoring_method_refactorer.py | 0 .../refactorers/unused_refactorer.py | 0 .../refactorers/use_a_generator_refactorer.py | 0 .../ecooptimizer}/testing/run_tests.py | 0 .../ecooptimizer/utils}/__init__.py | 0 .../ecooptimizer}/utils/analyzers_config.py | 0 .../ecooptimizer}/utils/ast_parser.py | 0 {src1 => src/ecooptimizer}/utils/logger.py | 0 .../ecooptimizer}/utils/outputs_config.py | 0 .../ecooptimizer}/utils/refactorer_factory.py | 0 .../outputs/all_configured_pylint_smells.json | 43 --- src1/outputs/all_pylint_smells.json | 262 ------------------ ...e_carbon_ineffcient_code_example_1_log.txt | 2 - .../code_carbon_refactored-test-case_log.txt | 8 - src1/outputs/final_emissions_data.txt | 34 --- src1/outputs/initial_emissions_data.txt | 34 --- src1/outputs/log.txt | 96 ------- src1/outputs/refactored-test-case.py | 33 --- src1/outputs/smells.json | 197 ------------- src1/utils/__init__.py | 0 34 files changed, 711 deletions(-) rename {src1 => src/ecooptimizer}/README.md (100%) rename {src1 => src/ecooptimizer}/__init__.py (100%) rename {src1 => src/ecooptimizer}/analyzers/__init__.py (100%) rename {src1 => src/ecooptimizer}/analyzers/base_analyzer.py (100%) rename {src1 => src/ecooptimizer}/analyzers/pylint_analyzer.py (100%) rename {src1 => src/ecooptimizer}/main.py (100%) rename {src1 => src/ecooptimizer}/measurements/__init__.py (100%) rename {src1 => src/ecooptimizer}/measurements/base_energy_meter.py (100%) rename {src1 => src/ecooptimizer}/measurements/codecarbon_energy_meter.py (100%) rename {src1/outputs => src/ecooptimizer/refactorers}/__init__.py (100%) rename {src1 => src/ecooptimizer}/refactorers/base_refactorer.py (100%) rename {src1 => src/ecooptimizer}/refactorers/long_lambda_function_refactorer.py (100%) rename {src1 => src/ecooptimizer}/refactorers/long_message_chain_refactorer.py (100%) rename {src1 => src/ecooptimizer}/refactorers/long_parameter_list_refactorer.py (99%) rename {src1 => src/ecooptimizer}/refactorers/member_ignoring_method_refactorer.py (100%) rename {src1 => src/ecooptimizer}/refactorers/unused_refactorer.py (100%) rename {src1 => src/ecooptimizer}/refactorers/use_a_generator_refactorer.py (100%) rename {src1 => src/ecooptimizer}/testing/run_tests.py (100%) rename {src1/refactorers => src/ecooptimizer/utils}/__init__.py (100%) rename {src1 => src/ecooptimizer}/utils/analyzers_config.py (100%) rename {src1 => src/ecooptimizer}/utils/ast_parser.py (100%) rename {src1 => src/ecooptimizer}/utils/logger.py (100%) rename {src1 => src/ecooptimizer}/utils/outputs_config.py (100%) rename {src1 => src/ecooptimizer}/utils/refactorer_factory.py (100%) delete mode 100644 src1/outputs/all_configured_pylint_smells.json delete mode 100644 src1/outputs/all_pylint_smells.json delete mode 100644 src1/outputs/code_carbon_ineffcient_code_example_1_log.txt delete mode 100644 src1/outputs/code_carbon_refactored-test-case_log.txt delete mode 100644 src1/outputs/final_emissions_data.txt delete mode 100644 src1/outputs/initial_emissions_data.txt delete mode 100644 src1/outputs/log.txt delete mode 100644 src1/outputs/refactored-test-case.py delete mode 100644 src1/outputs/smells.json delete mode 100644 src1/utils/__init__.py diff --git a/src1/README.md b/src/ecooptimizer/README.md similarity index 100% rename from src1/README.md rename to src/ecooptimizer/README.md diff --git a/src1/__init__.py b/src/ecooptimizer/__init__.py similarity index 100% rename from src1/__init__.py rename to src/ecooptimizer/__init__.py diff --git a/src1/analyzers/__init__.py b/src/ecooptimizer/analyzers/__init__.py similarity index 100% rename from src1/analyzers/__init__.py rename to src/ecooptimizer/analyzers/__init__.py diff --git a/src1/analyzers/base_analyzer.py b/src/ecooptimizer/analyzers/base_analyzer.py similarity index 100% rename from src1/analyzers/base_analyzer.py rename to src/ecooptimizer/analyzers/base_analyzer.py diff --git a/src1/analyzers/pylint_analyzer.py b/src/ecooptimizer/analyzers/pylint_analyzer.py similarity index 100% rename from src1/analyzers/pylint_analyzer.py rename to src/ecooptimizer/analyzers/pylint_analyzer.py diff --git a/src1/main.py b/src/ecooptimizer/main.py similarity index 100% rename from src1/main.py rename to src/ecooptimizer/main.py diff --git a/src1/measurements/__init__.py b/src/ecooptimizer/measurements/__init__.py similarity index 100% rename from src1/measurements/__init__.py rename to src/ecooptimizer/measurements/__init__.py diff --git a/src1/measurements/base_energy_meter.py b/src/ecooptimizer/measurements/base_energy_meter.py similarity index 100% rename from src1/measurements/base_energy_meter.py rename to src/ecooptimizer/measurements/base_energy_meter.py diff --git a/src1/measurements/codecarbon_energy_meter.py b/src/ecooptimizer/measurements/codecarbon_energy_meter.py similarity index 100% rename from src1/measurements/codecarbon_energy_meter.py rename to src/ecooptimizer/measurements/codecarbon_energy_meter.py diff --git a/src1/outputs/__init__.py b/src/ecooptimizer/refactorers/__init__.py similarity index 100% rename from src1/outputs/__init__.py rename to src/ecooptimizer/refactorers/__init__.py diff --git a/src1/refactorers/base_refactorer.py b/src/ecooptimizer/refactorers/base_refactorer.py similarity index 100% rename from src1/refactorers/base_refactorer.py rename to src/ecooptimizer/refactorers/base_refactorer.py diff --git a/src1/refactorers/long_lambda_function_refactorer.py b/src/ecooptimizer/refactorers/long_lambda_function_refactorer.py similarity index 100% rename from src1/refactorers/long_lambda_function_refactorer.py rename to src/ecooptimizer/refactorers/long_lambda_function_refactorer.py diff --git a/src1/refactorers/long_message_chain_refactorer.py b/src/ecooptimizer/refactorers/long_message_chain_refactorer.py similarity index 100% rename from src1/refactorers/long_message_chain_refactorer.py rename to src/ecooptimizer/refactorers/long_message_chain_refactorer.py diff --git a/src1/refactorers/long_parameter_list_refactorer.py b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py similarity index 99% rename from src1/refactorers/long_parameter_list_refactorer.py rename to src/ecooptimizer/refactorers/long_parameter_list_refactorer.py index 9490fa44..632ef327 100644 --- a/src1/refactorers/long_parameter_list_refactorer.py +++ b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py @@ -74,8 +74,6 @@ def refactor(self, file_path, pylint_smell, initial_emissions): with open(file_path, "r") as f: tree = ast.parse(f.read()) - print(ast.dump(tree, indent=4), file=open("ast.txt", "w")) - # Flag indicating if a refactoring has been made modified = False diff --git a/src1/refactorers/member_ignoring_method_refactorer.py b/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py similarity index 100% rename from src1/refactorers/member_ignoring_method_refactorer.py rename to src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py diff --git a/src1/refactorers/unused_refactorer.py b/src/ecooptimizer/refactorers/unused_refactorer.py similarity index 100% rename from src1/refactorers/unused_refactorer.py rename to src/ecooptimizer/refactorers/unused_refactorer.py diff --git a/src1/refactorers/use_a_generator_refactorer.py b/src/ecooptimizer/refactorers/use_a_generator_refactorer.py similarity index 100% rename from src1/refactorers/use_a_generator_refactorer.py rename to src/ecooptimizer/refactorers/use_a_generator_refactorer.py diff --git a/src1/testing/run_tests.py b/src/ecooptimizer/testing/run_tests.py similarity index 100% rename from src1/testing/run_tests.py rename to src/ecooptimizer/testing/run_tests.py diff --git a/src1/refactorers/__init__.py b/src/ecooptimizer/utils/__init__.py similarity index 100% rename from src1/refactorers/__init__.py rename to src/ecooptimizer/utils/__init__.py diff --git a/src1/utils/analyzers_config.py b/src/ecooptimizer/utils/analyzers_config.py similarity index 100% rename from src1/utils/analyzers_config.py rename to src/ecooptimizer/utils/analyzers_config.py diff --git a/src1/utils/ast_parser.py b/src/ecooptimizer/utils/ast_parser.py similarity index 100% rename from src1/utils/ast_parser.py rename to src/ecooptimizer/utils/ast_parser.py diff --git a/src1/utils/logger.py b/src/ecooptimizer/utils/logger.py similarity index 100% rename from src1/utils/logger.py rename to src/ecooptimizer/utils/logger.py diff --git a/src1/utils/outputs_config.py b/src/ecooptimizer/utils/outputs_config.py similarity index 100% rename from src1/utils/outputs_config.py rename to src/ecooptimizer/utils/outputs_config.py diff --git a/src1/utils/refactorer_factory.py b/src/ecooptimizer/utils/refactorer_factory.py similarity index 100% rename from src1/utils/refactorer_factory.py rename to src/ecooptimizer/utils/refactorer_factory.py diff --git a/src1/outputs/all_configured_pylint_smells.json b/src1/outputs/all_configured_pylint_smells.json deleted file mode 100644 index cb023984..00000000 --- a/src1/outputs/all_configured_pylint_smells.json +++ /dev/null @@ -1,43 +0,0 @@ -[ - { - "column": 4, - "endColumn": 27, - "endLine": 24, - "line": 24, - "message": "Too many arguments (8/6)", - "message-id": "R0913", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.complex_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "column": 4, - "endColumn": 31, - "endLine": 35, - "line": 35, - "message": "Too many arguments (12/6)", - "message-id": "R0913", - "module": "ineffcient_code_example_2", - "obj": "DataProcessor.multi_param_calculation", - "path": "tests/input/ineffcient_code_example_2.py", - "symbol": "too-many-arguments", - "type": "refactor" - }, - { - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "column": 18, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 18, - "message": "Method chain too long (3/3)", - "message-id": "LMC001", - "module": "ineffcient_code_example_2.py", - "obj": "", - "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "long-message-chain", - "type": "convention" - } -] \ No newline at end of file diff --git a/src1/outputs/all_pylint_smells.json b/src1/outputs/all_pylint_smells.json deleted file mode 100644 index ff83e649..00000000 --- a/src1/outputs/all_pylint_smells.json +++ /dev/null @@ -1,262 +0,0 @@ -[ - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 33, - "message": "Final newline missing", - "message-id": "C0304", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-final-newline", - "type": "convention" - }, - { - "column": 0, - "endColumn": null, - "endLine": null, - "line": 1, - "message": "Missing module docstring", - "message-id": "C0114", - "module": "ineffcient_code_example_1", - "obj": "", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-module-docstring", - "type": "convention" - }, - { - "column": 0, - "endColumn": 16, - "endLine": 3, - "line": 3, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "has_positive", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 44, - "endLine": 5, - "line": 5, - "message": "Use a generator instead 'any(num > 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "has_positive", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 20, - "endLine": 7, - "line": 7, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "all_non_negative", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 45, - "endLine": 9, - "line": 9, - "message": "Use a generator instead 'all(num >= 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_non_negative", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 26, - "endLine": 11, - "line": 11, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "contains_large_strings", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 13, - "line": 13, - "message": "Use a generator instead 'any(len(s) > 10 for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "contains_large_strings", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 16, - "endColumn": 27, - "endLine": 13, - "line": 13, - "message": "Consider using a named constant or an enum instead of '10'.", - "message-id": "R2004", - "module": "ineffcient_code_example_1", - "obj": "contains_large_strings", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 17, - "endLine": 15, - "line": 15, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "all_uppercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 17, - "line": 17, - "message": "Use a generator instead 'all(s.isupper() for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_uppercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 28, - "endLine": 19, - "line": 19, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "contains_special_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 63, - "endLine": 21, - "line": 21, - "message": "Use a generator instead 'any(num % 5 == 0 and num > 100 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "contains_special_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 33, - "endColumn": 42, - "endLine": 21, - "line": 21, - "message": "Consider using a named constant or an enum instead of '100'.", - "message-id": "R2004", - "module": "ineffcient_code_example_1", - "obj": "contains_special_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "magic-value-comparison", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 17, - "endLine": 23, - "line": 23, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "all_lowercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 46, - "endLine": 25, - "line": 25, - "message": "Use a generator instead 'all(s.islower() for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_lowercase", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 20, - "endLine": 27, - "line": 27, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "any_even_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 49, - "endLine": 29, - "line": 29, - "message": "Use a generator instead 'any(num % 2 == 0 for num in numbers)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "any_even_numbers", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - }, - { - "column": 0, - "endColumn": 28, - "endLine": 31, - "line": 31, - "message": "Missing function or method docstring", - "message-id": "C0116", - "module": "ineffcient_code_example_1", - "obj": "all_strings_start_with_a", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "missing-function-docstring", - "type": "convention" - }, - { - "column": 11, - "endColumn": 52, - "endLine": 33, - "line": 33, - "message": "Use a generator instead 'all(s.startswith('A') for s in strings)'", - "message-id": "R1729", - "module": "ineffcient_code_example_1", - "obj": "all_strings_start_with_a", - "path": "c:\\Users\\Nivetha\\Documents\\capstone--source-code-optimizer\\tests\\input\\ineffcient_code_example_1.py", - "symbol": "use-a-generator", - "type": "refactor" - } -] \ No newline at end of file diff --git a/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt b/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt deleted file mode 100644 index 139597f9..00000000 --- a/src1/outputs/code_carbon_ineffcient_code_example_1_log.txt +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/src1/outputs/code_carbon_refactored-test-case_log.txt b/src1/outputs/code_carbon_refactored-test-case_log.txt deleted file mode 100644 index 12a6f48e..00000000 --- a/src1/outputs/code_carbon_refactored-test-case_log.txt +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/src1/outputs/final_emissions_data.txt b/src1/outputs/final_emissions_data.txt deleted file mode 100644 index da2a02df..00000000 --- a/src1/outputs/final_emissions_data.txt +++ /dev/null @@ -1,34 +0,0 @@ -{ - "cloud_provider": NaN, - "cloud_region": NaN, - "codecarbon_version": "2.7.2", - "country_iso_code": "CAN", - "country_name": "Canada", - "cpu_count": 12, - "cpu_energy": 5.891369538386888e-06, - "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", - "cpu_power": 47.99377777777777, - "duration": 2.7314686000026995, - "emissions": 2.77266175958425e-07, - "emissions_rate": 1.0150809566624745e-07, - "energy_consumed": 7.020027544402079e-06, - "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": 1, - "gpu_energy": 4.2333367200000005e-07, - "gpu_model": "1 x NVIDIA GeForce RTX 2060", - "gpu_power": 3.4636462191974235, - "latitude": 43.2642, - "longitude": -79.9143, - "on_cloud": "N", - "os": "Windows-10-10.0.19045-SP0", - "project_name": "codecarbon", - "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 7.05324334015191e-07, - "ram_power": 5.91276741027832, - "ram_total_size": 15.767379760742188, - "region": "ontario", - "run_id": "463da52e-39ac-460f-a23f-e447b0b7c653", - "timestamp": "2024-11-10T22:32:38", - "tracking_mode": "machine" -} \ No newline at end of file diff --git a/src1/outputs/initial_emissions_data.txt b/src1/outputs/initial_emissions_data.txt deleted file mode 100644 index 8be8f489..00000000 --- a/src1/outputs/initial_emissions_data.txt +++ /dev/null @@ -1,34 +0,0 @@ -{ - "cloud_provider": NaN, - "cloud_region": NaN, - "codecarbon_version": "2.7.2", - "country_iso_code": "CAN", - "country_name": "Canada", - "cpu_count": 12, - "cpu_energy": 2.849305427399163e-06, - "cpu_model": "Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz", - "cpu_power": 25.30654545454545, - "duration": 2.812684600008652, - "emissions": 1.5001510415414538e-07, - "emissions_rate": 5.3335203013407164e-08, - "energy_consumed": 3.798191970579047e-06, - "experiment_id": "5b0fa12a-3dd7-45bb-9766-cc326314d9f1", - "gpu_count": 1, - "gpu_energy": 2.97778016e-07, - "gpu_model": "1 x NVIDIA GeForce RTX 2060", - "gpu_power": 2.650454217767624, - "latitude": 43.2642, - "longitude": -79.9143, - "on_cloud": "N", - "os": "Windows-10-10.0.19045-SP0", - "project_name": "codecarbon", - "pue": 1.0, - "python_version": "3.13.0", - "ram_energy": 6.511085271798837e-07, - "ram_power": 5.91276741027832, - "ram_total_size": 15.767379760742188, - "region": "ontario", - "run_id": "34062555-0738-4d57-93a2-98b97fbb4d69", - "timestamp": "2024-11-10T22:31:23", - "tracking_mode": "machine" -} \ No newline at end of file diff --git a/src1/outputs/log.txt b/src1/outputs/log.txt deleted file mode 100644 index 4db6d938..00000000 --- a/src1/outputs/log.txt +++ /dev/null @@ -1,96 +0,0 @@ -[2024-11-10 22:31:14] ##################################################################################################### -[2024-11-10 22:31:14] CAPTURE INITIAL EMISSIONS -[2024-11-10 22:31:14] ##################################################################################################### -[2024-11-10 22:31:14] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-10 22:31:20] CodeCarbon measurement completed successfully. -[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\initial_emissions_data.txt -[2024-11-10 22:31:23] Initial Emissions: 1.5001510415414535e-07 kg CO2 -[2024-11-10 22:31:23] ##################################################################################################### - - -[2024-11-10 22:31:23] ##################################################################################################### -[2024-11-10 22:31:23] CAPTURE CODE SMELLS -[2024-11-10 22:31:23] ##################################################################################################### -[2024-11-10 22:31:23] Running Pylint analysis on ineffcient_code_example_1.py -[2024-11-10 22:31:23] Pylint analyzer completed successfully. -[2024-11-10 22:31:23] Running custom parsers: -[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_pylint_smells.json -[2024-11-10 22:31:23] Filtering pylint smells -[2024-11-10 22:31:23] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\all_configured_pylint_smells.json -[2024-11-10 22:31:23] Refactorable code smells: 8 -[2024-11-10 22:31:23] ##################################################################################################### - - -[2024-11-10 22:31:23] ##################################################################################################### -[2024-11-10 22:31:23] REFACTOR CODE SMELLS -[2024-11-10 22:31:23] ##################################################################################################### -[2024-11-10 22:31:23] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 5 for identified code smell. -[2024-11-10 22:31:23] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:31:29] CodeCarbon measurement completed successfully. -[2024-11-10 22:31:32] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.606659214506875e-07 -[2024-11-10 22:31:32] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.606659214506875e-07 kg CO2. -[2024-11-10 22:31:32] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 22:31:32] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 9 for identified code smell. -[2024-11-10 22:31:32] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:31:38] CodeCarbon measurement completed successfully. -[2024-11-10 22:31:40] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.5569213706053624e-07 -[2024-11-10 22:31:40] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.5569213706053624e-07 kg CO2. -[2024-11-10 22:31:40] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 22:31:40] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 13 for identified code smell. -[2024-11-10 22:31:40] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:31:46] CodeCarbon measurement completed successfully. -[2024-11-10 22:31:48] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.9193877464710126e-07 -[2024-11-10 22:31:48] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.9193877464710126e-07 kg CO2. -[2024-11-10 22:31:48] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 22:31:48] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 17 for identified code smell. -[2024-11-10 22:31:48] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:31:54] CodeCarbon measurement completed successfully. -[2024-11-10 22:31:57] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.8302076101856833e-07 -[2024-11-10 22:31:57] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.8302076101856833e-07 kg CO2. -[2024-11-10 22:31:57] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 22:31:57] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 21 for identified code smell. -[2024-11-10 22:31:57] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:32:03] CodeCarbon measurement completed successfully. -[2024-11-10 22:32:05] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.9562061607657285e-07 -[2024-11-10 22:32:05] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.9562061607657285e-07 kg CO2. -[2024-11-10 22:32:05] No emission improvement after refactoring. Discarded refactored changes. - -[2024-11-10 22:32:05] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 25 for identified code smell. -[2024-11-10 22:32:05] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:32:11] CodeCarbon measurement completed successfully. -[2024-11-10 22:32:13] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.066947119830384e-07 -[2024-11-10 22:32:13] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.066947119830384e-07 kg CO2. -[2024-11-10 22:32:13] Refactored list comprehension to generator expression on line 25 and saved. - -[2024-11-10 22:32:13] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 29 for identified code smell. -[2024-11-10 22:32:13] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:32:19] CodeCarbon measurement completed successfully. -[2024-11-10 22:32:21] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.1866016806014599e-07 -[2024-11-10 22:32:21] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.1866016806014599e-07 kg CO2. -[2024-11-10 22:32:21] Refactored list comprehension to generator expression on line 29 and saved. - -[2024-11-10 22:32:21] Applying 'Use a Generator' refactor on 'ineffcient_code_example_1.py' at line 33 for identified code smell. -[2024-11-10 22:32:21] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py.temp -[2024-11-10 22:32:27] CodeCarbon measurement completed successfully. -[2024-11-10 22:32:29] Measured emissions for 'ineffcient_code_example_1.py.temp': 1.3302157130404294e-07 -[2024-11-10 22:32:29] Initial Emissions: 1.5001510415414535e-07 kg CO2. Final Emissions: 1.3302157130404294e-07 kg CO2. -[2024-11-10 22:32:29] Refactored list comprehension to generator expression on line 33 and saved. - -[2024-11-10 22:32:29] ##################################################################################################### - - -[2024-11-10 22:32:29] ##################################################################################################### -[2024-11-10 22:32:29] CAPTURE FINAL EMISSIONS -[2024-11-10 22:32:29] ##################################################################################################### -[2024-11-10 22:32:29] Starting CodeCarbon energy measurement on ineffcient_code_example_1.py -[2024-11-10 22:32:36] CodeCarbon measurement completed successfully. -[2024-11-10 22:32:38] Output saved to c:\Users\Nivetha\Documents\capstone--source-code-optimizer\src1\outputs\final_emissions_data.txt -[2024-11-10 22:32:38] Final Emissions: 2.77266175958425e-07 kg CO2 -[2024-11-10 22:32:38] ##################################################################################################### - - -[2024-11-10 22:32:38] Final emissions are greater than initial emissions; we are going to fail diff --git a/src1/outputs/refactored-test-case.py b/src1/outputs/refactored-test-case.py deleted file mode 100644 index 2053b7ed..00000000 --- a/src1/outputs/refactored-test-case.py +++ /dev/null @@ -1,33 +0,0 @@ -# Should trigger Use A Generator code smells - -def has_positive(numbers): - # List comprehension inside `any()` - triggers R1729 - return any([num > 0 for num in numbers]) - -def all_non_negative(numbers): - # List comprehension inside `all()` - triggers R1729 - return all([num >= 0 for num in numbers]) - -def contains_large_strings(strings): - # List comprehension inside `any()` - triggers R1729 - return any([len(s) > 10 for s in strings]) - -def all_uppercase(strings): - # List comprehension inside `all()` - triggers R1729 - return all([s.isupper() for s in strings]) - -def contains_special_numbers(numbers): - # List comprehension inside `any()` - triggers R1729 - return any([num % 5 == 0 and num > 100 for num in numbers]) - -def all_lowercase(strings): - # List comprehension inside `all()` - triggers R1729 - return all([s.islower() for s in strings]) - -def any_even_numbers(numbers): - # List comprehension inside `any()` - triggers R1729 - return any([num % 2 == 0 for num in numbers]) - -def all_strings_start_with_a(strings): - # List comprehension inside `all()` - triggers R1729 - return all([s.startswith('A') for s in strings]) \ No newline at end of file diff --git a/src1/outputs/smells.json b/src1/outputs/smells.json deleted file mode 100644 index 974c2a05..00000000 --- a/src1/outputs/smells.json +++ /dev/null @@ -1,197 +0,0 @@ -{ - "messages": [ - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 19, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (87/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 41, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (85/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 57, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "line-too-long", - "message": "Line too long (86/80)", - "messageId": "C0301", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "", - "line": 74, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "missing-module-docstring", - "message": "Missing module docstring", - "messageId": "C0114", - "confidence": "HIGH", - "module": "inefficent_code_example", - "obj": "", - "line": 1, - "column": 0, - "endLine": null, - "endColumn": null, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "missing-class-docstring", - "message": "Missing class docstring", - "messageId": "C0115", - "confidence": "HIGH", - "module": "inefficent_code_example", - "obj": "DataProcessor", - "line": 2, - "column": 0, - "endLine": 2, - "endColumn": 19, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "missing-function-docstring", - "message": "Missing function or method docstring", - "messageId": "C0116", - "confidence": "INFERENCE", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "line": 8, - "column": 4, - "endLine": 8, - "endColumn": 24, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "warning", - "symbol": "broad-exception-caught", - "message": "Catching too general exception Exception", - "messageId": "W0718", - "confidence": "INFERENCE", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "line": 18, - "column": 16, - "endLine": 18, - "endColumn": 25, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "error", - "symbol": "no-member", - "message": "Instance of 'DataProcessor' has no 'complex_calculation' member", - "messageId": "E1101", - "confidence": "INFERENCE", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data", - "line": 13, - "column": 25, - "endLine": 13, - "endColumn": 49, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "convention", - "symbol": "singleton-comparison", - "message": "Comparison 'x != None' should be 'x is not None'", - "messageId": "C0121", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "DataProcessor.process_all_data.", - "line": 27, - "column": 29, - "endLine": 27, - "endColumn": 38, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "type": "refactor", - "symbol": "too-few-public-methods", - "message": "Too few public methods (1/2)", - "messageId": "R0903", - "confidence": "UNDEFINED", - "module": "inefficent_code_example", - "obj": "DataProcessor", - "line": 2, - "column": 0, - "endLine": 2, - "endColumn": 19, - "path": "test/inefficent_code_example.py", - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/test/inefficent_code_example.py" - }, - { - "absolutePath": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "column": 18, - "confidence": "UNDEFINED", - "endColumn": null, - "endLine": null, - "line": 22, - "message": "Method chain too long (3/3)", - "message-id": "LMC001", - "module": "ineffcient_code_example_2.py", - "obj": "", - "path": "/Users/mya/Code/Capstone/capstone--source-code-optimizer/tests/input/ineffcient_code_example_2.py", - "symbol": "long-message-chain", - "type": "convention" - } - ], - "statistics": { - "messageTypeCount": { - "fatal": 0, - "error": 2, - "warning": 6, - "refactor": 7, - "convention": 14, - "info": 0 - }, - "modulesLinted": 3, - "score": 2.13 - } - } - \ No newline at end of file diff --git a/src1/utils/__init__.py b/src1/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 From 3e6923628c803fa6fbc932f1a63eb995c06c292b Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 10:49:20 -0500 Subject: [PATCH 085/105] updated paths and imports --- src/ecooptimizer/main.py | 4 ++-- src/ecooptimizer/refactorers/long_message_chain_refactorer.py | 2 +- .../refactorers/long_parameter_list_refactorer.py | 2 +- .../refactorers/member_ignoring_method_refactorer.py | 2 +- src/ecooptimizer/refactorers/unused_refactorer.py | 2 +- src/ecooptimizer/refactorers/use_a_generator_refactorer.py | 2 +- tests/test_analyzer.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ecooptimizer/main.py b/src/ecooptimizer/main.py index a0dbbb0a..14797e9f 100644 --- a/src/ecooptimizer/main.py +++ b/src/ecooptimizer/main.py @@ -13,7 +13,7 @@ def main(): # Path to the file to be analyzed TEST_FILE = os.path.abspath( - os.path.join(DIRNAME, "../tests/input/car_stuff.py") + os.path.join(DIRNAME, "../../tests/input/car_stuff.py") ) # Set up logging @@ -86,7 +86,7 @@ def main(): "#####################################################################################################" ) - SOURCE_CODE_OUTPUT = os.path.abspath("src1/outputs/refactored_source") + SOURCE_CODE_OUTPUT = os.path.abspath("src/ecooptimizer/outputs/refactored_source") print(SOURCE_CODE_OUTPUT) # Ensure the output directory exists; if not, create it if not os.path.exists(SOURCE_CODE_OUTPUT): diff --git a/src/ecooptimizer/refactorers/long_message_chain_refactorer.py b/src/ecooptimizer/refactorers/long_message_chain_refactorer.py index eed09034..742d1cee 100644 --- a/src/ecooptimizer/refactorers/long_message_chain_refactorer.py +++ b/src/ecooptimizer/refactorers/long_message_chain_refactorer.py @@ -22,7 +22,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Extract details from pylint_smell line_number = pylint_smell["line"] original_filename = os.path.basename(file_path) - temp_filename = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LMCR_line_{line_number}.py" + temp_filename = f"src/ecooptimizer/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LMCR_line_{line_number}.py" self.logger.log( f"Applying 'Separate Statements' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." diff --git a/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py index 632ef327..ff465839 100644 --- a/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py +++ b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py @@ -177,7 +177,7 @@ def visit_Name(self, node): if modified: # Write back modified code to temporary file original_filename = os.path.basename(file_path) - temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LPLR_line_{target_line}.py" + temp_file_path = f"src/ecooptimizer/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_LPLR_line_{target_line}.py" with open(temp_file_path, "w") as temp_file: temp_file.write(astor.to_source(tree)) diff --git a/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py b/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py index 3eb0e956..ffd4f00b 100644 --- a/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py +++ b/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py @@ -43,7 +43,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa modified_code = astor.to_source(modified_tree) original_filename = os.path.basename(file_path) - temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_MIMR_line_{self.target_line}.py" + temp_file_path = f"src/ecooptimizer/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_MIMR_line_{self.target_line}.py" print(os.path.abspath(temp_file_path)) diff --git a/src/ecooptimizer/refactorers/unused_refactorer.py b/src/ecooptimizer/refactorers/unused_refactorer.py index e94e06db..a6e09f09 100644 --- a/src/ecooptimizer/refactorers/unused_refactorer.py +++ b/src/ecooptimizer/refactorers/unused_refactorer.py @@ -52,7 +52,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Write the modified content to a temporary file original_filename = os.path.basename(file_path) - temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UNSDR_line_{line_number}.py" + temp_file_path = f"src/ecooptimizer/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UNSDR_line_{line_number}.py" with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) diff --git a/src/ecooptimizer/refactorers/use_a_generator_refactorer.py b/src/ecooptimizer/refactorers/use_a_generator_refactorer.py index 144cea3e..4cd31e43 100644 --- a/src/ecooptimizer/refactorers/use_a_generator_refactorer.py +++ b/src/ecooptimizer/refactorers/use_a_generator_refactorer.py @@ -75,7 +75,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Temporarily write the modified content to a temporary file original_filename = os.path.basename(file_path) - temp_file_path = f"src1/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UGENR_line_{line_number}.py" + temp_file_path = f"src/ecooptimizer/outputs/refactored_source/{os.path.splitext(original_filename)[0]}_UGENR_line_{line_number}.py" with open(temp_file_path, "w") as temp_file: temp_file.writelines(modified_lines) diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index cff91662..b1648b25 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -1,5 +1,5 @@ import unittest -from ..src1.analyzers.pylint_analyzer import PylintAnalyzer +from ..src.ecooptimizer.analyzers.pylint_analyzer import PylintAnalyzer class TestPylintAnalyzer(unittest.TestCase): From 6e6caa1946f7abb72cebde88c28bdf3729735b24 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:13:49 -0500 Subject: [PATCH 086/105] #249 : Add test for MIM analysis --- .gitignore | 4 +- pyproject.toml | 5 +- src/ecooptimizer/__init__.py | 5 - src/ecooptimizer/analyzers/base_analyzer.py | 3 +- src/ecooptimizer/analyzers/pylint_analyzer.py | 10 +- src/ecooptimizer/utils/logger.py | 2 +- tests/conftest.py | 13 +++ tests/test_analyzer.py | 50 +++++++--- tests/test_end_to_end.py | 16 --- tests/test_energy_measure.py | 20 ---- tests/test_refactorer.py | 99 ------------------- 11 files changed, 64 insertions(+), 163 deletions(-) create mode 100644 tests/conftest.py delete mode 100644 tests/test_end_to_end.py delete mode 100644 tests/test_energy_measure.py delete mode 100644 tests/test_refactorer.py diff --git a/.gitignore b/.gitignore index f626a011..b246896c 100644 --- a/.gitignore +++ b/.gitignore @@ -300,4 +300,6 @@ __pycache__/ *.egg-info/ # Package files -src/ecooptimizer/outputs/ \ No newline at end of file +src/ecooptimizer/outputs/ +build/ +tests/temp_dir/ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a496d4d4..92de972b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,14 +33,17 @@ Repository = "https://github.com/ssm-lab/capstone--source-code-optimizer" "Bug Tracker" = "https://github.com/ssm-lab/capstone--source-code-optimizer/issues" [tool.pytest.ini_options] +norecursedirs = ["tests/temp*", "tests/input", "tests/_input_copies"] +addopts = ["--basetemp=tests/temp_dir"] testpaths = ["tests"] +pythonpath = "src" [tool.ruff] extend-exclude = ["*tests/input/**/*.py"] [tool.ruff.lint] # 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults. -select = ["E4", "E7", "E9", "F", "B"] +select = ["E4", "E7", "E9", "F", "B", "PT"] # 2. Avoid enforcing line-length violations (`E501`) ignore = ["E501"] diff --git a/src/ecooptimizer/__init__.py b/src/ecooptimizer/__init__.py index 56f09c20..e69de29b 100644 --- a/src/ecooptimizer/__init__.py +++ b/src/ecooptimizer/__init__.py @@ -1,5 +0,0 @@ -from . import analyzers -from . import measurement -from . import refactorer -from . import testing -from . import utils \ No newline at end of file diff --git a/src/ecooptimizer/analyzers/base_analyzer.py b/src/ecooptimizer/analyzers/base_analyzer.py index 5a287c5a..ffd58ba2 100644 --- a/src/ecooptimizer/analyzers/base_analyzer.py +++ b/src/ecooptimizer/analyzers/base_analyzer.py @@ -1,6 +1,7 @@ from abc import ABC, abstractmethod import os -from utils.logger import Logger + +from ..utils.logger import Logger class Analyzer(ABC): def __init__(self, file_path: str, logger: Logger): diff --git a/src/ecooptimizer/analyzers/pylint_analyzer.py b/src/ecooptimizer/analyzers/pylint_analyzer.py index d88d3798..0690f5ee 100644 --- a/src/ecooptimizer/analyzers/pylint_analyzer.py +++ b/src/ecooptimizer/analyzers/pylint_analyzer.py @@ -1,20 +1,20 @@ import json import ast import os +from io import StringIO from pylint.lint import Run from pylint.reporters.json_reporter import JSONReporter -from io import StringIO -from utils.logger import Logger + from .base_analyzer import Analyzer -from utils.analyzers_config import ( +from ..utils.logger import Logger +from ..utils.ast_parser import parse_line +from ..utils.analyzers_config import ( PylintSmell, CustomSmell, IntermediateSmells, EXTRA_PYLINT_OPTIONS, ) -from utils.ast_parser import parse_line - class PylintAnalyzer(Analyzer): def __init__(self, file_path: str, logger: Logger): diff --git a/src/ecooptimizer/utils/logger.py b/src/ecooptimizer/utils/logger.py index 948a0414..c767f25a 100644 --- a/src/ecooptimizer/utils/logger.py +++ b/src/ecooptimizer/utils/logger.py @@ -14,7 +14,7 @@ def __init__(self, log_path): # Ensure the log file directory exists and clear any previous content os.makedirs(os.path.dirname(log_path), exist_ok=True) - open(self.log_path, 'w').close() # Open in write mode to clear the file + open(self.log_path, 'w+').close() # Open in write mode to clear the file def log(self, message): """ diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..bab77049 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,13 @@ +import os +import pytest + +from ecooptimizer.utils.logger import Logger + +@pytest.fixture(scope="session") +def output_dir(tmp_path_factory): + return tmp_path_factory.mktemp("output") + +@pytest.fixture +def logger(output_dir): + file = os.path.join(output_dir, "log.txt") + return Logger(file) \ No newline at end of file diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index b1648b25..eadd216f 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -1,19 +1,41 @@ -import unittest -from ..src.ecooptimizer.analyzers.pylint_analyzer import PylintAnalyzer +import os +import textwrap +import pytest +from ecooptimizer.analyzers.pylint_analyzer import PylintAnalyzer +@pytest.fixture(scope="module") +def source_files(tmp_path_factory): + return tmp_path_factory.mktemp("input") -class TestPylintAnalyzer(unittest.TestCase): - def test_analyze_method(self): - analyzer = PylintAnalyzer("input/ineffcient_code_example_2.py") - analyzer.analyze() - analyzer.configure_smells() +@pytest.fixture +def MIM_code(source_files): + mim_code = textwrap.dedent("""\ + class SomeClass(): + def __init__(self, string): + self.string = string + + def print_str(self): + print(self.string) + + def say_hello(self, name): + print(f"Hello {name}!") + """) + file = os.path.join(source_files, "mim_code.py") + with open(file, "w") as f: + f.write(mim_code) - data = analyzer.smells_data + return file - print(data) - # self.assertIsInstance(report, list) # Check if the output is a list - # # Add more assertions based on expected output +def test_member_ignoring_method(MIM_code, logger): + analyzer = PylintAnalyzer(MIM_code, logger) + analyzer.analyze() + analyzer.configure_smells() + + smells = analyzer.smells_data + + assert len(smells) == 1 + assert smells[0].get("symbol") == "no-self-use" + assert smells[0].get("message-id") == "R6301" + assert smells[0].get("line") == 8 + assert smells[0].get("module") == os.path.splitext(os.path.basename(MIM_code))[0] - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py deleted file mode 100644 index bef67b8e..00000000 --- a/tests/test_end_to_end.py +++ /dev/null @@ -1,16 +0,0 @@ -import unittest - -class TestEndToEnd(unittest.TestCase): - """ - End-to-end tests for the full refactoring flow. - """ - - def test_refactor_flow(self): - """ - Test the complete flow from analysis to refactoring. - """ - # Implement the test logic here - self.assertTrue(True) # Placeholder for actual test - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_energy_measure.py b/tests/test_energy_measure.py deleted file mode 100644 index 00d381c6..00000000 --- a/tests/test_energy_measure.py +++ /dev/null @@ -1,20 +0,0 @@ -import unittest -from src.measurement.energy_meter import EnergyMeter - -class TestEnergyMeter(unittest.TestCase): - """ - Unit tests for the EnergyMeter class. - """ - - def test_measurement(self): - """ - Test starting and stopping energy measurement. - """ - meter = EnergyMeter() - meter.start_measurement() - # Logic to execute code - result = meter.stop_measurement() - self.assertIsNotNone(result) # Check that a result is produced - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_refactorer.py b/tests/test_refactorer.py deleted file mode 100644 index af992428..00000000 --- a/tests/test_refactorer.py +++ /dev/null @@ -1,99 +0,0 @@ -import unittest -from src.refactorer.long_method_refactorer import LongMethodRefactorer -from src.refactorer.large_class_refactorer import LargeClassRefactorer -from src.refactorer.complex_list_comprehension_refactorer import ComplexListComprehensionRefactorer - -class TestRefactorers(unittest.TestCase): - """ - Unit tests for various refactorers. - """ - - def test_refactor_long_method(self): - """ - Test the refactor method of the LongMethodRefactorer. - """ - original_code = """ - def long_method(): - # A long method with too many lines of code - a = 1 - b = 2 - c = a + b - # More complex logic... - return c - """ - expected_refactored_code = """ - def long_method(): - result = calculate_result() - return result - - def calculate_result(): - a = 1 - b = 2 - return a + b - """ - refactorer = LongMethodRefactorer(original_code) - result = refactorer.refactor() - self.assertEqual(result.strip(), expected_refactored_code.strip()) - - def test_refactor_large_class(self): - """ - Test the refactor method of the LargeClassRefactorer. - """ - original_code = """ - class LargeClass: - def method1(self): - # Method 1 - pass - - def method2(self): - # Method 2 - pass - - def method3(self): - # Method 3 - pass - - # ... many more methods ... - """ - expected_refactored_code = """ - class LargeClass: - def method1(self): - # Method 1 - pass - - class AnotherClass: - def method2(self): - # Method 2 - pass - - def method3(self): - # Method 3 - pass - """ - refactorer = LargeClassRefactorer(original_code) - result = refactorer.refactor() - self.assertEqual(result.strip(), expected_refactored_code.strip()) - - def test_refactor_complex_list_comprehension(self): - """ - Test the refactor method of the ComplexListComprehensionRefactorer. - """ - original_code = """ - def complex_list(): - return [x**2 for x in range(10) if x % 2 == 0 and x > 3] - """ - expected_refactored_code = """ - def complex_list(): - result = [] - for x in range(10): - if x % 2 == 0 and x > 3: - result.append(x**2) - return result - """ - refactorer = ComplexListComprehensionRefactorer(original_code) - result = refactorer.refactor() - self.assertEqual(result.strip(), expected_refactored_code.strip()) - -# Run all tests in the module -if __name__ == "__main__": - unittest.main() From a598b1254ab9fcbcf2630c51140f4111d9160d20 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:14:22 -0500 Subject: [PATCH 087/105] #249 : Add test for LMC analysis --- tests/test_analyzer.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index eadd216f..ff045b81 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -7,6 +7,18 @@ def source_files(tmp_path_factory): return tmp_path_factory.mktemp("input") +@pytest.fixture +def LMC_code(source_files): + lmc_code = textwrap.dedent("""\ + def transform_str(string): + return string.lstrip().rstrip().lower().capitalize().split().remove("var") + """) + file = os.path.join(source_files, "lmc_code.py") + with open(file, "w") as f: + f.write(lmc_code) + + return file + @pytest.fixture def MIM_code(source_files): mim_code = textwrap.dedent("""\ @@ -26,6 +38,19 @@ def say_hello(self, name): return file +def test_long_message_chain(LMC_code, logger): + analyzer = PylintAnalyzer(LMC_code, logger) + analyzer.analyze() + analyzer.configure_smells() + + smells = analyzer.smells_data + + assert len(smells) == 1 + assert smells[0].get("symbol") == "long-message-chain" + assert smells[0].get("message-id") == "LMC001" + assert smells[0].get("line") == 2 + assert smells[0].get("module") == os.path.basename(LMC_code) + def test_member_ignoring_method(MIM_code, logger): analyzer = PylintAnalyzer(MIM_code, logger) analyzer.analyze() From bebeb2afac38cc9b4d0179aef3205c4efca70b9d Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:20:40 -0500 Subject: [PATCH 088/105] add analyzer test utility function --- tests/test_analyzer.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index ff045b81..d1acafac 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -3,6 +3,13 @@ import pytest from ecooptimizer.analyzers.pylint_analyzer import PylintAnalyzer +def get_smells(code, logger): + analyzer = PylintAnalyzer(code, logger) + analyzer.analyze() + analyzer.configure_smells() + + return analyzer.smells_data + @pytest.fixture(scope="module") def source_files(tmp_path_factory): return tmp_path_factory.mktemp("input") @@ -39,11 +46,7 @@ def say_hello(self, name): return file def test_long_message_chain(LMC_code, logger): - analyzer = PylintAnalyzer(LMC_code, logger) - analyzer.analyze() - analyzer.configure_smells() - - smells = analyzer.smells_data + smells = get_smells(LMC_code, logger) assert len(smells) == 1 assert smells[0].get("symbol") == "long-message-chain" @@ -52,11 +55,7 @@ def test_long_message_chain(LMC_code, logger): assert smells[0].get("module") == os.path.basename(LMC_code) def test_member_ignoring_method(MIM_code, logger): - analyzer = PylintAnalyzer(MIM_code, logger) - analyzer.analyze() - analyzer.configure_smells() - - smells = analyzer.smells_data + smells = get_smells(MIM_code, logger) assert len(smells) == 1 assert smells[0].get("symbol") == "no-self-use" From 45c9464ba78967a0235096545b65b652aa92dff7 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:24:55 -0500 Subject: [PATCH 089/105] made typing fixes + changed JSON reporter type --- pyproject.toml | 37 +++++++- src/ecooptimizer/analyzers/base_analyzer.py | 8 +- src/ecooptimizer/analyzers/pylint_analyzer.py | 89 +++++++++---------- src/ecooptimizer/data_wrappers/__init__.py | 0 src/ecooptimizer/data_wrappers/smell.py | 34 +++++++ src/ecooptimizer/main.py | 16 +++- .../measurements/codecarbon_energy_meter.py | 2 +- .../refactorers/base_refactorer.py | 9 +- .../long_message_chain_refactorer.py | 11 ++- .../long_parameter_list_refactorer.py | 7 +- .../member_ignoring_method_refactorer.py | 8 +- .../refactorers/unused_refactorer.py | 11 ++- .../refactorers/use_a_generator_refactorer.py | 10 ++- src/ecooptimizer/utils/analyzers_config.py | 59 +++++------- src/ecooptimizer/utils/ast_parser.py | 6 +- src/ecooptimizer/utils/refactorer_factory.py | 13 ++- tests/test_analyzer.py | 4 +- 17 files changed, 205 insertions(+), 119 deletions(-) create mode 100644 src/ecooptimizer/data_wrappers/__init__.py create mode 100644 src/ecooptimizer/data_wrappers/smell.py diff --git a/pyproject.toml b/pyproject.toml index 92de972b..dcd670a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ readme = "README.md" license = {file = "LICENSE"} [project.optional-dependencies] -dev = ["pytest", "mypy", "ruff", "coverage"] +dev = ["pytest", "mypy", "ruff", "coverage", "pyright"] [project.urls] Documentation = "https://readthedocs.org" @@ -39,11 +39,11 @@ testpaths = ["tests"] pythonpath = "src" [tool.ruff] -extend-exclude = ["*tests/input/**/*.py"] +extend-exclude = ["*tests/input/**/*.py", "tests/_input_copies"] [tool.ruff.lint] # 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults. -select = ["E4", "E7", "E9", "F", "B", "PT"] +select = ["E4", "E7", "E9", "F", "B", "PT", "W"] # 2. Avoid enforcing line-length violations (`E501`) ignore = ["E501"] @@ -54,4 +54,33 @@ unfixable = ["B"] # 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories. [tool.ruff.lint.per-file-ignores] "__init__.py" = ["E402"] -"**/{tests,docs,tools}/*" = ["E402"] \ No newline at end of file +"**/{tests,docs,tools}/*" = ["E402"] + +[tool.pyright] +include = ["src", "tests"] +exclude = ["tests/input", "tests/_input*", "src/ecooptimizer/outputs"] + +disableBytesTypePromotions = true +reportAttributeAccessIssue = "warning" +reportPropertyTypeMismatch = true +reportFunctionMemberAccess = true +reportMissingImports = true +reportUnusedVariable = "warning" +reportDuplicateImport = "warning" +reportUntypedFunctionDecorator = true +reportUntypedClassDecorator = true +reportUntypedBaseClass = true +reportUntypedNamedTuple = true +reportPrivateUsage = true +reportConstantRedefinition = "warning" +reportDeprecated = "warning" +reportIncompatibleMethodOverride = true +reportIncompatibleVariableOverride = true +reportInconsistentConstructor = true +reportOverlappingOverload = true +reportMissingTypeArgument = true +reportCallInDefaultInitializer = "warning" +reportUnnecessaryIsInstance = "warning" +reportUnnecessaryCast = "warning" +reportUnnecessaryComparison = true +reportMatchNotExhaustive = "warning" \ No newline at end of file diff --git a/src/ecooptimizer/analyzers/base_analyzer.py b/src/ecooptimizer/analyzers/base_analyzer.py index ffd58ba2..671d41dd 100644 --- a/src/ecooptimizer/analyzers/base_analyzer.py +++ b/src/ecooptimizer/analyzers/base_analyzer.py @@ -1,7 +1,9 @@ from abc import ABC, abstractmethod import os -from ..utils.logger import Logger +from ecooptimizer.utils.logger import Logger + +from ecooptimizer.data_wrappers.smell import Smell class Analyzer(ABC): def __init__(self, file_path: str, logger: Logger): @@ -12,13 +14,13 @@ def __init__(self, file_path: str, logger: Logger): :param logger: Logger instance to handle log messages. """ self.file_path = file_path - self.smells_data: list[object] = [] + self.smells_data: list[Smell] = list() self.logger = logger # Use logger instance def validate_file(self): """ Validates that the specified file path exists and is a file. - + :return: Boolean indicating the validity of the file path. """ is_valid = os.path.isfile(self.file_path) diff --git a/src/ecooptimizer/analyzers/pylint_analyzer.py b/src/ecooptimizer/analyzers/pylint_analyzer.py index 0690f5ee..ed30f471 100644 --- a/src/ecooptimizer/analyzers/pylint_analyzer.py +++ b/src/ecooptimizer/analyzers/pylint_analyzer.py @@ -4,18 +4,20 @@ from io import StringIO from pylint.lint import Run -from pylint.reporters.json_reporter import JSONReporter +from pylint.reporters.json_reporter import JSON2Reporter from .base_analyzer import Analyzer -from ..utils.logger import Logger -from ..utils.ast_parser import parse_line -from ..utils.analyzers_config import ( +from ecooptimizer.utils.logger import Logger +from ecooptimizer.utils.ast_parser import parse_line +from ecooptimizer.utils.analyzers_config import ( PylintSmell, CustomSmell, IntermediateSmells, EXTRA_PYLINT_OPTIONS, ) +from ecooptimizer.data_wrappers.smell import Smell + class PylintAnalyzer(Analyzer): def __init__(self, file_path: str, logger: Logger): super().__init__(file_path, logger) @@ -41,7 +43,7 @@ def analyze(self): # Capture pylint output in a JSON format buffer with StringIO() as buffer: - reporter = JSONReporter(buffer) + reporter = JSON2Reporter(buffer) pylint_options = self.build_pylint_options() try: @@ -50,7 +52,7 @@ def analyze(self): # Parse the JSON output buffer.seek(0) - self.smells_data = json.loads(buffer.getvalue()) + self.smells_data = json.loads(buffer.getvalue())["messages"] self.logger.log("Pylint analyzer completed successfully.") except json.JSONDecodeError as e: self.logger.log(f"Failed to parse JSON output from pylint: {e}") @@ -58,20 +60,22 @@ def analyze(self): self.logger.log(f"An error occurred during pylint analysis: {e}") self.logger.log("Running custom parsers:") + lmc_data = PylintAnalyzer.detect_long_message_chain( PylintAnalyzer.read_code_from_path(self.file_path), self.file_path, os.path.basename(self.file_path), ) - self.smells_data += lmc_data + print(type(lmc_data)) + lmc_data = PylintAnalyzer.detect_unused_variables_and_attributes( PylintAnalyzer.read_code_from_path(self.file_path), self.file_path, os.path.basename(self.file_path), ) - self.smells_data += lmc_data - print(self.smells_data) + self.smells_data.extend(lmc_data) + print(self.smells_data) def configure_smells(self): """ @@ -79,28 +83,28 @@ def configure_smells(self): """ self.logger.log("Filtering pylint smells") - configured_smells: list[object] = [] + configured_smells: list[Smell] = [] for smell in self.smells_data: - if smell["message-id"] in PylintSmell.list(): + if smell["messageId"] in PylintSmell.list(): configured_smells.append(smell) - elif smell["message-id"] in CustomSmell.list(): + elif smell["messageId"] in CustomSmell.list(): configured_smells.append(smell) - if smell["message-id"] == IntermediateSmells.LINE_TOO_LONG.value: + if smell["messageId"] == IntermediateSmells.LINE_TOO_LONG.value: self.filter_ternary(smell) self.smells_data = configured_smells - def filter_for_one_code_smell(self, pylint_results: list[object], code: str): - filtered_results: list[object] = [] + def filter_for_one_code_smell(self, pylint_results: list[Smell], code: str): + filtered_results: list[Smell] = [] for error in pylint_results: - if error["message-id"] == code: + if error["messageId"] == code: # type: ignore filtered_results.append(error) return filtered_results - def filter_ternary(self, smell: object): + def filter_ternary(self, smell: Smell): """ Filters LINE_TOO_LONG smells to find ternary expression smells """ @@ -111,12 +115,13 @@ def filter_ternary(self, smell: object): for node in ast.walk(root_node): if isinstance(node, ast.IfExp): # Ternary expression node - smell["message-id"] = CustomSmell.LONG_TERN_EXPR.value + smell["messageId"] = CustomSmell.LONG_TERN_EXPR.value smell["message"] = "Ternary expression has too many branches" self.smells_data.append(smell) break - def detect_long_message_chain(code, file_path, module_name, threshold=3): + @staticmethod + def detect_long_message_chain(code: str, file_path: str, module_name: str, threshold=3): """ Detects long message chains in the given Python code and returns a list of results. @@ -132,7 +137,7 @@ def detect_long_message_chain(code, file_path, module_name, threshold=3): # Parse the code into an Abstract Syntax Tree (AST) tree = ast.parse(code) - results = [] + results: list[Smell] = [] used_lines = set() # Function to detect long chains @@ -142,11 +147,11 @@ def check_chain(node, chain_length=0): # Create the message for the convention message = f"Method chain too long ({chain_length}/{threshold})" # Add the result in the required format - result = { + result: Smell = { "type": "convention", "symbol": "long-message-chain", "message": message, - "message-id": "LMC001", + "messageId": "LMC001", "confidence": "UNDEFINED", "module": module_name, "obj": "", @@ -185,7 +190,8 @@ def check_chain(node, chain_length=0): return results - def detect_unused_variables_and_attributes(code, file_path, module_name): + @staticmethod + def detect_unused_variables_and_attributes(code: str, file_path: str, module_name: str): """ Detects unused variables and class attributes in the given Python code and returns a list of results. @@ -203,7 +209,7 @@ def detect_unused_variables_and_attributes(code, file_path, module_name): # Store variable and attribute declarations and usage declared_vars = set() used_vars = set() - results = [] + results: list[Smell] = [] # Helper function to gather declared variables (including class attributes) def gather_declarations(node): @@ -213,7 +219,7 @@ def gather_declarations(node): if isinstance(target, ast.Name): # Simple variable declared_vars.add(target.id) elif isinstance(target, ast.Attribute): # Class attribute - declared_vars.add(f'{target.value.id}.{target.attr}') + declared_vars.add(f'{target.value.id}.{target.attr}') # type: ignore # For class attribute assignments (e.g., self.attribute) elif isinstance(node, ast.ClassDef): @@ -223,7 +229,7 @@ def gather_declarations(node): if isinstance(target, ast.Name): declared_vars.add(target.id) elif isinstance(target, ast.Attribute): - declared_vars.add(f'{target.value.id}.{target.attr}') + declared_vars.add(f'{target.value.id}.{target.attr}') # type: ignore # Helper function to gather used variables and class attributes def gather_usages(node): @@ -245,7 +251,7 @@ def gather_usages(node): for var in unused_vars: # Locate the line number for each unused variable or attribute - line_no, column_no = None, None + line_no, column_no = 0, 0 for node in ast.walk(tree): if isinstance(node, ast.Name) and node.id == var: line_no = node.lineno @@ -254,13 +260,13 @@ def gather_usages(node): elif isinstance(node, ast.Attribute) and f'self.{node.attr}' == var and isinstance(node.value, ast.Name) and node.value.id == "self": line_no = node.lineno column_no = node.col_offset - break - - result = { + break + + result: Smell = { "type": "convention", "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", "message": f"Unused variable or attribute '{var}'", - "message-id": "UV001", + "messageId": "UV001", "confidence": "UNDEFINED", "module": module_name, "obj": '', @@ -279,23 +285,14 @@ def gather_usages(node): @staticmethod - def read_code_from_path(file_path): + def read_code_from_path(file_path: str): """ Reads the Python code from a given file path. - Args: - - file_path (str): The path to the Python file. - - Returns: - - str: The content of the file as a string. + :param: file_path (str): The path to the Python file. + :return: code (str): The content of the file as a string. """ - try: - with open(file_path, "r") as file: + with open(file_path, "r") as file: code = file.read() - return code - except FileNotFoundError: - print(f"Error: The file at {file_path} was not found.") - return None - except IOError as e: - print(f"Error reading file {file_path}: {e}") - return None + + return code diff --git a/src/ecooptimizer/data_wrappers/__init__.py b/src/ecooptimizer/data_wrappers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/ecooptimizer/data_wrappers/smell.py b/src/ecooptimizer/data_wrappers/smell.py new file mode 100644 index 00000000..68e6d8ce --- /dev/null +++ b/src/ecooptimizer/data_wrappers/smell.py @@ -0,0 +1,34 @@ +from typing import TypedDict + +class Smell(TypedDict): + """ + Represents a code smell detected in a source file, including its location, type, and related metadata. + + Attributes: + absolutePath (str): The absolute path to the source file containing the smell. + column (int): The starting column in the source file where the smell is detected. + confidence (str): The level of confidence for the smell detection (e.g., "high", "medium", "low"). + endColumn (int): The ending column in the source file for the smell location. + endLine (int): The line number where the smell ends in the source file. + line (int): The line number where the smell begins in the source file. + message (str): A descriptive message explaining the nature of the smell. + messageId (str): A unique identifier for the specific message or warning related to the smell. + module (str): The name of the module or component in which the smell is located. + obj (str): The specific object (e.g., function, class) associated with the smell. + path (str): The relative path to the source file from the project root. + symbol (str): The symbol or code construct (e.g., variable, method) involved in the smell. + type (str): The type or category of the smell (e.g., "complexity", "duplication"). + """ + absolutePath: str + column: int + confidence: str + endColumn: int | None + endLine: int | None + line: int + message: str + messageId: str + module: str + obj: str + path: str + symbol: str + type: str diff --git a/src/ecooptimizer/main.py b/src/ecooptimizer/main.py index 14797e9f..3e3fab6a 100644 --- a/src/ecooptimizer/main.py +++ b/src/ecooptimizer/main.py @@ -11,14 +11,17 @@ def main(): + # Set up logging + LOG_FILE = os.path.join(DIRNAME, "outputs/log.txt") + logger = Logger(LOG_FILE) + # Path to the file to be analyzed TEST_FILE = os.path.abspath( os.path.join(DIRNAME, "../../tests/input/car_stuff.py") ) - # Set up logging - LOG_FILE = os.path.join(DIRNAME, "outputs/log.txt") - logger = Logger(LOG_FILE) + if not os.path.isfile(TEST_FILE): + logger.log(f"Cannot find source code file '{TEST_FILE}'. Exiting...") # Log start of emissions capture logger.log( @@ -35,6 +38,11 @@ def main(): codecarbon_energy_meter = CodeCarbonEnergyMeter(TEST_FILE, logger) codecarbon_energy_meter.measure_energy() initial_emissions = codecarbon_energy_meter.emissions # Get initial emission + + if not initial_emissions: + logger.log("Could not retrieve initial emissions. Ending Task.") + exit(0) + initial_emissions_data = ( codecarbon_energy_meter.emissions_data ) # Get initial emission data @@ -97,7 +105,7 @@ def main(): for pylint_smell in pylint_analyzer.smells_data: refactoring_class = RefactorerFactory.build_refactorer_class( - pylint_smell["message-id"], logger + pylint_smell["messageId"], logger ) if refactoring_class: refactoring_class.refactor(TEST_FILE, pylint_smell, initial_emissions) diff --git a/src/ecooptimizer/measurements/codecarbon_energy_meter.py b/src/ecooptimizer/measurements/codecarbon_energy_meter.py index ce6dde52..56365c8b 100644 --- a/src/ecooptimizer/measurements/codecarbon_energy_meter.py +++ b/src/ecooptimizer/measurements/codecarbon_energy_meter.py @@ -36,7 +36,7 @@ def measure_energy(self): os.environ['TMPDIR'] = custom_temp_dir # For Unix-based systems # TODO: Save to logger so doesn't print to console - tracker = EmissionsTracker(output_dir=custom_temp_dir, allow_multiple_runs=True) + tracker = EmissionsTracker(output_dir=custom_temp_dir, allow_multiple_runs=True) # type: ignore tracker.start() try: diff --git a/src/ecooptimizer/refactorers/base_refactorer.py b/src/ecooptimizer/refactorers/base_refactorer.py index c80e5a59..f820b8f4 100644 --- a/src/ecooptimizer/refactorers/base_refactorer.py +++ b/src/ecooptimizer/refactorers/base_refactorer.py @@ -4,6 +4,8 @@ import os from measurements.codecarbon_energy_meter import CodeCarbonEnergyMeter +from ecooptimizer.data_wrappers.smell import Smell + class BaseRefactorer(ABC): def __init__(self, logger): """ @@ -15,7 +17,7 @@ def __init__(self, logger): self.logger = logger # Store the mandatory logger instance @abstractmethod - def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: Smell, initial_emissions: float): """ Abstract method for refactoring the code smell. Each subclass should implement this method. @@ -26,7 +28,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa """ pass - def measure_energy(self, file_path: str) -> float: + def measure_energy(self, file_path: str): """ Method for measuring the energy after refactoring. """ @@ -34,6 +36,9 @@ def measure_energy(self, file_path: str) -> float: codecarbon_energy_meter.measure_energy() # measure emissions emissions = codecarbon_energy_meter.emissions # get emission + if not emissions: + return None + # Log the measured emissions self.logger.log(f"Measured emissions for '{os.path.basename(file_path)}': {emissions}") diff --git a/src/ecooptimizer/refactorers/long_message_chain_refactorer.py b/src/ecooptimizer/refactorers/long_message_chain_refactorer.py index 742d1cee..fb9cbe20 100644 --- a/src/ecooptimizer/refactorers/long_message_chain_refactorer.py +++ b/src/ecooptimizer/refactorers/long_message_chain_refactorer.py @@ -5,6 +5,8 @@ from testing.run_tests import run_tests from .base_refactorer import BaseRefactorer +from ecooptimizer.data_wrappers.smell import Smell + class LongMessageChainRefactorer(BaseRefactorer): """ @@ -14,7 +16,7 @@ class LongMessageChainRefactorer(BaseRefactorer): def __init__(self, logger): super().__init__(logger) - def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: Smell, initial_emissions: float): """ Refactor long message chains by breaking them into separate statements and writing the refactored code to a new file. @@ -35,7 +37,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa line_with_chain = lines[line_number - 1].rstrip() # Extract leading whitespace for correct indentation - leading_whitespace = re.match(r"^\s*", line_with_chain).group() + leading_whitespace = re.match(r"^\s*", line_with_chain).group() # type: ignore # Remove the function call wrapper if present (e.g., `print(...)`) chain_content = re.sub(r"^\s*print\((.*)\)\s*$", r"\1", line_with_chain) @@ -76,6 +78,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Measure emissions of the modified code final_emission = self.measure_energy(temp_file_path) + if not final_emission: + # os.remove(temp_file_path) + self.logger.log(f"Could not measure emissions for '{os.path.basename(temp_file_path)}'. Discarded refactoring.") + return + #Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content diff --git a/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py index ff465839..17f814e6 100644 --- a/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py +++ b/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py @@ -45,7 +45,7 @@ def classify_parameters(params): return data_params, config_params -def create_parameter_object_class(param_names: list, class_name="ParamsObject"): +def create_parameter_object_class(param_names: list[str], class_name="ParamsObject"): """ Creates a class definition for encapsulating parameters as attributes """ @@ -184,6 +184,11 @@ def visit_Name(self, node): # Measure emissions of the modified code final_emission = self.measure_energy(temp_file_path) + if not final_emission: + # os.remove(temp_file_path) + self.logger.log(f"Could not measure emissions for '{os.path.basename(temp_file_path)}'. Discarded refactoring.") + return + if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content if run_tests() == 0: diff --git a/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py b/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py index ffd4f00b..b4dae712 100644 --- a/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py +++ b/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py @@ -8,6 +8,7 @@ from .base_refactorer import BaseRefactorer +from ecooptimizer.data_wrappers.smell import Smell class MakeStaticRefactorer(BaseRefactorer, NodeTransformer): """ @@ -18,7 +19,7 @@ def __init__(self, logger): super().__init__(logger) self.target_line = None - def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: Smell, initial_emissions: float): """ Perform refactoring @@ -53,6 +54,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Measure emissions of the modified code final_emission = self.measure_energy(temp_file_path) + if not final_emission: + # os.remove(temp_file_path) + self.logger.log(f"Could not measure emissions for '{os.path.basename(temp_file_path)}'. Discarded refactoring.") + return + # Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content diff --git a/src/ecooptimizer/refactorers/unused_refactorer.py b/src/ecooptimizer/refactorers/unused_refactorer.py index a6e09f09..2502b8b1 100644 --- a/src/ecooptimizer/refactorers/unused_refactorer.py +++ b/src/ecooptimizer/refactorers/unused_refactorer.py @@ -3,6 +3,8 @@ from refactorers.base_refactorer import BaseRefactorer from testing.run_tests import run_tests +from ecooptimizer.data_wrappers.smell import Smell + class RemoveUnusedRefactorer(BaseRefactorer): def __init__(self, logger): """ @@ -12,7 +14,7 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: Smell, initial_emissions: float): """ Refactors unused imports, variables and class attributes by removing lines where they appear. Modifies the specified instance in the file if it results in lower emissions. @@ -22,7 +24,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa :param initial_emission: Initial emission value before refactoring. """ line_number = pylint_smell.get("line") - code_type = pylint_smell.get("message-id") + code_type = pylint_smell.get("messageId") print(code_type) self.logger.log( f"Applying 'Remove Unused Stuff' refactor on '{os.path.basename(file_path)}' at line {line_number} for identified code smell." @@ -60,6 +62,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Measure emissions of the modified code final_emissions = self.measure_energy(temp_file_path) + if not final_emissions: + # os.remove(temp_file_path) + self.logger.log(f"Could not measure emissions for '{os.path.basename(temp_file_path)}'. Discarded refactoring.") + return + # shutil.move(temp_file_path, file_path) # check for improvement in emissions (for logging purposes only) diff --git a/src/ecooptimizer/refactorers/use_a_generator_refactorer.py b/src/ecooptimizer/refactorers/use_a_generator_refactorer.py index 4cd31e43..21b86215 100644 --- a/src/ecooptimizer/refactorers/use_a_generator_refactorer.py +++ b/src/ecooptimizer/refactorers/use_a_generator_refactorer.py @@ -5,6 +5,7 @@ import shutil import os +from ecooptimizer.data_wrappers.smell import Smell from testing.run_tests import run_tests from .base_refactorer import BaseRefactorer @@ -22,7 +23,7 @@ def __init__(self, logger): """ super().__init__(logger) - def refactor(self, file_path: str, pylint_smell: object, initial_emissions: float): + def refactor(self, file_path: str, pylint_smell: Smell, initial_emissions: float): """ Refactors an unnecessary list comprehension by converting it to a generator expression. Modifies the specified instance in the file directly if it results in lower emissions. @@ -83,6 +84,11 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa # Measure emissions of the modified code final_emission = self.measure_energy(temp_file_path) + if not final_emission: + # os.remove(temp_file_path) + self.logger.log(f"Could not measure emissions for '{os.path.basename(temp_file_path)}'. Discarded refactoring.") + return + # Check for improvement in emissions if self.check_energy_improvement(initial_emissions, final_emission): # If improved, replace the original file with the modified content @@ -93,7 +99,7 @@ def refactor(self, file_path: str, pylint_smell: object, initial_emissions: floa f"Refactored list comprehension to generator expression on line {line_number} and saved.\n" ) return - + self.logger.log("Tests Fail! Discarded refactored changes") else: diff --git a/src/ecooptimizer/utils/analyzers_config.py b/src/ecooptimizer/utils/analyzers_config.py index 3fbf10d1..0b2bc755 100644 --- a/src/ecooptimizer/utils/analyzers_config.py +++ b/src/ecooptimizer/utils/analyzers_config.py @@ -1,9 +1,7 @@ # Any configurations that are done by the analyzers -from enum import Enum -from itertools import chain +from enum import EnumMeta, StrEnum - -class ExtendedEnum(Enum): +class ExtendedEnum(StrEnum): @classmethod def list(cls) -> list[str]: @@ -12,37 +10,18 @@ def list(cls) -> list[str]: def __str__(self): return str(self.value) - # Enum class for standard Pylint code smells class PylintSmell(ExtendedEnum): LARGE_CLASS = "R0902" # Pylint code smell for classes with too many attributes - LONG_PARAMETER_LIST = ( - "R0913" # Pylint code smell for functions with too many parameters - ) + LONG_PARAMETER_LIST = "R0913" # Pylint code smell for functions with too many parameters LONG_METHOD = "R0915" # Pylint code smell for methods that are too long - COMPLEX_LIST_COMPREHENSION = ( - "C0200" # Pylint code smell for complex list comprehensions - ) - INVALID_NAMING_CONVENTIONS = ( - "C0103" # Pylint code smell for naming conventions violations - ) + COMPLEX_LIST_COMPREHENSION = "C0200" # Pylint code smell for complex list comprehensions + INVALID_NAMING_CONVENTIONS = "C0103" # Pylint code smell for naming conventions violations NO_SELF_USE = "R6301" # Pylint code smell for class methods that don't use any self calls - - # unused stuff - UNUSED_IMPORT = ( - "W0611" # Pylint code smell for unused imports - ) - UNUSED_VARIABLE = ( - "W0612" # Pylint code smell for unused variable - ) - UNUSED_CLASS_ATTRIBUTE = ( - "W0615" # Pylint code smell for unused class attribute - ) - USE_A_GENERATOR = ( - "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` - ) - - + UNUSED_IMPORT = "W0611" # Pylint code smell for unused imports + UNUSED_VARIABLE = "W0612" # Pylint code smell for unused variable + UNUSED_CLASS_ATTRIBUTE = "W0615" # Pylint code smell for unused class attribute + USE_A_GENERATOR = "R1729" # Pylint code smell for unnecessary list comprehensions inside `any()` or `all()` # Enum class for custom code smells not detected by Pylint class CustomSmell(ExtendedEnum): @@ -50,18 +29,20 @@ class CustomSmell(ExtendedEnum): LONG_MESSAGE_CHAIN = "LMC001" # CUSTOM CODE UNUSED_VAR_OR_ATTRIBUTE = "UV001" # CUSTOM CODE - class IntermediateSmells(ExtendedEnum): LINE_TOO_LONG = "C0301" # pylint smell - -# Enum containing all smells -class AllSmells(ExtendedEnum): - _ignore_ = "member cls" - cls = vars() - for member in chain(list(PylintSmell), list(CustomSmell)): - cls[member.name] = member.value - +class CombinedSmellsMeta(EnumMeta): + def __new__(metacls, clsname, bases, clsdict): + # Add all members from base enums + for enum in (PylintSmell, CustomSmell): + for member in enum: + clsdict[member.name] = member.value + return super().__new__(metacls, clsname, bases, clsdict) + +# Define AllSmells, combining all enum members +class AllSmells(ExtendedEnum, metaclass=CombinedSmellsMeta): + pass # Additional Pylint configuration options for analyzing code EXTRA_PYLINT_OPTIONS = [ diff --git a/src/ecooptimizer/utils/ast_parser.py b/src/ecooptimizer/utils/ast_parser.py index 2da6f3f0..b79df429 100644 --- a/src/ecooptimizer/utils/ast_parser.py +++ b/src/ecooptimizer/utils/ast_parser.py @@ -13,10 +13,10 @@ def parse_line(file: str, line: int): try: # Parse the specified line (adjusted for 0-based indexing) into an AST node node = ast.parse(file_lines[line - 1].strip()) - except(SyntaxError) as e: + except(SyntaxError) : # Return None if there is a syntax error in the specified line return None - + return node # Return the parsed AST node for the line def parse_file(file: str): @@ -28,5 +28,5 @@ def parse_file(file: str): """ with open(file, "r") as f: source = f.read() # Read the full content of the file - + return ast.parse(source) # Parse the entire content as an AST node diff --git a/src/ecooptimizer/utils/refactorer_factory.py b/src/ecooptimizer/utils/refactorer_factory.py index b7a09acc..33688d2b 100644 --- a/src/ecooptimizer/utils/refactorer_factory.py +++ b/src/ecooptimizer/utils/refactorer_factory.py @@ -4,7 +4,6 @@ from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer from refactorers.member_ignoring_method_refactorer import MakeStaticRefactorer from refactorers.long_message_chain_refactorer import LongMessageChainRefactorer -from refactorers.base_refactorer import BaseRefactorer # Import the configuration for all Pylint smells from utils.logger import Logger @@ -36,17 +35,17 @@ def build_refactorer_class(smell_messageID: str, logger: Logger): # Use match statement to select the appropriate refactorer based on smell message ID match smell_messageID: - case AllSmells.USE_A_GENERATOR.value: + case AllSmells.USE_A_GENERATOR: # type: ignore selected = UseAGeneratorRefactorer(logger) - case AllSmells.UNUSED_IMPORT.value: + case AllSmells.UNUSED_IMPORT: selected = RemoveUnusedRefactorer(logger) - case AllSmells.UNUSED_VAR_OR_ATTRIBUTE.value: + case AllSmells.UNUSED_VAR_OR_ATTRIBUTE: selected = RemoveUnusedRefactorer(logger) - case AllSmells.NO_SELF_USE.value: + case AllSmells.NO_SELF_USE: selected = MakeStaticRefactorer(logger) - case AllSmells.LONG_PARAMETER_LIST.value: + case AllSmells.LONG_PARAMETER_LIST: selected = LongParameterListRefactorer(logger) - case AllSmells.LONG_MESSAGE_CHAIN.value: + case AllSmells.LONG_MESSAGE_CHAIN: selected = LongMessageChainRefactorer(logger) case _: selected = None diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index d1acafac..e3652049 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -50,7 +50,7 @@ def test_long_message_chain(LMC_code, logger): assert len(smells) == 1 assert smells[0].get("symbol") == "long-message-chain" - assert smells[0].get("message-id") == "LMC001" + assert smells[0].get("messageId") == "LMC001" assert smells[0].get("line") == 2 assert smells[0].get("module") == os.path.basename(LMC_code) @@ -59,7 +59,7 @@ def test_member_ignoring_method(MIM_code, logger): assert len(smells) == 1 assert smells[0].get("symbol") == "no-self-use" - assert smells[0].get("message-id") == "R6301" + assert smells[0].get("messageId") == "R6301" assert smells[0].get("line") == 8 assert smells[0].get("module") == os.path.splitext(os.path.basename(MIM_code))[0] From ef032e5827c1f3f670f8b98c58b109141de36d4a Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:39:48 -0500 Subject: [PATCH 090/105] fixed bug in analyzer --- src/ecooptimizer/analyzers/pylint_analyzer.py | 12 +++++------- src/ecooptimizer/utils/analyzers_config.py | 4 ++-- tests/test_analyzer.py | 8 ++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/ecooptimizer/analyzers/pylint_analyzer.py b/src/ecooptimizer/analyzers/pylint_analyzer.py index ed30f471..0aabca6a 100644 --- a/src/ecooptimizer/analyzers/pylint_analyzer.py +++ b/src/ecooptimizer/analyzers/pylint_analyzer.py @@ -66,16 +66,14 @@ def analyze(self): self.file_path, os.path.basename(self.file_path), ) - print(type(lmc_data)) + self.smells_data.extend(lmc_data) - lmc_data = PylintAnalyzer.detect_unused_variables_and_attributes( + uva_data = PylintAnalyzer.detect_unused_variables_and_attributes( PylintAnalyzer.read_code_from_path(self.file_path), self.file_path, os.path.basename(self.file_path), ) - self.smells_data.extend(lmc_data) - - print(self.smells_data) + self.smells_data.extend(uva_data) def configure_smells(self): """ @@ -151,7 +149,7 @@ def check_chain(node, chain_length=0): "type": "convention", "symbol": "long-message-chain", "message": message, - "messageId": "LMC001", + "messageId": CustomSmell.LONG_MESSAGE_CHAIN, "confidence": "UNDEFINED", "module": module_name, "obj": "", @@ -266,7 +264,7 @@ def gather_usages(node): "type": "convention", "symbol": "unused-variable" if isinstance(node, ast.Name) else "unused-attribute", "message": f"Unused variable or attribute '{var}'", - "messageId": "UV001", + "messageId": CustomSmell.UNUSED_VAR_OR_ATTRIBUTE, "confidence": "UNDEFINED", "module": module_name, "obj": '', diff --git a/src/ecooptimizer/utils/analyzers_config.py b/src/ecooptimizer/utils/analyzers_config.py index 0b2bc755..8b5942ee 100644 --- a/src/ecooptimizer/utils/analyzers_config.py +++ b/src/ecooptimizer/utils/analyzers_config.py @@ -25,9 +25,9 @@ class PylintSmell(ExtendedEnum): # Enum class for custom code smells not detected by Pylint class CustomSmell(ExtendedEnum): - LONG_TERN_EXPR = "CUST-1" # Custom code smell for long ternary expressions + LONG_TERN_EXPR = "LTE001" # Custom code smell for long ternary expressions LONG_MESSAGE_CHAIN = "LMC001" # CUSTOM CODE - UNUSED_VAR_OR_ATTRIBUTE = "UV001" # CUSTOM CODE + UNUSED_VAR_OR_ATTRIBUTE = "UVA001" # CUSTOM CODE class IntermediateSmells(ExtendedEnum): LINE_TOO_LONG = "C0301" # pylint smell diff --git a/tests/test_analyzer.py b/tests/test_analyzer.py index e3652049..65148661 100644 --- a/tests/test_analyzer.py +++ b/tests/test_analyzer.py @@ -32,10 +32,10 @@ def MIM_code(source_files): class SomeClass(): def __init__(self, string): self.string = string - + def print_str(self): print(self.string) - + def say_hello(self, name): print(f"Hello {name}!") """) @@ -47,7 +47,7 @@ def say_hello(self, name): def test_long_message_chain(LMC_code, logger): smells = get_smells(LMC_code, logger) - + assert len(smells) == 1 assert smells[0].get("symbol") == "long-message-chain" assert smells[0].get("messageId") == "LMC001" @@ -56,7 +56,7 @@ def test_long_message_chain(LMC_code, logger): def test_member_ignoring_method(MIM_code, logger): smells = get_smells(MIM_code, logger) - + assert len(smells) == 1 assert smells[0].get("symbol") == "no-self-use" assert smells[0].get("messageId") == "R6301" From 61af376e63d04f53a9f30b9c5173970bc62ba827 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:14:20 -0500 Subject: [PATCH 091/105] added testing directories --- tests/analyzers/__init__.py | 0 tests/{ => analyzers}/test_analyzer.py | 0 tests/measurements/__init__.py | 0 tests/refactorers/__init__.py | 0 tests/testing/__init__.py | 0 tests/utils/__init__.py | 0 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/analyzers/__init__.py rename tests/{ => analyzers}/test_analyzer.py (100%) create mode 100644 tests/measurements/__init__.py create mode 100644 tests/refactorers/__init__.py create mode 100644 tests/testing/__init__.py create mode 100644 tests/utils/__init__.py diff --git a/tests/analyzers/__init__.py b/tests/analyzers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/test_analyzer.py b/tests/analyzers/test_analyzer.py similarity index 100% rename from tests/test_analyzer.py rename to tests/analyzers/test_analyzer.py diff --git a/tests/measurements/__init__.py b/tests/measurements/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/refactorers/__init__.py b/tests/refactorers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/testing/__init__.py b/tests/testing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b From 806981471d92860412a72445ee4d17371a586dd2 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:33:55 -0500 Subject: [PATCH 092/105] added placeholder tests to simulate passing --- tests/measurements/test_code_carbon.py | 2 ++ tests/refactorers/test_member_ignoring_method.py | 2 ++ tests/testing/test_testing.py | 2 ++ tests/utils/test_utils.py | 2 ++ 4 files changed, 8 insertions(+) create mode 100644 tests/measurements/test_code_carbon.py create mode 100644 tests/refactorers/test_member_ignoring_method.py create mode 100644 tests/testing/test_testing.py create mode 100644 tests/utils/test_utils.py diff --git a/tests/measurements/test_code_carbon.py b/tests/measurements/test_code_carbon.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/tests/measurements/test_code_carbon.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass diff --git a/tests/refactorers/test_member_ignoring_method.py b/tests/refactorers/test_member_ignoring_method.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/tests/refactorers/test_member_ignoring_method.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass diff --git a/tests/testing/test_testing.py b/tests/testing/test_testing.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/tests/testing/test_testing.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py new file mode 100644 index 00000000..201975fc --- /dev/null +++ b/tests/utils/test_utils.py @@ -0,0 +1,2 @@ +def test_placeholder(): + pass From 2c0d4a1075cc537969521b37d24dce8f033d545c Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:03:08 -0500 Subject: [PATCH 093/105] Updated linting commands in workflow --- .github/workflows/python-lint.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index da59474d..1bc19d3d 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -38,6 +38,7 @@ jobs: - name: Run Ruff run: | + ruff format ruff check --fix --output-format=github . # Commit the generated PDF back to the repository @@ -46,5 +47,5 @@ jobs: with: author_name: "Github Action" author_email: "action@github.com" - message: "Made automatic lint fixes" - \ No newline at end of file + message: "Made automatic formatting/lint fixes" + From 1e0e56d30ea6de6061622542f56e9ae4c2bf8eeb Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 18 Nov 2024 07:58:14 -0500 Subject: [PATCH 094/105] renamed test files for clarity --- .gitignore | 5 ++++- ..._a_generator_refactorer.py => list_comp_any_all.py} | 0 ..._function_refactorer.py => long_lambda_function.py} | 0 ...ssage_chain_refactorer.py => long_message_chain.py} | 0 ...meter_list_refactorer.py => long_parameter_list.py} | 0 ..._method_refactorer.py => member_ignoring_method.py} | 0 .../refactorers/{unused_refactorer.py => unused.py} | 0 src/ecooptimizer/testing/__init__.py | 0 src/ecooptimizer/utils/refactorer_factory.py | 10 +++++----- .../{test_analyzer.py => test_pylint_analyzer.py} | 0 ..._code_carbon.py => test_codecarbon_energy_meter.py} | 0 tests/testing/{test_testing.py => test_run_tests.py} | 0 tests/utils/{test_utils.py => test_ast_parser.py} | 0 13 files changed, 9 insertions(+), 6 deletions(-) rename src/ecooptimizer/refactorers/{use_a_generator_refactorer.py => list_comp_any_all.py} (100%) rename src/ecooptimizer/refactorers/{long_lambda_function_refactorer.py => long_lambda_function.py} (100%) rename src/ecooptimizer/refactorers/{long_message_chain_refactorer.py => long_message_chain.py} (100%) rename src/ecooptimizer/refactorers/{long_parameter_list_refactorer.py => long_parameter_list.py} (100%) rename src/ecooptimizer/refactorers/{member_ignoring_method_refactorer.py => member_ignoring_method.py} (100%) rename src/ecooptimizer/refactorers/{unused_refactorer.py => unused.py} (100%) create mode 100644 src/ecooptimizer/testing/__init__.py rename tests/analyzers/{test_analyzer.py => test_pylint_analyzer.py} (100%) rename tests/measurements/{test_code_carbon.py => test_codecarbon_energy_meter.py} (100%) rename tests/testing/{test_testing.py => test_run_tests.py} (100%) rename tests/utils/{test_utils.py => test_ast_parser.py} (100%) diff --git a/.gitignore b/.gitignore index b246896c..accdc98c 100644 --- a/.gitignore +++ b/.gitignore @@ -302,4 +302,7 @@ __pycache__/ # Package files src/ecooptimizer/outputs/ build/ -tests/temp_dir/ \ No newline at end of file +tests/temp_dir/ + +# Coverage +.coverage \ No newline at end of file diff --git a/src/ecooptimizer/refactorers/use_a_generator_refactorer.py b/src/ecooptimizer/refactorers/list_comp_any_all.py similarity index 100% rename from src/ecooptimizer/refactorers/use_a_generator_refactorer.py rename to src/ecooptimizer/refactorers/list_comp_any_all.py diff --git a/src/ecooptimizer/refactorers/long_lambda_function_refactorer.py b/src/ecooptimizer/refactorers/long_lambda_function.py similarity index 100% rename from src/ecooptimizer/refactorers/long_lambda_function_refactorer.py rename to src/ecooptimizer/refactorers/long_lambda_function.py diff --git a/src/ecooptimizer/refactorers/long_message_chain_refactorer.py b/src/ecooptimizer/refactorers/long_message_chain.py similarity index 100% rename from src/ecooptimizer/refactorers/long_message_chain_refactorer.py rename to src/ecooptimizer/refactorers/long_message_chain.py diff --git a/src/ecooptimizer/refactorers/long_parameter_list_refactorer.py b/src/ecooptimizer/refactorers/long_parameter_list.py similarity index 100% rename from src/ecooptimizer/refactorers/long_parameter_list_refactorer.py rename to src/ecooptimizer/refactorers/long_parameter_list.py diff --git a/src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py b/src/ecooptimizer/refactorers/member_ignoring_method.py similarity index 100% rename from src/ecooptimizer/refactorers/member_ignoring_method_refactorer.py rename to src/ecooptimizer/refactorers/member_ignoring_method.py diff --git a/src/ecooptimizer/refactorers/unused_refactorer.py b/src/ecooptimizer/refactorers/unused.py similarity index 100% rename from src/ecooptimizer/refactorers/unused_refactorer.py rename to src/ecooptimizer/refactorers/unused.py diff --git a/src/ecooptimizer/testing/__init__.py b/src/ecooptimizer/testing/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/ecooptimizer/utils/refactorer_factory.py b/src/ecooptimizer/utils/refactorer_factory.py index 33688d2b..4b4c80d7 100644 --- a/src/ecooptimizer/utils/refactorer_factory.py +++ b/src/ecooptimizer/utils/refactorer_factory.py @@ -1,9 +1,9 @@ # Import specific refactorer classes -from refactorers.use_a_generator_refactorer import UseAGeneratorRefactorer -from refactorers.unused_refactorer import RemoveUnusedRefactorer -from refactorers.long_parameter_list_refactorer import LongParameterListRefactorer -from refactorers.member_ignoring_method_refactorer import MakeStaticRefactorer -from refactorers.long_message_chain_refactorer import LongMessageChainRefactorer +from ecooptimizer.refactorers.list_comp_any_all import UseAGeneratorRefactorer +from ecooptimizer.refactorers.unused import RemoveUnusedRefactorer +from ecooptimizer.refactorers.long_parameter_list import LongParameterListRefactorer +from ecooptimizer.refactorers.member_ignoring_method import MakeStaticRefactorer +from ecooptimizer.refactorers.long_message_chain import LongMessageChainRefactorer # Import the configuration for all Pylint smells from utils.logger import Logger diff --git a/tests/analyzers/test_analyzer.py b/tests/analyzers/test_pylint_analyzer.py similarity index 100% rename from tests/analyzers/test_analyzer.py rename to tests/analyzers/test_pylint_analyzer.py diff --git a/tests/measurements/test_code_carbon.py b/tests/measurements/test_codecarbon_energy_meter.py similarity index 100% rename from tests/measurements/test_code_carbon.py rename to tests/measurements/test_codecarbon_energy_meter.py diff --git a/tests/testing/test_testing.py b/tests/testing/test_run_tests.py similarity index 100% rename from tests/testing/test_testing.py rename to tests/testing/test_run_tests.py diff --git a/tests/utils/test_utils.py b/tests/utils/test_ast_parser.py similarity index 100% rename from tests/utils/test_utils.py rename to tests/utils/test_ast_parser.py From 238d594b157e67800764e550426274f873af959e Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:34:16 -0500 Subject: [PATCH 095/105] created ruff pre-commit (#254) --- .pre-commit-config.yaml | 10 ++++++++++ pyproject.toml | 28 ++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..ad82203d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.7.4 + hooks: + # Run the linter. + - id: ruff + args: [ --fix ] + # Run the formatter. + - id: ruff-format \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index dcd670a0..5f6f98cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ dependencies = [ "astor", "codecarbon" ] -requires-python = ">=3.8" +requires-python = ">=3.9" authors = [ {name = "Sevhena Walker"}, {name = "Mya Hussain"}, @@ -25,7 +25,7 @@ readme = "README.md" license = {file = "LICENSE"} [project.optional-dependencies] -dev = ["pytest", "mypy", "ruff", "coverage", "pyright"] +dev = ["pytest", "mypy", "ruff", "coverage", "pyright", "pre-commit"] [project.urls] Documentation = "https://readthedocs.org" @@ -40,13 +40,29 @@ pythonpath = "src" [tool.ruff] extend-exclude = ["*tests/input/**/*.py", "tests/_input_copies"] +line-length = 100 [tool.ruff.lint] -# 1. Enable flake8-bugbear (`B`) rules, in addition to the defaults. -select = ["E4", "E7", "E9", "F", "B", "PT", "W"] +select = [ + "E", # Enforce Python Error rules (e.g., syntax errors, exceptions). + "UP", # Check for unnecessary passes and other unnecessary constructs. + "ANN001", # Ensure type annotations are present where needed. + "ANN002", + "ANN003", + "ANN401", + "INP", # Flag invalid Python patterns or usage. + "PTH", # Check path-like or import-related issues. + "F", # Enforce function-level checks (e.g., complexity, arguments). + "B", # Enforce best practices for Python coding (general style rules). + "PT", # Enforce code formatting and Pythonic idioms. + "W", # Enforce warnings (e.g., suspicious constructs or behaviours). + "A", # Flag common anti-patterns or bad practices. + "RUF", # Ruff-specific rules. + "ARG", # Check for function argument issues. +] # 2. Avoid enforcing line-length violations (`E501`) -ignore = ["E501"] +ignore = ["E501", "RUF003"] # 3. Avoid trying to fix flake8-bugbear (`B`) violations. unfixable = ["B"] @@ -54,7 +70,7 @@ unfixable = ["B"] # 4. Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories. [tool.ruff.lint.per-file-ignores] "__init__.py" = ["E402"] -"**/{tests,docs,tools}/*" = ["E402"] +"**/{tests,docs,tools}/*" = ["E402", "ANN"] [tool.pyright] include = ["src", "tests"] From b7c151bc88c28cff62518d982807ce07911c65c2 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:41:19 -0500 Subject: [PATCH 096/105] changed pre-commit ruff config to run formatter first (#254) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad82203d..fc04efac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,8 +3,8 @@ repos: # Ruff version. rev: v0.7.4 hooks: + # Run the formatter. + - id: ruff-format # Run the linter. - id: ruff - args: [ --fix ] - # Run the formatter. - - id: ruff-format \ No newline at end of file + \ No newline at end of file From 3a8598675470e69f529139e338c2b54faf8157d8 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:52:05 -0500 Subject: [PATCH 097/105] change .py linting workflow to only check rules not fix (#254) --- .github/workflows/python-lint.yaml | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index 1bc19d3d..b084fe0e 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -1,4 +1,4 @@ -name: "Make Python Files Pretty" +name: "Lint Python Files" on: pull_request: @@ -26,26 +26,8 @@ jobs: with: token: ${{ steps.app-token.outputs.token }} - - name: Install Python - uses: actions/setup-python@v5 - with: - python-version: "3.11" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install ruff - - name: Run Ruff - run: | - ruff format - ruff check --fix --output-format=github . - - # Commit the generated PDF back to the repository - - name: Commit & Push changes - uses: EndBug/add-and-commit@v9 + uses: astral-sh/ruff-action@v1 with: - author_name: "Github Action" - author_email: "action@github.com" - message: "Made automatic formatting/lint fixes" + changed-files: "true" From 02fb0a1819612a6623597de136abdf348983efb1 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:00:08 -0500 Subject: [PATCH 098/105] update ruff linting workflow to use existing config file (#254) --- .github/workflows/python-lint.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index b084fe0e..d829c54f 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -29,5 +29,6 @@ jobs: - name: Run Ruff uses: astral-sh/ruff-action@v1 with: + args: "--config pyproject.toml" changed-files: "true" From 1d592e8efef17b144226b813dad5382ad1c52cf8 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:09:54 -0500 Subject: [PATCH 099/105] fix python-lint.yaml --- .github/workflows/python-lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index d829c54f..7d8d4915 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -29,6 +29,6 @@ jobs: - name: Run Ruff uses: astral-sh/ruff-action@v1 with: - args: "--config pyproject.toml" + args: "check --config pyproject.toml" changed-files: "true" From c72ac15f668582df090b85ea044b9f6eef5b63ea Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:40:58 -0500 Subject: [PATCH 100/105] fix python-lint.yaml (#254) --- .github/workflows/python-lint.yaml | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index 7d8d4915..9185c14e 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -6,7 +6,7 @@ on: branches: [dev] paths: - "src/**/*.py" - + jobs: lint: runs-on: ubuntu-latest @@ -26,9 +26,31 @@ jobs: with: token: ${{ steps.app-token.outputs.token }} - - name: Run Ruff - uses: astral-sh/ruff-action@v1 + # Get changed .py files + - name: Get changed .py files + id: changed-py-files + uses: tj-actions/changed-files@v45 + with: + files: | + **/*.py + files_ignore: | + tests/input + tests/_input_copies + diff_relative: true # Get the list of files relative to the repo root + + - name: Install Python + uses: actions/setup-python@v5 with: - args: "check --config pyproject.toml" - changed-files: "true" + python-version: "3.11" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Run Ruff + env: + ALL_CHANGED_FILES: ${{ steps.changed-py-files.outputs.all_changed_files }} + run: | + ruff check $ALL_CHANGED_FILES --output-format=github . From eea4025f4fb937edf4cd447447b24016da12d192 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:43:47 -0500 Subject: [PATCH 101/105] fix python-lint.yaml --- .github/workflows/python-lint.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index 9185c14e..d62082a4 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -34,8 +34,8 @@ jobs: files: | **/*.py files_ignore: | - tests/input - tests/_input_copies + tests/input/**/*.py + tests/_input_copies/**/.py diff_relative: true # Get the list of files relative to the repo root - name: Install Python From 37e458dd0a680f42f42f6a22b6786e7893ba9867 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:48:00 -0500 Subject: [PATCH 102/105] final fix (please) for python-lint.yaml --- .github/workflows/python-lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index d62082a4..133de123 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -35,7 +35,7 @@ jobs: **/*.py files_ignore: | tests/input/**/*.py - tests/_input_copies/**/.py + tests/_input_copies/**/*.py diff_relative: true # Get the list of files relative to the repo root - name: Install Python From 668d3e784dd75b965df77205748090005b1e5c50 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:45:03 -0500 Subject: [PATCH 103/105] Changed testing workflow to check coverage (#259) --- .github/workflows/python-test.yaml | 38 +++++++++++++----------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index a6d6c78e..bfeef4fe 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -5,11 +5,7 @@ on: types: [opened, reopened, synchronize] branches: [dev] paths: - - "src/ecooptimizer/analyzers/**/*.py" - - "src/ecooptimizer/measurements/**/*.py" - - "src/ecooptimizer/refactorers/**/*.py" - - "src/ecooptimizer/utils/**/*.py" - - "src/ecooptimizer/testing/**/*.py" + - "src/ecooptimizer/**/*.py" jobs: test: @@ -41,25 +37,25 @@ jobs: pip install . pip install .'[dev]' - - name: Get changed modules - id: changed-modules + - name: Get changed files + id: changed-files uses: tj-actions/changed-files@v45 with: files: | - src/ecooptimizer/analyzers/**/*.py - src/ecooptimizer/measurements/**/*.py - src/ecooptimizer/refactorers/**/*.py - src/ecooptimizer/utils/**/*.py - src/ecooptimizer/testing/**/*.py - dir_names: True + src/ecooptimizer/**/*.py - - name: Run Pytest - if: steps.changed-modules.outputs.any_changed == 'true' - env: - ALL_CHANGED_MODULES: ${{ steps.changed-modules.outputs.all_changed_files }} + - name: Run Tests and Generate Coverage Report run: | - for module in ${ALL_CHANGED_MODULES}; do - folder="$(basename $module)" - pytest "tests/$folder/" + pytest --cov=src/ecooptimizer --cov-branch --cov-report=xml --cov-report=term-missing + + - name: Check Coverage for Changed Lines + run: | + git fetch origin ${{ github.base_ref }} + diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --fail-under=80 + + - name: Check Per-File Coverage + run: | + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + echo "Checking overall coverage for $file" + coverage report --include=$file --fail-under=80 || exit 1 done - From cc99cdee11c16d849f4433b3aeac593b7dc4ee13 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:05:59 -0500 Subject: [PATCH 104/105] add pytest-cov dependency to .toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5f6f98cb..bf941cd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ readme = "README.md" license = {file = "LICENSE"} [project.optional-dependencies] -dev = ["pytest", "mypy", "ruff", "coverage", "pyright", "pre-commit"] +dev = ["pytest", "pytest-cov", "mypy", "ruff", "coverage", "pyright", "pre-commit"] [project.urls] Documentation = "https://readthedocs.org" From 6a7ef99e7174aa60dfc8e1d2f257c186d6d88767 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:12:49 -0500 Subject: [PATCH 105/105] add diff-cover dependency to python workflow .yaml (#259) --- .github/workflows/python-test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-test.yaml b/.github/workflows/python-test.yaml index bfeef4fe..45902a32 100644 --- a/.github/workflows/python-test.yaml +++ b/.github/workflows/python-test.yaml @@ -35,6 +35,7 @@ jobs: run: | python -m pip install --upgrade pip pip install . + pip install diff-cover pip install .'[dev]' - name: Get changed files