* What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
@ 2015-11-26 3:47 Nan Xiao
2015-11-26 19:56 ` Frank Ch. Eigler
0 siblings, 1 reply; 4+ messages in thread
From: Nan Xiao @ 2015-11-26 3:47 UTC (permalink / raw)
To: systemtap
Hi all,
From the "foreach" section in SystemTap
doc(https://sourceware.org/systemtap/langref/Statement_types.html#SECTION00076000000000000000),
I can see there is a foreach usage:
foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT
But execute the following script generate errors:
# cat test.stp
#!/usr/bin/stap
global reads
probe vfs.read
{
reads[pid(), execname()]++
}
probe timer.s(3)
{
foreach (var = [pid, name] in reads)
printf("%d\n", reads[var]);
exit()
}
# ./test.stp
semantic error: inconsistent arity (2 vs 1): identifier 'reads' at
./test.stp:13:18
source: printf("%d\n", reads[var]);
^
semantic error: arity 2 first inferred here: identifier 'reads' at :7:2
source: reads[pid(), execname()]++
^
Pass 2: analysis failed. [man error::pass2]
What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in
ARRAY) STMT"? How to use it?
Thanks in advance!
Best Regards
Nan Xiao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
2015-11-26 3:47 What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"? Nan Xiao
@ 2015-11-26 19:56 ` Frank Ch. Eigler
2015-11-27 2:23 ` Nan Xiao
0 siblings, 1 reply; 4+ messages in thread
From: Frank Ch. Eigler @ 2015-11-26 19:56 UTC (permalink / raw)
To: Nan Xiao; +Cc: systemtap
xiaonan830818 wrote:
> [...]
> I can see there is a foreach usage:
> foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT
See [man stap]. This syntax is for automatically fetching
the ARRAY[VAR1,VAR2,...] value into a VALUE variable, so:
> But execute the following script generate errors:
> [...]
> probe timer.s(3)
> {
> foreach (var = [pid, name] in reads)
> printf("%d\n", reads[var]);
... would be correctly written as
> printf("%d\n", var)
- FChE
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
2015-11-26 19:56 ` Frank Ch. Eigler
@ 2015-11-27 2:23 ` Nan Xiao
2015-11-27 2:30 ` Nan Xiao
0 siblings, 1 reply; 4+ messages in thread
From: Nan Xiao @ 2015-11-27 2:23 UTC (permalink / raw)
To: Frank Ch. Eigler; +Cc: systemtap
Hi Frank,
Yeah, it works! Thanks very much for your help!
Best Regards
Nan Xiao
On Fri, Nov 27, 2015 at 3:56 AM, Frank Ch. Eigler <fche@redhat.com> wrote:
>
> xiaonan830818 wrote:
>
>> [...]
>> I can see there is a foreach usage:
>> foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT
>
> See [man stap]. This syntax is for automatically fetching
> the ARRAY[VAR1,VAR2,...] value into a VALUE variable, so:
>
>> But execute the following script generate errors:
>> [...]
>> probe timer.s(3)
>> {
>> foreach (var = [pid, name] in reads)
>> printf("%d\n", reads[var]);
>
> ... would be correctly written as
>
>> printf("%d\n", var)
>
>
> - FChE
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"?
2015-11-27 2:23 ` Nan Xiao
@ 2015-11-27 2:30 ` Nan Xiao
0 siblings, 0 replies; 4+ messages in thread
From: Nan Xiao @ 2015-11-27 2:30 UTC (permalink / raw)
To: Frank Ch. Eigler; +Cc: systemtap
Hi Frank,
BTW, I think in this
page(https://sourceware.org/systemtap/langref/Statement_types.html#SECTION00076000000000000000),
use
foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT (man stap)
is better and more understandable than
foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT
Thanks!
Best Regards
Nan Xiao
On Fri, Nov 27, 2015 at 10:23 AM, Nan Xiao <xiaonan830818@gmail.com> wrote:
> Hi Frank,
>
> Yeah, it works! Thanks very much for your help!
> Best Regards
> Nan Xiao
>
>
> On Fri, Nov 27, 2015 at 3:56 AM, Frank Ch. Eigler <fche@redhat.com> wrote:
>>
>> xiaonan830818 wrote:
>>
>>> [...]
>>> I can see there is a foreach usage:
>>> foreach (VALUE = [VAR1, VAR2, ...] in ARRAY) STMT
>>
>> See [man stap]. This syntax is for automatically fetching
>> the ARRAY[VAR1,VAR2,...] value into a VALUE variable, so:
>>
>>> But execute the following script generate errors:
>>> [...]
>>> probe timer.s(3)
>>> {
>>> foreach (var = [pid, name] in reads)
>>> printf("%d\n", reads[var]);
>>
>> ... would be correctly written as
>>
>>> printf("%d\n", var)
>>
>>
>> - FChE
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-11-27 2:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-26 3:47 What is the function of "VAR" in "foreach (VAR = [VAR1, VAR2, ...] in ARRAY) STMT"? Nan Xiao
2015-11-26 19:56 ` Frank Ch. Eigler
2015-11-27 2:23 ` Nan Xiao
2015-11-27 2:30 ` Nan Xiao
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).