Re: Converting int to a string in DTrace

2022-08-30 Thread Domagoj Stolfa

I'm not sure if it's documented anywhere in FreeBSD itself, but it is

documented here: https://illumos.org/books/dtrace/chp-actsub.html.


--

Domagoj


On 8/30/2022 5:01 PM, Mateusz Piotrowski wrote:

Hey Domagoj!

On 30. Aug 2022, at 17:58, Domagoj Stolfa  
wrote:



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


This is exactly what  I was looking for, thanks!

Is it documented somewhere on FreeBSD?

Best,
Mateusz

Re: Converting int to a string in DTrace

2022-08-30 Thread Mateusz Piotrowski
Hey Domagoj!

> On 30. Aug 2022, at 17:58, Domagoj Stolfa  wrote:
> 
> 
> this->unit_number = args[1]->unit_number >= 0 ? 
> lltostr(args[1]->unit_number) : "";

This is exactly what  I was looking for, thanks!

Is it documented somewhere on FreeBSD?

Best,
Mateusz

Re: Converting int to a string in DTrace

2022-08-30 Thread Domagoj Stolfa

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

Converting int to a string in DTrace

2022-08-30 Thread Mateusz Piotrowski
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