Skip to content

Commit dc0af97

Browse files
committed
store the tracer command in the sqlite for future use
1 parent a06d726 commit dc0af97

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

codeflash/tracer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def __init__(
8181
config_file_path: Path | None = None,
8282
max_function_count: int = 256,
8383
timeout: int | None = None, # seconds
84+
command: str | None = None,
8485
) -> None:
8586
"""Use this class to trace function calls.
8687
@@ -91,6 +92,7 @@ def __init__(
9192
:param max_function_count: Maximum number of times to trace one function
9293
:param timeout: Timeout in seconds for the tracer, if the traced code takes more than this time, then tracing
9394
stops and normal execution continues. If this is None then no timeout applies
95+
:param command: The command that initiated the tracing (for metadata storage)
9496
"""
9597
if functions is None:
9698
functions = []
@@ -148,6 +150,9 @@ def __init__(
148150
assert "test_framework" in self.config, "Please specify 'test-framework' in pyproject.toml config file"
149151
self.t = self.timer()
150152

153+
# Store command information for metadata table
154+
self.command = command if command else " ".join(sys.argv)
155+
151156
def __enter__(self) -> None:
152157
if self.disable:
153158
return
@@ -174,6 +179,19 @@ def __enter__(self) -> None:
174179
"CREATE TABLE function_calls(type TEXT, function TEXT, classname TEXT, filename TEXT, "
175180
"line_number INTEGER, last_frame_address INTEGER, time_ns INTEGER, args BLOB)"
176181
)
182+
183+
# Create metadata table to store command information
184+
cur.execute("CREATE TABLE metadata(key TEXT PRIMARY KEY, value TEXT)")
185+
186+
# Store command metadata
187+
cur.execute("INSERT INTO metadata VALUES (?, ?)", ("command", self.command))
188+
cur.execute("INSERT INTO metadata VALUES (?, ?)", ("program_name", self.file_being_called_from))
189+
cur.execute(
190+
"INSERT INTO metadata VALUES (?, ?)",
191+
("functions_filter", json.dumps(self.functions) if self.functions else None),
192+
)
193+
cur.execute("INSERT INTO metadata VALUES (?, ?)", ("timestamp", str(int(time.time()))))
194+
cur.execute("INSERT INTO metadata VALUES (?, ?)", ("project_root", str(self.project_root)))
177195
console.rule("Codeflash: Traced Program Output Begin", style="bold blue")
178196
frame = sys._getframe(0) # Get this frame and simulate a call to it # noqa: SLF001
179197
self.dispatch["call"](self, frame, 0)
@@ -842,6 +860,7 @@ def main() -> ArgumentParser:
842860
max_function_count=args.max_function_count,
843861
timeout=args.tracer_timeout,
844862
config_file_path=args.codeflash_config,
863+
command=" ".join(sys.argv),
845864
).runctx(code, globs, None)
846865

847866
except BrokenPipeError as exc:

0 commit comments

Comments
 (0)