Now that we have it, let's use it.
I did one small rewrite of tapset/inet_sock.stp, which is nicely smaller now. It does still need a small tidbit of embedded C because we cannot easily cast between basic types/unions, see the new daddr_to_string. function inet_get_local_port:long(sock:long) { %(kernel_v < "2.6.21" %? port = @cast(sock, "inet_sock", "kernel")->inet->num; %: port = @cast(sock, "inet_sock", "kernel")->num; %) return port; } // Get IP source address string given a pointer to a kernel socket. function inet_get_ip_source:string(sock:long) { %(kernel_v < "2.6.21" %? daddr = @cast(sock, "inet_sock", "kernel")->inet->daddr; %: daddr = @cast(sock, "inet_sock", "kernel")->daddr; %) return daddr_to_string(daddr); } // Turns a daddr as found in an inet_sock into a dotted ip string. function daddr_to_string:string(daddr:long) %{ /* pure */ union { __u32 d; unsigned char addr[4]; } u; u.d = THIS->daddr; sprintf(THIS->__retvalue, "%d.%d.%d.%d", u.addr[0], u.addr[1], u.addr[2], u.addr[3]); %}
Created attachment 3794 [details] Revamp some functions of nfs.stp using @cast The new functions look more compact and many duplicated codes have been eliminated.
Yes much nicer and much more readable compared to the previous versions. Thanks. One minor stylistic request. Could you add spaces around the ? and : so that something like: dentry = file? @cast(file, "file", "kernel")->f_dentry: 0 will look like: dentry = file ? @cast(file, "file", "kernel")->f_dentry : 0 that makes them a bit more readable and makes the sources a bit more consistent (currently the sources sometimes do and sometimes don't add spaces).
thanks for your review. More update see commit fb3b52a7346202fea1905ed680a3256d372a7b03 PR9871: use @cast in tapset
In taspset/*/registers.stp, _stp_get_register_by_offset() could be replaced using @cast.
(In reply to comment #5) > In taspset/*/registers.stp, _stp_get_register_by_offset() could be replaced > using @cast. Just remember that @cast requires debuginfo -- aren't the registers tapsets designed to be helpful for running with no debuginfo?
Correct. (In reply to comment #6) > (In reply to comment #5) > > In taspset/*/registers.stp, _stp_get_register_by_offset() could be replaced > > using @cast. > > Just remember that @cast requires debuginfo -- aren't the registers tapsets > designed to be helpful for running with no debuginfo? Yes, indeed. Does it help that we'd be casting only to predefined types -- e.g., pointer-to-long?
(In reply to comment #7) > Yes, indeed. Does it help that we'd be casting only to predefined types -- > e.g., pointer-to-long? For POD types, you can just use kernel_long() and family.
I have some problems with the 0.9.7 Version of Systemtap. Scripts than run with 0.9 don't run anymore on 0.9.7. I think it affects the "@cast" stuff, in my example this affects "inet_sock.stp" Changing: daddr = @cast(sock, "inet_sock", "kernel")->inet->daddr; To: daddr = @cast(sock, "inet_sock", "kernel<linux/ip.h>")->inet->daddr; Fixes the problem. I have a 2.6.9 Kernel.
Commit 961479c removes some embedded-C from tcpmib.stp
Commit 1713a05 removed some embedded-C in ioblock.stp/vfs.stp
Commit fd81a55 removed some embedded-C from nfs_proc.stp.
Commit abf0244 removed more embedded-C from nfs_proc.stp.
Commit 84b869b removed more embedded-C in nfs_proc.stp and nfs.stp.
Commit dd3d6ed removed some embedded-C from scsi.stp.
Commit 7dfee5e removes all embedded-C in rpc.stp.
Commit 354c797 removed some embedded-C in ioblock.stp and ipmib.stp.
Commit 5ccccbb removed all remaining embedded-C from vfs.stp.
Commit 00bd540 removed some embedded-C from task.stp and context.stp.
I've made a pass through the tapsets and removed embedded-C when feasible.