Bug 7053 - automatic global printing of statistic needs to check @count>0
Summary: automatic global printing of statistic needs to check @count>0
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Wenji Huang
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-25 19:19 UTC by Frank Ch. Eigler
Modified: 2009-03-27 16:24 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
patch for checking empty aggregate and adding default print (901 bytes, patch)
2008-12-02 03:35 UTC, Wenji Huang
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Frank Ch. Eigler 2008-11-25 19:19:45 UTC
probe never {p <<< 1} global p
results in 
   ERROR: empty aggregate near identifier 'p' at <input>:1:28
but should result in
   p @count=0x0
Comment 1 Wenji Huang 2008-11-27 04:46:31 UTC
The related code in tranlate.cxx

// PR 2142+2610: empty aggregates

3757       o->newline() << "if (unlikely (" << agg.value() << " == NULL)"

3758                    << " || " <<  agg.value() << "->count == 0) {";

3759       o->newline(1) << "c->last_error = \"empty aggregate\";";

3760       o->newline() << "goto out;";

I can't reproduce 2142 and 2610 when such code is commented. Then
sensible result will be printed in the test case. Maybe some 
improvements on global were added since that commit.

Guess we can weaken the checking of empty aggregrate.

Comment 2 Frank Ch. Eigler 2008-11-27 16:32:36 UTC
If we wish to keep the status quo that @operators on empty aggregates are
erroneous, then the code to change for this bug would be elaborate.cxx's
synthesis of the printf (" @count=....@avg=..."), to fork it into one
case where @count=0 and is printed alone, and another one where @count>1
and the other @values are printed.
Comment 3 Wenji Huang 2008-12-02 03:35:28 UTC
Created attachment 3085 [details]
patch for checking empty aggregate and adding default print

Add checking empty aggregate and default print where @count==0. It's not
necessary to check empty aggregate in Array case. The generated foreach 
can eliminate the possibly of printing empty aggregate.

Sample script:
$ sudo stap -ve 'global var; probe never{ var<<<2}' -p2
Pass 1: parsed user script and 47 library script(s) in 540usr/60sys/603real ms.

# globals
var:stats
# probes
never /* <- never */
(var) <<< (2)
end /* <- end */
{
if ((@count(var)) > (0)) printf("var @count=%#x @min=%#x @max=%#x @sum=%#x
@avg=%#x\\n", @count(var), @min(var), @max(var), @sum(var), @avg(var))
else printf("var @count=0x0\\n")

}
Pass 2: analyzed script: 2 probe(s), 0 function(s), 0 embed(s), 1 global(s) in
10usr/20sys/26real ms.
Comment 4 Frank Ch. Eigler 2008-12-02 19:17:53 UTC
Nice work, plase commit with a test case.
Comment 5 Wenji Huang 2008-12-03 03:08:08 UTC
Seem commit	271d408e09e033857658c83cb722078fab02edda
Comment 6 Frank Ch. Eigler 2009-03-27 16:24:24 UTC
patch already committed