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>
next in thread | raw e-mail | index | archive | help
--Apple-Mail=_21A9CCA2-6BC2-43C1-B484-2EE36926FCF8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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 =3D args[1]->unit_number >=3D 0 ? = (string)args[1]->unit_number : ""; @[args[1]->device_name, this->unit_number, execname, pid] =3D = 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= --Apple-Mail=_21A9CCA2-6BC2-43C1-B484-2EE36926FCF8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; = charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; line-break: after-white-space;" class=3D"">Hello= everyone,<div class=3D""><br class=3D""></div><div class=3D"">Is it = possible to convert an int to a string in DTrace?</div><div class=3D""><br= class=3D""></div><div class=3D"">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=3D""><br class=3D""></div><blockquote = style=3D"margin: 0 0 0 40px; border: none; padding: 0px;" class=3D""><div = class=3D""><div class=3D"">#!/usr/sbin/dtrace -s</div></div><div = class=3D""><div class=3D""><br class=3D""></div></div><div class=3D""><div= class=3D"">#pragma D option quiet</div></div><div class=3D""><div = class=3D""><br class=3D""></div></div><div class=3D""><div = class=3D"">io:::start</div></div><div class=3D""><div = class=3D"">{</div></div><div class=3D""><div class=3D""> = this->unit_number =3D args[1]->unit_number >=3D 0 = ? (string)args[1]->unit_number : "";</div></div><div class=3D""><div = class=3D""> @[args[1]->device_name, = this->unit_number, execname, pid] =3D = sum(args[0]->bio_bcount);</div></div><div class=3D""><div = class=3D"">}</div></div><div class=3D""><div class=3D""><br = class=3D""></div></div><div class=3D""><div class=3D"">END</div></div><div= class=3D""><div class=3D"">{</div></div><div class=3D""><div = class=3D""> printf("%10s%-3s %20s %10s = %15s\n", "DEVICE", "", "APP", "PID", "BYTES");</div></div><div = class=3D""><div class=3D""> printa("%10s%-3s = %20s %10d %15@d\n", @);</div></div><div class=3D""><div = class=3D"">}</div></div></blockquote><div class=3D""><div class=3D""><br = class=3D""></div></div><div class=3D"">(Of course, the `(string)` cast = does not work here because it's just not how DTrace works.)</div><div = class=3D""><br class=3D""></div><div class=3D"">Best,</div><div = class=3D"">Mateusz</div></body></html>= --Apple-Mail=_21A9CCA2-6BC2-43C1-B484-2EE36926FCF8--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?317C65CC-5BF0-422D-80E9-4340CD241569>