一键导入
dftracer-annotate-python
Python annotation rules for dftracer — decorator usage, initialize/finalize, comp types, class methods, and quick checklist
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Python annotation rules for dftracer — decorator usage, initialize/finalize, comp types, class methods, and quick checklist
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Communication-component (MPI/collective/network) bottleneck-to-optimization mappings, papers, and L1/L2/L3 strategies for the dftracer optimization pipeline
Compute-component bottleneck-to-optimization mappings, papers, and L1/L2/L3 strategies for the dftracer optimization pipeline
Key literature, bottleneck-to-optimization mappings, and strategies for the dftracer I/O optimization pipeline
Memory-component bottleneck-to-optimization mappings, papers, and L1/L2/L3 strategies for the dftracer optimization pipeline
VPIC-Kokkos-specific knowledge: build/annotation quirks, the two-stage deck-compile pattern, deck sizing for smoke vs validation runs, and the measured MPI-communication-bound diagnosis on Tuolumne. Load this skill whenever working with vpic-kokkos (github.com/lanl/vpic-kokkos).
Install and build dftracer into the session using the MCP install tool and record tool pitfalls early.
| name | dftracer-annotate-python |
| description | Python annotation rules for dftracer — decorator usage, initialize/finalize, comp types, class methods, and quick checklist |
from dftracer.logger import dftracer_fn, dft_fn
@dftracer_fn(cat="IO") # cat groups functions in the trace viewer
def my_read(path: str, size: int) -> bytes:
...
@dftracer_fn decorator wraps the function with START/END automatically.cat (category) is required — use a meaningful group name: "IO", "Compute",
"MPI", "Data", "Init", etc.dft_fn is an alias for dftracer_fn — prefer dftracer_fn for clarity.from dftracer.logger import DFTracer
# At program entry (after MPI.Init if using mpi4py)
tracer = DFTracer.initialize_log(
log_file="traces/my_app", # prefix for .pfw trace files
data_dir="/data", # directory to monitor for I/O events
process_id=rank, # Pointer to MPI rank or 0 for single-process
)
# At program exit (before MPI.Finalize if using mpi4py)
DFTracer.finalize_log()
DFTracer.initialize_log AFTER MPI.Init().DFTracer.finalize_log() BEFORE MPI.Finalize().process_id=NULL for single-process runs.export DFTRACER_ENABLE=1
export DFTRACER_LOG_FILE=/tmp/traces/my_app
export DFTRACER_DATA_DIR=/data
python my_app.py
The env var only handles INIT/FINI — decorators are still needed for function-level spans.
from dftracer.logger import DFTracer
tracer = DFTracer.get_instance()
with tracer.get_time("IO", "read_loop"):
for chunk in data:
process(chunk)
Only use context managers when the code block is too coarse-grained to fit a function decorator.
from dftracer.logger import dftracer_fn
@dftracer_fn(cat="IO", comp="io")
def read_checkpoint(path: str) -> dict: ...
@dftracer_fn(cat="COMM", comp="comm")
def broadcast_weights(tensor, comm): ...
@dftracer_fn(cat="CPU", comp="cpu")
def compute_checksum(data: bytes) -> str: ...
@dftracer_fn(cat="MEM", comp="mem")
def copy_batch(src, dst) -> None: ...
Types: "io", "mem", "cpu", "comm" — same taxonomy as C.
If dftracer_fn doesn't accept comp as a keyword argument:
@dftracer_fn(cat="IO")
def read_checkpoint(path: str) -> dict:
DFTracer.get_instance().update("comp", "io") # fallback
...
# ✅ Annotate — does real file I/O
@dftracer_fn(cat="IO")
def read_checkpoint(path: str, rank: int) -> dict:
with open(path, "rb") as f:
return pickle.load(f)
# ❌ Skip — trivial property
@property
def rank(self) -> int:
return self._rank
# ❌ Skip — one-liner string helper
def _fmt_path(self, p: str) -> str:
return str(Path(p).resolve())
class DataLoader:
@dftracer_fn(cat="IO")
def load(self, path: str, batch_size: int) -> list:
...
@dftracer_fn(cat="IO")
def write(self, path: str, data: bytes) -> None:
...
def _validate(self, x): # ❌ skip — trivial helper
return x is not None
from dftracer.logger import dftracer_fn imported at top of fileDFTracer.initialize_log(...) called at program entry (after MPI.Init if applicable)DFTracer.finalize_log() called at program exit (before MPI.Finalize if applicable)@dftracer_fn(cat="<CATEGORY>", comp="<type>") on every annotated functioncomp is one of "io", "mem", "cpu", "comm"