Discussion:
Why can't I use stack as index to an array but I can for an aggregation?
Brian Utterback
2010-12-17 20:44:00 UTC
Permalink
I am aggregating using the stack function as the index:

@s[stack()] = count();

This works great. However, I found that in addition to how many times
each stack appears, it would also be useful to know which stacks were
called shortly before the script exited. So I thought to make an
associative array with the same indexes, and store the timestamp the
last time they were set:

ts[stack()] = timestamp;

This gives me an error:
tracing function stack( ) may not be called from a D expression (D
program context required)

Why can't I use stack as the index to an associative array when I can
use it as the index to an aggregation? Am I doing something wrong? And
if I can't use it, does anyone have a suggestion how to store the time
of the last call of each stack?
--
blu

It's bad civic hygiene to build technologies that could someday be
used to facilitate a police state. - Bruce Schneier
-----------------------------------------------------------------------|
Brian Utterback - Solaris RPE, Oracle Corporation.
Ph:603-262-3916, Em:brian.utterback-QHcLZuEGTsvQT0dZR+***@public.gmane.org
Nicolas Williams
2010-12-17 20:57:22 UTC
Permalink
Post by Brian Utterback
@s[stack()] = count();
This works great. However, I found that in addition to how many times
each stack appears, it would also be useful to know which stacks were
called shortly before the script exited. So I thought to make an
associative array with the same indexes, and store the timestamp the
ts[stack()] = timestamp;
tracing function stack( ) may not be called from a D expression (D
program context required)
Why can't I use stack as the index to an associative array when I can
use it as the index to an aggregation? Am I doing something wrong? And
if I can't use it, does anyone have a suggestion how to store the time
of the last call of each stack?
While I don't know the answer to your question, a workaround would be to
use max() as the aggregation function...

Nico
--
Adam Leventhal
2010-12-18 00:50:22 UTC
Permalink
Post by Brian Utterback
Why can't I use stack as the index to an associative array when I can
use it as the index to an aggregation? Am I doing something wrong? And
if I can't use it, does anyone have a suggestion how to store the time
of the last call of each stack?
If Bryan is monitoring this, he can provide a more authoritative answer,
but I believe the use of stack() -- normally a data recording action -- as a
key to an aggregation was a special case. The stack() action should,
perhaps, have produced an object that could then be used as a key for an
aggregation or associative array, or recorded with, say, the trace() action
(e.g. trace(stack());).

Arguably it's a bug that you can't use stack() in the way that you
described. You should feel free to file it with Oracle or in illumos.

Adam
--
Adam Leventhal, Delphix http://dtrace.org/blogs/ahl
Loading...