Converting int to a string in DTrace

From: Mateusz Piotrowski <0mp_at_FreeBSD.org>
Date: Tue, 30 Aug 2022 15:49:21 UTC
Hello everyone,

Is it possible to convert an int to a string in DTrace?

E.g., I'd like the following script to work (it's an example from dtrace_io(4), but with device unit number added):

#!/usr/sbin/dtrace -s

#pragma D option quiet

io:::start
{
        this->unit_number = args[1]->unit_number >= 0 ? (string)args[1]->unit_number : "";
        @[args[1]->device_name, this->unit_number, execname, pid] = sum(args[0]->bio_bcount);
}

END
{
        printf("%10s%-3s %20s %10s %15s\n", "DEVICE", "", "APP", "PID", "BYTES");
        printa("%10s%-3s %20s %10d %15@d\n", @);
}

(Of course, the `(string)` cast does not work here because it's just not how DTrace works.)

Best,
Mateusz