* Chained numeric assignments
@ 2007-06-14 14:58 Mike Mason
2007-06-14 15:49 ` Stone, Joshua I
0 siblings, 1 reply; 3+ messages in thread
From: Mike Mason @ 2007-06-14 14:58 UTC (permalink / raw)
To: systemtap; +Cc: Eugene Teo
Should the following chained assignment:
writes[execname()] = total_io[execname()] += $return
be equivalent to:
writes[execname()] += $return
total_io[execname()] += $return
They yield different results in a couple scripts I tried (see below). For example, it appears that writes[] gets assigned total_io[] instead of += $return.
=============== Script #1 ================
global reads, writes, total_io
probe kernel.function("vfs_read").return {
reads[execname()] = total_io[execname()] += $return
}
probe kernel.function("vfs_write").return {
writes[execname()] = total_io[execname()] += $return
}
probe timer.s(1) {
foreach(p in total_io- limit 10)
printf("%15s r: %8d KiB w: %8d KiB\n",
p, reads[p]/1024,
writes[p]/1024)
printf("\n")
}
************** Script #1 Output ***********
lspci r: 455 KiB w: 456 KiB
sh r: 35 KiB w: 35 KiB
wcstatusd r: 10 KiB w: 0 KiB
Xvnc r: 8 KiB w: 8 KiB
ifconfig r: 7 KiB w: 8 KiB
mii-tool r: 4 KiB w: 4 KiB
xterm r: 4 KiB w: 4 KiB
staprun r: 0 KiB w: 0 KiB
klogd r: 0 KiB w: 0 KiB
sendmail r: 0 KiB w: 0 KiB
lspci r: 455 KiB w: 456 KiB
sh r: 35 KiB w: 35 KiB
Xvnc r: 16 KiB w: 16 KiB
wcstatusd r: 10 KiB w: 0 KiB
xterm r: 9 KiB w: 9 KiB
ifconfig r: 7 KiB w: 8 KiB
mii-tool r: 4 KiB w: 4 KiB
staprun r: 1 KiB w: 1 KiB
klogd r: 0 KiB w: 0 KiB
sendmail r: 0 KiB w: 0 KiB
============== Script #2 ==================
global reads, writes, total_io
probe kernel.function("vfs_read").return {
reads[execname()] += $return
total_io[execname()] += $return
}
probe kernel.function("vfs_write").return {
writes[execname()] += $return
total_io[execname()] += $return
}
probe timer.s(1) {
foreach(p in total_io- limit 10)
printf("%15s r: %8d KiB w: %8d KiB\n",
p, reads[p]/1024,
writes[p]/1024)
printf("\n")
}
************** Script #2 Output **************
lspci r: 449 KiB w: 6 KiB
sh r: 35 KiB w: 0 KiB
wcstatusd r: 10 KiB w: 0 KiB
ifconfig r: 7 KiB w: 0 KiB
Xvnc r: 4 KiB w: 3 KiB
xterm r: 0 KiB w: 4 KiB
mii-tool r: 4 KiB w: 0 KiB
staprun r: 0 KiB w: 0 KiB
klogd r: 0 KiB w: 0 KiB
metacity r: 0 KiB w: 0 KiB
lspci r: 898 KiB w: 13 KiB
sh r: 70 KiB w: 0 KiB
wcstatusd r: 21 KiB w: 0 KiB
ifconfig r: 15 KiB w: 1 KiB
Xvnc r: 9 KiB w: 5 KiB
xterm r: 1 KiB w: 9 KiB
mii-tool r: 9 KiB w: 0 KiB
staprun r: 0 KiB w: 0 KiB
metacity r: 0 KiB w: 0 KiB
klogd r: 0 KiB w: 0 KiB
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Chained numeric assignments
2007-06-14 14:58 Chained numeric assignments Mike Mason
@ 2007-06-14 15:49 ` Stone, Joshua I
2007-06-14 18:58 ` Mike Mason
0 siblings, 1 reply; 3+ messages in thread
From: Stone, Joshua I @ 2007-06-14 15:49 UTC (permalink / raw)
To: Mike Mason; +Cc: systemtap, Eugene Teo
Mike Mason wrote:
> Should the following chained assignment:
> writes[execname()] = total_io[execname()] += $return
> be equivalent to:
> writes[execname()] += $return total_io[execname()] += $return
Not if we mimic C's operator associativity, which is right-to-left for
assignment operators. So your statement is effectively:
writes[execname()] = ( total_io[execname()] += $return )
Or equivalent to:
total_io[execname()] += $return
writes[execname()] = total_io[execname()]
Also, if you look at the -p1 output, it will show you the explicit
associativity that was parsed. e.g.
$ stap -ue 'probe begin { a = b += c }' -p1
# parse tree dump
# file <input>
probe begin{
(a) = ((b) += (c))
}
> They yield different results in a couple scripts I tried (see below).
> For example, it appears that writes[] gets assigned total_io[] instead
> of += $return.
That's correct. But if you're seeing inconsistent results, please file
a bug and commit a testcase.
Josh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Chained numeric assignments
2007-06-14 15:49 ` Stone, Joshua I
@ 2007-06-14 18:58 ` Mike Mason
0 siblings, 0 replies; 3+ messages in thread
From: Mike Mason @ 2007-06-14 18:58 UTC (permalink / raw)
To: Stone, Joshua I; +Cc: systemtap, Eugene Teo
OK, that's what I thought, but had some doubts. Thanks for clearing it up.
Mike
Stone, Joshua I wrote:
> Mike Mason wrote:
>> Should the following chained assignment:
>> writes[execname()] = total_io[execname()] += $return
>> be equivalent to:
>> writes[execname()] += $return total_io[execname()] +=
>> $return
>
> Not if we mimic C's operator associativity, which is right-to-left for
> assignment operators. So your statement is effectively:
>
> writes[execname()] = ( total_io[execname()] += $return )
>
> Or equivalent to:
>
> total_io[execname()] += $return
> writes[execname()] = total_io[execname()]
>
> Also, if you look at the -p1 output, it will show you the explicit
> associativity that was parsed. e.g.
>
> $ stap -ue 'probe begin { a = b += c }' -p1
> # parse tree dump
> # file <input>
> probe begin{
> (a) = ((b) += (c))
> }
>
>> They yield different results in a couple scripts I tried (see below).
>> For example, it appears that writes[] gets assigned total_io[] instead
>> of += $return.
>
> That's correct. But if you're seeing inconsistent results, please file
> a bug and commit a testcase.
>
> Josh
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-06-14 18:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-14 14:58 Chained numeric assignments Mike Mason
2007-06-14 15:49 ` Stone, Joshua I
2007-06-14 18:58 ` Mike Mason
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).