From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57103 invoked by alias); 20 Jul 2015 19:09:49 -0000 Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org Received: (qmail 57085 invoked by uid 89); 20 Jul 2015 19:09:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 20 Jul 2015 19:09:47 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id ABAC18F23D for ; Mon, 20 Jul 2015 19:09:46 +0000 (UTC) Received: from [10.3.113.84] (ovpn-113-84.phx2.redhat.com [10.3.113.84]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6KJ9kI3011560 for ; Mon, 20 Jul 2015 15:09:46 -0400 Subject: Re: Array handling question To: systemtap@sourceware.org References: <55AD3A9F.4030703@linaro.org> From: Josh Stone Message-ID: <55AD477A.9000205@redhat.com> Date: Mon, 20 Jul 2015 19:09:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <55AD3A9F.4030703@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-q3/txt/msg00043.txt.bz2 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().function().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().function().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++; > }