Hi Mateusz:

I believe that lltostr might be what you're looking for?


        this->unit_number = args[1]->unit_number >= 0 ? lltostr(args[1]->unit_number) : "";


--
Domagoj

On 8/30/2022 4:49 PM, Mateusz Piotrowski wrote:
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

Reply via email to