* Array handling question
@ 2015-07-20 18:15 Zoltan Kiss
2015-07-20 19:09 ` Josh Stone
2015-07-21 14:23 ` Frank Ch. Eigler
0 siblings, 2 replies; 4+ messages in thread
From: Zoltan Kiss @ 2015-07-20 18:15 UTC (permalink / raw)
To: systemtap
Hi,
I have troubles to get what I want from linetimes.stp example, so I've
decided to create my own somewhat simplified version. I'm currently
interested in the average runtime of a function after a certain number
of runs, but apparently it gives me values like 74279383992077, which is
clearly wrong. And I have a feeling I'm misunderstanding something
obvious about the array handling, but I couldn't figure out what.
Could anyone give me an advice about what am I missing?
Regards,
Zoltan Kiss
And here is my example script:
global cnt = 0;
global starttime = 0;
global runtimes;
probe process(<procname>).function(<funcname>).call {
starttime = gettimeofday_ns();
}
probe process(<procname>).function(<funcname>).return {
runtime = gettimeofday_ns() - starttime;
starttime = 0;
runtimes <<< runtime;
if (cnt > 50000) {
printf("Runtime avg: %u\n", @avg(runtimes));
delete runtimes;
cnt = 0;
}
cnt++;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Array handling question
2015-07-20 18:15 Array handling question Zoltan Kiss
@ 2015-07-20 19:09 ` Josh Stone
2015-07-21 14:23 ` Frank Ch. Eigler
1 sibling, 0 replies; 4+ messages in thread
From: Josh Stone @ 2015-07-20 19:09 UTC (permalink / raw)
To: systemtap
On 07/20/2015 11:14 AM, Zoltan Kiss wrote:
> Hi,
>
> I have troubles to get what I want from linetimes.stp example, so I've
> decided to create my own somewhat simplified version. I'm currently
> interested in the average runtime of a function after a certain number
> of runs, but apparently it gives me values like 74279383992077, which is
> clearly wrong. And I have a feeling I'm misunderstanding something
> obvious about the array handling, but I couldn't figure out what.
> Could anyone give me an advice about what am I missing?
I don't see where you are doing anything with arrays
-- do you mean stats?
> Regards,
>
> Zoltan Kiss
>
> And here is my example script:
>
> global cnt = 0;
> global starttime = 0;
These two are scalar longs.
> global runtimes;
This is a statistic value, thanks to your '<<<' assignment.
> probe process(<procname>).function(<funcname>).call {
> starttime = gettimeofday_ns();
> }
Since starttime is a scalar, this will behave badly if you ever have
multiple calls active at the same time. These could be simultaneous
from separate threads or even just recursive calls in a single thread.
So this is usually where we'd recommend at least a tid()-indexed array,
and probably another nesting index to deal with recursion. But you
don't need to write that manually; stap has @entry for this purpose.
> probe process(<procname>).function(<funcname>).return {
> runtime = gettimeofday_ns() - starttime;
> starttime = 0;
Consider this sequence with two threads, maybe from different processes:
1. Thread A reaches the .call and sets starttime.
2. Thread B reaches the .call and sets a later starttime.
3. Either thread reaches the .return, uses starttime, and sets it to 0.
4. The remaining thread reaches .return and uses gettimeofday_ns - 0.
This is nanoseconds since the Unix epoch, a large value that will skew
your @avg so much to be useless.
Recursion has a similar story, with call-A, call-B, return-B, return-A.
With @entry, you can remove your .call probe and just write:
runtime = gettimeofday(ns) - @entry(gettimeofday_ns())
That will automatically take care of multiple threads and recursion.
> runtimes <<< runtime;
> if (cnt > 50000) {
> printf("Runtime avg: %u\n", @avg(runtimes));
> delete runtimes;
> cnt = 0;
> }
> cnt++;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Array handling question
2015-07-20 18:15 Array handling question Zoltan Kiss
2015-07-20 19:09 ` Josh Stone
@ 2015-07-21 14:23 ` Frank Ch. Eigler
2015-07-31 11:45 ` Zoltan Kiss
1 sibling, 1 reply; 4+ messages in thread
From: Frank Ch. Eigler @ 2015-07-21 14:23 UTC (permalink / raw)
To: Zoltan Kiss; +Cc: systemtap
zoltan.kiss wrote:
> [...]
> global cnt = 0;
> [...]
> global runtimes;
> probe process(<procname>).function(<funcname>).return {
> [...]
> runtimes <<< runtime;
> if (cnt > 50000) {
> [...]
> delete runtimes;
> }
> cnt++;
> }
By the way, a more canonical way to count would be to drop the extra
"cnt" variable and use @count(runtimes) as the value to compare with 50000.
- FChE
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Array handling question
2015-07-21 14:23 ` Frank Ch. Eigler
@ 2015-07-31 11:45 ` Zoltan Kiss
0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Kiss @ 2015-07-31 11:45 UTC (permalink / raw)
To: Frank Ch. Eigler, Josh Stone; +Cc: systemtap
Many thanks guys, I was able to sort it out!
Though I'm not on the list, but Google pointed me in the end to Josh's
reply in the archives :)
Yes, I've mixed up stats with arrays in my mind, that was the root of
the problems.
Regards,
Zoltan
On 21/07/15 15:24, Frank Ch. Eigler wrote:
>
> zoltan.kiss wrote:
>
>> [...]
>> global cnt = 0;
>> [...]
>> global runtimes;
>> probe process(<procname>).function(<funcname>).return {
>> [...]
>> runtimes <<< runtime;
>> if (cnt > 50000) {
>> [...]
>> delete runtimes;
>> }
>> cnt++;
>> }
>
> By the way, a more canonical way to count would be to drop the extra
> "cnt" variable and use @count(runtimes) as the value to compare with 50000.
>
>
> - FChE
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-07-31 11:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-20 18:15 Array handling question Zoltan Kiss
2015-07-20 19:09 ` Josh Stone
2015-07-21 14:23 ` Frank Ch. Eigler
2015-07-31 11:45 ` Zoltan Kiss
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).