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

Add ops-jsonl #88

Merged
merged 3 commits into from
Jan 18, 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
50 changes: 50 additions & 0 deletions probe_src/python/probe_py/manual/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import typing
import dataclasses
import json
from typing_extensions import Annotated
import pathlib
import typer
Expand Down Expand Up @@ -413,6 +416,53 @@ def nextflow(
script = g.generate_workflow(dataflow_graph)
output.write_text(script)


@export_app.command()
def ops_jsonl(
probe_log: Annotated[
pathlib.Path,
typer.Argument(help="output file written by `probe record -o $file`."),
] = pathlib.Path("probe_log"),
) -> None:
"""
Export each op to a JSON line.

The format is subject to change as PROBE evolves. Use with caution!
"""

def filter_nested_dict(
dct: typing.Mapping[typing.Any, typing.Any],
) -> typing.Mapping[typing.Any, typing.Any]:
"""Converts the bytes in a nested dict to a string"""
return {
key: (
# If dict, Recurse self
filter_nested_dict(val) if isinstance(val, dict) else
# If bytes, decode to string
val.decode(errors="surrogateescape") if isinstance(val, bytes) else
# Else, do nothing
val
)
for key, val in dct.items()
}
stdout_console = rich.console.Console()
prov_log = parse_probe_log(probe_log)
for pid, process in prov_log.processes.items():
for exec_epoch_no, exec_epoch in process.exec_epochs.items():
for tid, thread in exec_epoch.threads.items():
for i, op in enumerate(thread.ops):
stdout_console.print_json(json.dumps({
"pid": pid,
"tid": tid,
"exec_epoch_no": exec_epoch_no,
"i": i,
"op": filter_nested_dict(
dataclasses.asdict(op),
),
"op_data_type": type(op.data).__name__,
}))


# Example: scp Desktop/sample_example.txt [email protected]:/home/remote_dir
@app.command(
context_settings=dict(
Expand Down