Discussion:
Supporting the return of an array...
Darren Reed
2010-10-15 23:08:25 UTC
Permalink
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-10-15 23:26:05 UTC
Permalink
Post by Darren Reed
At present, dtrace does not support conditional execution,
so no if's and no loops.
There's the ? : operator...
Post by Darren Reed
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).
Post by Darren Reed
Therefore what I'd like to do is be able to return an array
@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.
Post by Darren Reed
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-10-16 20:20:34 UTC
Permalink
Post by Nicolas Williams
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

Loading...