Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new script for finding db client metrics #16

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions analyze_local.py
Original file line number Diff line number Diff line change
@@ -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}")
Loading