From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6346 invoked by alias); 17 Dec 2011 02:14:15 -0000 Received: (qmail 6334 invoked by uid 22791); 17 Dec 2011 02:14:14 -0000 X-SWARE-Spam-Status: No, hits=4.8 required=5.0 tests=BAYES_00,BOTNET,NO_DNS_FOR_FROM,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC,TO_NO_BRKTS_DYNIP X-Spam-Check-By: sourceware.org Received: from cpe-071-070-225-064.nc.res.rr.com (HELO localhost.localdomain) (71.70.225.64) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 17 Dec 2011 02:13:59 +0000 Received: from localhost.localdomain (cannondale [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.4) with ESMTP id pBGJpqKs021366; Fri, 16 Dec 2011 14:51:52 -0500 Received: (from wcohen@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) id pBGJpqHk021364; Fri, 16 Dec 2011 14:51:52 -0500 From: William Cohen To: systemtap@sourceware.org Cc: William Cohen Subject: [PATCH 1/2] Add the speculative.stp tapset Date: Sat, 17 Dec 2011 02:14:00 -0000 Message-Id: <1324065101-21332-1-git-send-email-wcohen@redhat.com> X-IsSubscribed: yes 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 X-SW-Source: 2011-q4/txt/msg00385.txt.bz2 The speculative.stp tapset allow one to speculative add things to output buffers and then later commit or discard the information in the buffers. Four functions in the tapset: speculation() - function to give an id for speculative buffer speculate() - add output to a speculative buffer discard() - remove output for a speculative buffer commit() - output data for a speculative buffer Signed-off-by: William Cohen --- doc/SystemTap_Tapset_Reference/tapsets.tmpl | 10 +++ tapset/speculative.stp | 80 +++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 0 deletions(-) create mode 100644 tapset/speculative.stp diff --git a/doc/SystemTap_Tapset_Reference/tapsets.tmpl b/doc/SystemTap_Tapset_Reference/tapsets.tmpl index 685c733..dd78a4e 100644 --- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl +++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl @@ -389,4 +389,14 @@ !Itapset/nfsd.stp !Itapset/nfsderrno.stp + + + Speculation + + This family of functions provides the ability to speculative record + information and then at a later point in the SystemTap script either + commit the information or discard it. + +!Itapset/speculative.stp + diff --git a/tapset/speculative.stp b/tapset/speculative.stp new file mode 100644 index 0000000..4338672 --- /dev/null +++ b/tapset/speculative.stp @@ -0,0 +1,80 @@ +// Speculative tapset +// Copyright (C) 2011 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. + +global _spec_id +global _spec_counter +global _spec_buff +global _spec_discard + +/** + * sfunction speculation - Allocate a new id for speculative output + * + * The speculation() function is called when a new speculation buffer is needed. + * It returns an id for the speculative output. + * There can be multiple threads being speculated on concurrently. + * This id is used by other speculation fuctions to keep the threads + * separate. + */ +function speculation:long () +{ + _spec_id += 1 + return _spec_id +} + + +/** + * sfunction speculate - Store a string for possible output later + * @id: buffer id to store the information in + * @output: string to write out when commit occurs + * + * Add a string to the speculaive buffer for id. + */ +function speculate (id:long, output:string) +{ + _spec_counter[id] += 1 + _spec_buff[id, _spec_counter[id]] = output +} + + +function _spec_erase (id:long) { + foreach([i, counter] in _spec_discard) + delete _spec_buff[i, counter] + delete _spec_discard +} + + +/** + * sfunction discard - Discard all output related to a speculation buffer + * @id: of the buffer to store the information in + * + */ +function discard (id:long) +{ + foreach([i, counter] in _spec_buff) + if (i==id) _spec_discard[i, counter] = 1 + _spec_erase (id) +} + + +/** + * sfunction commit - Write out all output related to a speculation buffer + * @id: of the buffer to store the information in + * + * Output all the output for @id in the order that it was entered into + * the speculative buffer by speculative(). + */ +function commit (id:long) +{ + foreach([i, counter+] in _spec_buff) { + if (i==id) { + printf("%s", _spec_buff[i, counter]) + _spec_discard[i, counter] = 1 + } + } + _spec_erase (id) +} -- 1.7.1