Skip to content
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
12 changes: 5 additions & 7 deletions codeflash/languages/java/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def instrument_function(self, func: FunctionInfo, lines: list[str], file_path: P
# Add profiling to each executable line
function_entry_added = False

file_posix = file_path.as_posix()

for local_idx, line in enumerate(func_lines):
local_line_num = local_idx + 1 # 1-indexed within function
global_line_num = func.starting_line + local_idx # Global line number
Expand All @@ -377,23 +379,19 @@ def instrument_function(self, func: FunctionInfo, lines: list[str], file_path: P
if (
local_line_num in executable_lines
and stripped
and not stripped.startswith("//")
and not stripped.startswith("/*")
and not stripped.startswith("*")
and not stripped.startswith(("//", "/*", "*"))
and stripped not in ("}", "};")
):
# Get indentation
indent = len(line) - len(line.lstrip())
indent_str = " " * indent

# Store line content for profiler output
content_key = f"{file_path.as_posix()}:{global_line_num}"
content_key = f"{file_posix}:{global_line_num}"
self.line_contents[content_key] = stripped

# Add hit() call before the line
profiled_line = (
f'{indent_str}{self.profiler_class}.hit("{file_path.as_posix()}", {global_line_num});\n{line}'
)
profiled_line = f'{indent_str}{self.profiler_class}.hit("{file_posix}", {global_line_num});\n{line}'
instrumented_lines.append(profiled_line)
else:
instrumented_lines.append(line)
Expand Down
Loading