public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* RE: Fwd: Any way to find the network usage by a process?
@ 2006-10-06  1:08 Stone, Joshua I
  0 siblings, 0 replies; 8+ messages in thread
From: Stone, Joshua I @ 2006-10-06  1:08 UTC (permalink / raw)
  To: Frank Ch. Eigler, Mike Mason; +Cc: systemtap

On Thursday, October 05, 2006 5:00 PM, Frank Ch. Eigler wrote:
> Hi -
> 
> On Thu, Oct 05, 2006 at 04:28:10PM -0700, Mike Mason wrote:
>> [...]
>> ERROR: empty aggregate near identifier 'execname' at nettop.stp:35:4
>> WARNING: Number of errors: 1, skipped probes: 0
>> Apparently using @sum on empty aggregates isn't allowed. I expected
>> 0's to be returned.
> 
> As a judgement call, to be consistent with other extractors like @avg,
> the @sum etc. of an empty set was deemed to be undefined.

FWIW, Python allows you to take the sum of an empty list, even though
other equivalent extractors fail:

>>> sum([])
0
>>> max([])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: min() or max() arg is an empty sequence

I'm just looking for precedence in other languages...

>> The only way to avoid the error is use @sum only if @count >
>> 0, which makes the printf too complex in my opinion.
> 
> Maybe so.  It's worth considering some syntactic sugar to express a
> undefined=>0 intent.

One possibility is an optional second parameter to the extractor that
gives a default value.  We could require this to be a constant (usually
0), or maybe even allow a numeric expression.

	a <<< 1; del a // prepare an empty aggregate
	printf("%d\n", @sum(a)) // runtime error
	printf("%d\n", @sum(a, 0)) // prints 0
	printf("%d\n", @sum(a, x)) // prints value of x

This works for min, max, and avg as well.

Or, instead of a default, it might be less confusing to consider the
second parameter as an initializer -- so when 'a' isn't empty, @sum(a,x)
== x + @sum(a).  Then min and max would effectively get an upper and
lower bound, respectively.  I'm not sure if avg works well this way
though.


Josh

^ permalink raw reply	[flat|nested] 8+ messages in thread
[parent not found: <3420082f0610030114o5b44b8ak7797483e02002614@mail.gmail.com>]

end of thread, other threads:[~2006-10-06 15:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-06  1:08 Fwd: Any way to find the network usage by a process? Stone, Joshua I
     [not found] <3420082f0610030114o5b44b8ak7797483e02002614@mail.gmail.com>
     [not found] ` <3420082f0610030114o4c6998en907bccce81d28c59@mail.gmail.com>
2006-10-03 15:49   ` Jose R. Santos
2006-10-04 20:54     ` Mike Mason
2006-10-05 21:22       ` Frank Ch. Eigler
2006-10-05 23:28         ` Mike Mason
2006-10-06  0:00           ` Frank Ch. Eigler
2006-10-06  1:10             ` Mike Mason
2006-10-06 15:30               ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).