At present, dtrace does not support conditional execution, so no if''s and no loops. With the current design, all collection of statistics is about something that is happening. This means I can''t present information about objects that have no activity alongside those that do. Well, I suppose I can, but I have to either provide the information from outside of the D script or cause some iterative function to occur that the D script can monitor and learn from - both of which seem like kludges to me. Therefore what I''d like to do is be able to return an array of objects and assign them the value "0". For example: @fsactivity[zfs_list()] = zero(); ... where "zfs_list()" would return an array of strings that are the names of all the zfs filesystems and zero() is a function that would be considered an aggregation friendly function that assigned 0 to every element in fsactivity. Now I know that doing zero() is possible, and specifics of zfs_list() aside, but is it possible to support a function returning an array or list that is used to populate an array in D? Can the internals of D be easily modified to work in that fashion or would that require an extensive rewrite? Darren
Nicolas Williams
2010-Oct-15 23:26 UTC
[dtrace-discuss] Supporting the return of an array...
On Fri, Oct 15, 2010 at 04:08:25PM -0700, Darren Reed wrote:> At present, dtrace does not support conditional execution, > so no if''s and no loops.There''s the ? : operator...> With the current design, all collection of statistics is about > something that is happening. This means I can''t present > information about objects that have no activity alongside > those that do. Well, I suppose I can, but I have to either > provide the information from outside of the D script or > cause some iterative function to occur that the D script > can monitor and learn from - both of which seem like > kludges to me.You might be better off using the Java interface to DTrace... That way you''d have better access to raw data (i.e., without having to parse text output of dtrace(1) in a shell or Python script).> Therefore what I''d like to do is be able to return an array > of objects and assign them the value "0". For example: > > @fsactivity[zfs_list()] = zero(); > > ... where "zfs_list()" would return an array of strings that > are the names of all the zfs filesystems and zero() is a > function that would be considered an aggregation friendly > function that assigned 0 to every element in fsactivity.You can create SDT (and/or USDT) if-enabled probes that gather the relevant data and make it available as probe arguments. That''s the typical answer for this sort of thing. But remember that DTrace probe context is very limited. You can''t grab locks to build a list of "the names of all the zfs filesystems" -- if you''d need to grab locks then you''d better maintain that list at runtime and keep a per-CPU copy/reference, or something along those lines.> Now I know that doing zero() is possible, and specifics of > zfs_list() aside, but is it possible to support a function > returning an array or list that is used to populate an > array in D? Can the internals of D be easily modified to > work in that fashion or would that require an extensive > rewrite?All functions that can be called in D code are provided by DTrace itself. You can''t define new functions from the host OS outside the context of DTrace itself. The limitations of DTrace context (which are purposeful, not accidental) also necessarily limit the extensibility of the language itself. If you find yourself wanting to create a variety of D functions unrelated to core DTrace functionality, then you may need to reconsider your approach. Nico --
Kaelin Colclasure
2010-Oct-16 20:20 UTC
[dtrace-discuss] Supporting the return of an array...
On Oct 15, 2010, at 4:26 PM, Nicolas Williams wrote:> You might be better off using the Java interface to DTrace... That way > you''d have better access to raw data (i.e., without having to parse text > output of dtrace(1) in a shell or Python script).This sounds intriguing? Does this also exist for the Mac OS X version of dtrace, or is it exclusive to Solaris? <http://hub.opensolaris.org/bin/view/Project+dtrace-chime/java_dtrace_api> -- Kaelin