Date: Tue, 30 Aug 2022 17:49:21 +0200 From: Mateusz Piotrowski <0mp@FreeBSD.org> To: freebsd-dtrace@freebsd.org Subject: Converting int to a string in DTrace Message-ID: <317C65CC-5BF0-422D-80E9-4340CD241569@FreeBSD.org>
index | next in thread | raw e-mail
[-- Attachment #1 --]
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
[-- Attachment #2 --]
<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hello everyone,<div class=""><br class=""></div><div class="">Is it possible to convert an int to a string in DTrace?</div><div class=""><br class=""></div><div class="">E.g., I'd like the following script to work (it's an example from dtrace_io(4), but with device unit number added):</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class="">#!/usr/sbin/dtrace -s</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">#pragma D option quiet</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">io:::start</div></div><div class=""><div class="">{</div></div><div class=""><div class=""> this->unit_number = args[1]->unit_number >= 0 ? (string)args[1]->unit_number : "";</div></div><div class=""><div class=""> @[args[1]->device_name, this->unit_number, execname, pid] = sum(args[0]->bio_bcount);</div></div><div class=""><div class="">}</div></div><div class=""><div class=""><br class=""></div></div><div class=""><div class="">END</div></div><div class=""><div class="">{</div></div><div class=""><div class=""> printf("%10s%-3s %20s %10s %15s\n", "DEVICE", "", "APP", "PID", "BYTES");</div></div><div class=""><div class=""> printa("%10s%-3s %20s %10d %15@d\n", @);</div></div><div class=""><div class="">}</div></div></blockquote><div class=""><div class=""><br class=""></div></div><div class="">(Of course, the `(string)` cast does not work here because it's just not how DTrace works.)</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Mateusz</div></body></html>
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?317C65CC-5BF0-422D-80E9-4340CD241569>
