Skip to content

Benchmark directive produces NA for all metrics on Windows (AttributeError on meminfo.pss) #4159

@PatrikMrnka

Description

@PatrikMrnka

Snakemake version
9.19.0

Operating system

Windows 10/11 (tested with micromamba-managed environment)

Describe the bug
The benchmark: directive records only wall-clock time (s, h:m:s). All other
columns (max_rss, max_vms, max_uss, max_pss, io_in, io_out,
mean_load, cpu_time) are written as NA on Windows.

Root cause

In snakemake/benchmark.py, BenchmarkTimer._update_record() accesses
meminfo.pss unconditionally (line ~240):

pss += meminfo.pss

On Windows, psutil.Process.memory_full_info() does not return a pss
field (Proportional Set Size is a Linux-only metric). This raises
AttributeError, which is caught by BenchmarkTimer.work():

except AttributeError:
    pass  # skip, process died in flight

The exception is silently swallowed every polling cycle, so
data_collected never becomes True and all metrics remain NoneNA.

Confirmation

I verified that psutil works correctly inside a Snakemake run: block on
the same machine:

PID: 13148
memory_info OK -> RSS=101478400, VMS=82669568
memory_full_info OK -> USS=76996608
io_counters OK -> read=28964767, write=1707
children OK -> count=0
parent process OK -> PID=12860, name=snakemake.exe
parent.children OK -> count=1

All psutil calls succeed — the only failure point is the missing pss
attribute.

Minimal example

# Snakefile
rule test_benchmark:
    output: "test_flag.txt"
    benchmark: "benchmark.txt"
    run:
        import time
        data = [0] * (50 * 1024 * 1024)  # allocate ~400 MB
        time.sleep(60)
        with open(output[0], "w") as f:
            f.write("done")
snakemake --cores 1 test_flag.txt
type benchmark.txt

Expected output: Filled values for at least max_rss, max_vms, max_uss, io_in, io_out.

Actual output:

s       h:m:s   max_rss max_vms max_uss max_pss io_in   io_out  mean_load       cpu_time
60.27   0:01:00 NA      NA      NA      NA      NA      NA      NA              NA

Suggested fix

Replace the direct attribute access with getattr:

pss += getattr(meminfo, "pss", 0)

This is a one-line change in snakemake/benchmark.py inside
_update_record(). On Linux nothing changes (the attribute exists). On
Windows/macOS, pss will report 0 but all other metrics will work
correctly.

I am happy to submit a PR with this fix and a corresponding test case if
desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions