From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12891 invoked by alias); 5 Oct 2006 23:28:35 -0000 Received: (qmail 12873 invoked by uid 22791); 5 Oct 2006 23:28:34 -0000 X-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,SARE_BAYES_5x7,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e31.co.us.ibm.com (HELO e31.co.us.ibm.com) (32.97.110.149) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 05 Oct 2006 23:28:26 +0000 Received: from westrelay02.boulder.ibm.com (westrelay02.boulder.ibm.com [9.17.195.11]) by e31.co.us.ibm.com (8.13.8/8.12.11) with ESMTP id k95NSNlS016838 for ; Thu, 5 Oct 2006 19:28:23 -0400 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by westrelay02.boulder.ibm.com (8.13.6/8.13.6/NCO v8.1.1) with ESMTP id k95NSNVB530430 for ; Thu, 5 Oct 2006 17:28:23 -0600 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id k95NSNuw016489 for ; Thu, 5 Oct 2006 17:28:23 -0600 Received: from [127.0.0.1] (wecm-9-67-59-179.wecm.ibm.com [9.67.59.179]) by d03av01.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id k95NSH2I016380; Thu, 5 Oct 2006 17:28:22 -0600 Message-ID: <4525950A.8020009@us.ibm.com> Date: Thu, 05 Oct 2006 23:28:00 -0000 From: Mike Mason User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: "Frank Ch. Eigler" CC: jrs@us.ibm.com, Irfan Habib , Linux kernel , SystemTAP Subject: Re: Fwd: Any way to find the network usage by a process? References: <3420082f0610030114o5b44b8ak7797483e02002614@mail.gmail.com> <3420082f0610030114o4c6998en907bccce81d28c59@mail.gmail.com> <452285FD.7010909@us.ibm.com> <45241F7A.5050501@us.ibm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2006-q4/txt/msg00025.txt.bz2 Frank Ch. Eigler wrote: > Mike Mason writes: > >> Here's a variation of Jose's script that uses the networking tapset >> and prints top-like output for transmits and receives. [...] > > Thanks for posting it to the systemtap wiki. > > Some minor style suggestions follow: > >> [...] >> ifxmit_p[pid(), dev_name] ++ >> ifxmit_b[pid(), dev_name] += length > > These could be collapsed into a single statistics-aggregate array: > # ifxmit[pid(), dev_name] <<< length > Then the printing routine would use @count(ifxmit[...]) and @sum(ifxmit[...]) > to extract the two values. Same of course for ifrecv. I tried that and got the following output: PID UID DEV XMIT_PK RECV_PK XMIT_KB RECV_KB COMMAND 0 0 eth0 9 10 486 672 swapper ERROR: empty aggregate near identifier 'execname' at nettop.stp:35:4 WARNING: Number of errors: 1, skipped probes: 0 Apparently using @sum on empty aggregates isn't allowed. I expected 0's to be returned. The only way to avoid the error is use @sum only if @count > 0, which makes the printf too complex in my opinion. > >> execname[pid()] = execname() >> user[pid()] = uid() >> ifdevs[pid(), dev_name] = dev_name > > Calling pid() so many times is worse than calling it once and caching > the result in a local variable ("p = pid()"). Agreed. I'll change that. > > The way that the script tracks pid-to-uid and pid-to-execname mappings > is not bad, though if that part were moved to new probes on fork or > exec, it would allow the network-related probes to run concurrently on > an SMP without fighting over locks. But that would only catch processes created after the script starts, correct? - Mike > > > - FChE