Skip to content

Aggregates with integer keys #25

@ictrobot

Description

@ictrobot

Does python-dtrace support using integer keys in aggregates?

Here is a simple example:

from dtrace import DTraceConsumerThread
from subprocess import check_output, Popen, PIPE, STDOUT
import time

script = """syscall::read:entry /execname == "dd"/
{
    @values[arg2] = count();
}"""
command = ["dd", "if=/dev/zero", "of=/dev/null", "status=none", "bs=1M", "count=10"]

print("Running with dtrace-python")
dtrace_thread = DTraceConsumerThread(script, sleep=1)
dtrace_thread.start()
check_output(command)
dtrace_thread.stop()
dtrace_thread.join()

print("\nRunning with command line dtrace")
with Popen(["dtrace", "-n", script], stderr=STDOUT, stdout=PIPE) as proc:
    time.sleep(0.5) # let dtrace start
    check_output(command)
    proc.terminate()
    print(proc.stdout.read().decode())

python-dtrace prints:

1793 1 [b'/'] 1
1793 1 [b'\x80'] 1
1793 1 [b''] 10

The dtrace command prints

               47                1
              128                1
          1048576               10

Is there some way to recover the integer aggregate keys from the byte strings returned (b'/', b'\x80', b''), or is this functionality not yet supported?
Thanks in advance.

(I'm using version 0.0.12 installed from master, on FreeBSD 13)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions