* [PATCH 1/2] Add the speculative.stp tapset @ 2011-12-17 2:14 William Cohen 2011-12-17 14:27 ` [PATCH 2/2] Add a test for " William Cohen 0 siblings, 1 reply; 2+ messages in thread From: William Cohen @ 2011-12-17 2:14 UTC (permalink / raw) To: systemtap; +Cc: William Cohen 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 <wcohen@redhat.com> --- 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 </chapter> + + <chapter id="speculation.stp"> + <title>Speculation</title> + <para> + 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. + </para> +!Itapset/speculative.stp + </chapter> </book> 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 ^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] Add a test for the speculative.stp tapset 2011-12-17 2:14 [PATCH 1/2] Add the speculative.stp tapset William Cohen @ 2011-12-17 14:27 ` William Cohen 0 siblings, 0 replies; 2+ messages in thread From: William Cohen @ 2011-12-17 14:27 UTC (permalink / raw) To: systemtap; +Cc: William Cohen A simple test to make sure that the speculative.stp tapset can be compiled and used. Signed-off-by: William Cohen <wcohen@redhat.com> --- testsuite/systemtap.speculate/speculate.c | 34 ++++++++++++++++++++ testsuite/systemtap.speculate/speculate.exp | 27 ++++++++++++++++ testsuite/systemtap.speculate/speculate.stp | 44 +++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 testsuite/systemtap.speculate/speculate.c create mode 100644 testsuite/systemtap.speculate/speculate.exp create mode 100644 testsuite/systemtap.speculate/speculate.stp diff --git a/testsuite/systemtap.speculate/speculate.c b/testsuite/systemtap.speculate/speculate.c new file mode 100644 index 0000000..6eadec1 --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.c @@ -0,0 +1,34 @@ +/* program to exercise spec_example.stp */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define BOGUS NULL +#define MAXSIZE 512 +static char buf1[MAXSIZE]; +static char buf2[MAXSIZE]; + +main (int argc, char ** argv) +{ + int fbad = open("/tmp/junky_bad", O_CREAT|O_RDWR, 0660); + int fokay = open("/tmp/junky_good", O_CREAT|O_RDWR, 0660); + + if (fbad < 0) return(EXIT_FAILURE); + if (fokay < 0) return(EXIT_FAILURE); + + write(fokay, buf1, MAXSIZE); + write(fokay, buf1, MAXSIZE); + write(fbad, buf2, MAXSIZE); + write(fokay, buf2, MAXSIZE); + write(fokay, buf1, MAXSIZE); + write(fbad, buf1, MAXSIZE); + write(fbad, BOGUS, MAXSIZE); + write(fokay, buf1, MAXSIZE); + + return(EXIT_SUCCESS); +} diff --git a/testsuite/systemtap.speculate/speculate.exp b/testsuite/systemtap.speculate/speculate.exp new file mode 100644 index 0000000..8e484bb --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.exp @@ -0,0 +1,27 @@ +set test speculate + +catch {exec gcc -g -o $test $srcdir/$subdir/$test.c} err +if {$err == "" && [file exists $test]} then { pass "$test compile" } else { fail "$test compile" } + +set rc [stap_run_batch $srcdir/$subdir/$test.stp] +if {$rc == 0} then { pass "$test -p4" } else { fail "$test -p4" } + +if {! [installtest_p]} { + catch {exec rm -f $test} + untested "$test -p5" + return +} + +spawn stap $srcdir/$subdir/$test.stp -c ./$test +set ok 0 +expect { + -timeout 60 + -re {^open[^\r\n]*\r\n} { incr ok; exp_continue } + -re {^write[^\r\n]*\r\n} { incr ok; exp_continue } + timeout { fail "$test (timeout)" } + eof { } +} +catch { close } +wait +if {$ok == 4} then { pass "$test -p5" } else { fail "$test -p5 ($ok)" } +exec rm -f $test diff --git a/testsuite/systemtap.speculate/speculate.stp b/testsuite/systemtap.speculate/speculate.stp new file mode 100644 index 0000000..c2ba229 --- /dev/null +++ b/testsuite/systemtap.speculate/speculate.stp @@ -0,0 +1,44 @@ +#! stap -p4 + +# test to exercise the speculative.stp tapset +# shows file operations for a file that later had a read or write problem. + +global file_desc + +probe syscall.open.return +{ + if (pid() != target()) next + file_desc[$return] = speculation() + speculate(file_desc[$return], sprintf("open(%s) = %d\n", + user_string($filename), $return)) +} + +probe syscall.close.return +{ + if (pid() != target()) next + if (! ($fd in file_desc)) next + + if ($return < 0) + commit(file_desc[$fd]) + else + discard(file_desc[$fd]) + delete file_desc[$fd] +} + +probe syscall.read.return { + if (pid() != target()) next + if (! ($fd in file_desc)) next + + speculate(file_desc[$fd], sprintf("read(%d, %p, %d) = %d\n", + $fd, $buf, $count, $return)) + if ($return < 0) commit(file_desc[$fd]) +} + +probe syscall.write.return { + if (pid() != target()) next + if (! ($fd in file_desc)) next + + speculate(file_desc[$fd], sprintf("write(%d, %p, %d) = %d\n", + $fd, $buf, $count, $return)) + if ($return < 0) commit(file_desc[$fd]) +} -- 1.7.1 ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-17 2:14 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-12-17 2:14 [PATCH 1/2] Add the speculative.stp tapset William Cohen 2011-12-17 14:27 ` [PATCH 2/2] Add a test for " William Cohen
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).