From 2e857ffaee9a88da08a5ddd9f00339ea36ebcba3 Mon Sep 17 00:00:00 2001 From: Jay DeLuca Date: Wed, 22 Jan 2025 06:44:27 -0500 Subject: [PATCH] new script for finding db client metrics (#16) --- analyze_local.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 analyze_local.py diff --git a/analyze_local.py b/analyze_local.py new file mode 100644 index 0000000..63b5a5f --- /dev/null +++ b/analyze_local.py @@ -0,0 +1,35 @@ +import os +from typing import List, Tuple + + +def find_string_in_files(file_list: List[str], search_string: str) -> List[str]: + matching_files = [] + for file_path in file_list: + if file_path.endswith(".java"): + try: + with open(file_path, 'r', encoding='utf-8') as file: + for line in file: + if search_string in line: + matching_files.append(file_path) + break + except FileNotFoundError: + continue + return matching_files + + +def traverse_and_search(root_dir: str, search_string: str) -> List[Tuple[str, str]]: + matching_files = [] + for dirpath, _, filenames in os.walk(root_dir): + file_paths = [os.path.join(dirpath, f) for f in filenames] + for file_path in find_string_in_files(file_paths, search_string): + instrumentation_name = file_path.split("/instrumentation/")[1].split("/")[0] + matching_files.append((instrumentation_name, file_path)) + return matching_files + + +if __name__ == "__main__": + root_directory = "/Users/jay/code/projects/opentelemetry-java-instrumentation/instrumentation/" + search_str = "DbClientMetrics.get()" + result = traverse_and_search(root_directory, search_str) + for instrumentation_name, file_path in result: + print(f"{instrumentation_name}: {file_path}")