diff options
author | Dave Brolley <brolley@redhat.com> | 2009-06-18 11:46:45 -0400 |
---|---|---|
committer | Dave Brolley <brolley@redhat.com> | 2009-06-18 11:46:45 -0400 |
commit | d729143af5242b17645d3f405141918940680894 (patch) | |
tree | 165520a77b1b53b83284d115ec62b77679e28f42 | |
parent | 8f222481f9c010f4c3d8060726234dbb779ce77f (diff) | |
parent | 76248b8b52d687abb52c5e69eda7927f84d2e483 (diff) | |
download | systemtap-steved-d729143af5242b17645d3f405141918940680894.tar.gz systemtap-steved-d729143af5242b17645d3f405141918940680894.tar.xz systemtap-steved-d729143af5242b17645d3f405141918940680894.zip |
Merge branch 'master' of git://sources.redhat.com/git/systemtap
-rw-r--r-- | doc/langref.tex | 4 | ||||
-rw-r--r-- | includes/sys/sdt.h | 8 | ||||
-rw-r--r-- | stapfuncs.3stap.in | 6 | ||||
-rw-r--r-- | tapset/string.stp | 23 | ||||
-rw-r--r-- | testsuite/systemtap.base/flightrec3.exp | 22 | ||||
-rw-r--r-- | testsuite/systemtap.string/tokenize.exp | 19 | ||||
-rw-r--r-- | testsuite/systemtap.string/tokenize.stp | 54 |
7 files changed, 72 insertions, 64 deletions
diff --git a/doc/langref.tex b/doc/langref.tex index 5aefa278..5a149d19 100644 --- a/doc/langref.tex +++ b/doc/langref.tex @@ -3160,8 +3160,8 @@ General syntax: tokenize:string (input:string, delim:string) \end{verbatim} \end{vindent} -This function returns the next token in the given input string, where -the tokens are delimited by one of the characters in the delim string. +This function returns the next non-empty token in the given input string, +where the tokens are delimited by characters in the delim string. If the input string is non-NULL, it returns the first token. If the input string is NULL, it returns the next token in the string passed in the previous call to tokenize. If no delimiter is found, the entire remaining input string diff --git a/includes/sys/sdt.h b/includes/sys/sdt.h index 10639d9c..0f86cc3b 100644 --- a/includes/sys/sdt.h +++ b/includes/sys/sdt.h @@ -257,10 +257,10 @@ do { \ syscall (STAP_SYSCALL, #probe, GETTID); \ } while (0) -#define STAP_PROBE1_(probe,label,parm1) \ -do { \ - STAP_PROBE_DATA(probe,STAP_GUARD,1); \ - syscall (STAP_SYSCALL, #probe, GETTID, parm1); \ +#define STAP_PROBE1_(probe,label,parm1) \ +do { \ + STAP_PROBE_DATA(probe,STAP_GUARD,1); \ + syscall (STAP_SYSCALL, #probe, GETTID, (size_t)parm1); \ } while (0) #define STAP_PROBE2_(probe,label,parm1,parm2) \ diff --git a/stapfuncs.3stap.in b/stapfuncs.3stap.in index 518ff2bb..3d88b2ea 100644 --- a/stapfuncs.3stap.in +++ b/stapfuncs.3stap.in @@ -166,11 +166,11 @@ specified by base. For example, strtol("1000", 16) returns 4096. Returns 0 if string cannot be converted. .TP tokenize:string (str:string, delim:string) -Return the next token in the given str string, where the tokens are delimited -by one of the characters in the delim string. If the str string is not blank, +Return the next non-empty token in the given str string, where the tokens are +delimited by characters in the delim string. If the str string is not blank, it returns the first token. If the str string is blank, it returns the next token in the string passed in the previous call to tokenize. If no delimiter -is found, the entire remaining str string is returned. Returns blank when +is found, the entire remaining str string is returned. Returns blank when no more tokens are left. .SS TIMESTAMP diff --git a/tapset/string.stp b/tapset/string.stp index 35ee9fa2..cc842929 100644 --- a/tapset/string.stp +++ b/tapset/string.stp @@ -70,25 +70,32 @@ function text_strn:string(input:string, len:long, quoted:long) /* * tokenize - Given a string and a token delimiter, - * return the next token in the string - * input String to tokenize. If NULL, returns the next token in the - * string passed in the previous call to tokenize(). - * delim Token delimiter. Note this is a string, but only the first - * character is used as the delimiter. + * return the next non-empty token in the string + * or blank when no more non-empty tokens are left + * input String to tokenize. If NULL, returns the next non-empty token + * in the string passed in the previous call to tokenize(). + * delim Token delimiter. Set of characters that delimit the tokens. */ function tokenize:string(input:string, delim:string) %{ /* pure */ static char str[MAXSTRINGLEN]; static char *str_start; + static char *str_end; char *token = NULL; + char *token_end = NULL; if (THIS->input[0]) { strncpy(str, THIS->input, MAXSTRINGLEN); str_start = &str[0]; + str_end = &str[0] + strlen(str); + } + do { + token = strsep(&str_start, THIS->delim); + } while (token && !token[0]); + if (token) { + token_end = (str_start ? str_start - 1 : str_end); + memcpy(THIS->__retvalue, token, token_end - token + 1); } - token = strsep(&str_start, THIS->delim); - if (token) - strncpy (THIS->__retvalue, token, MAXSTRINGLEN); %} /* diff --git a/testsuite/systemtap.base/flightrec3.exp b/testsuite/systemtap.base/flightrec3.exp index 5b9d8253..3799c6a6 100644 --- a/testsuite/systemtap.base/flightrec3.exp +++ b/testsuite/systemtap.base/flightrec3.exp @@ -6,7 +6,7 @@ system "rm -f flightlog.out*" set pid 0 # check -S option with bulk(percpu file) mode -spawn stap -F -o flightlog.out -S 1,3 -b $srcdir/$subdir/$test.stp +catch {spawn stap -F -o flightlog.out -S 1,3 -b $srcdir/$subdir/$test.stp} expect { -timeout 240 -re {([0-9]+)\r\n} { @@ -26,9 +26,9 @@ exec sleep 4 array set cpus {} set scnt 0 # wait for log files -exec kill -STOP $pid +catch {exec kill -STOP $pid} exec sleep 1 -eval spawn stat -c \"%n %s\" [glob flightlog.out_cpu*] +catch {eval spawn stat -c \"%n %s\" [glob -nocomplain flightlog.out_cpu*]} expect { -timeout 100 -re {flightlog.out_cpu([0-9]+).[0-9]+ ([0-9]+)\r\n} { @@ -41,10 +41,10 @@ expect { timeout { fail "$test (logfile timeout)"} } wait -exec kill -CONT $pid +catch {exec kill -CONT $pid} exec sleep 3 -exec kill -STOP $pid -eval spawn stat -c \"%n %s\" [glob flightlog.out_cpu*] +catch {exec kill -STOP $pid} +catch {eval spawn stat -c \"%n %s\" [glob -nocomplain flightlog.out_cpu*]} expect { -timeout 100 -re {flightlog.out_cpu([0-9]+).[0-9]+ ([0-9]+)\r\n} { @@ -57,11 +57,13 @@ expect { timeout { fail "$test (logfile timeout)"} } wait -exec kill -CONT $pid +catch {exec kill -CONT $pid} # check logfile number set cnt 0 foreach e [array names cpus] { - if {$cpus($e) != 6} { + # If we have more than 6 files per cpu, something is wrong. We + # might have less than 6 files per cpu if the machine is slow. + if {$cpus($e) > 6} { fail "$test (log file numbers cpu:$e, cnt:$cpus($e)))" } set cnt [expr $cnt + $cpus($e)] @@ -72,8 +74,8 @@ if {$scnt == $cnt} { } else { fail "$test (log file size ($scnt != $cnt))" } -exec kill -TERM $pid +catch {exec kill -TERM $pid} # wait for exiting... exec sleep 1 -system "rm -f flightlog.out*" +catch {system "rm -f flightlog.out*"} diff --git a/testsuite/systemtap.string/tokenize.exp b/testsuite/systemtap.string/tokenize.exp index 697b7c7e..d32868cf 100644 --- a/testsuite/systemtap.string/tokenize.exp +++ b/testsuite/systemtap.string/tokenize.exp @@ -1,5 +1,6 @@ set test "tokenize" -set ::result_string {one +set ::result_string {- +one two three four @@ -9,7 +10,9 @@ seven eight nine ten +- one|two|three|four|five|six|seven|eight|nine|ten +- a b c @@ -17,10 +20,22 @@ d e f g +- 1 2 3 4 -this is a string with no delimiters} +- +- +this is a string with no delimiters +- +this +is +a +string +which +has +two +delimiters} stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.string/tokenize.stp b/testsuite/systemtap.string/tokenize.stp index 10703d90..ba95f63f 100644 --- a/testsuite/systemtap.string/tokenize.stp +++ b/testsuite/systemtap.string/tokenize.stp @@ -1,3 +1,14 @@ +function tokprint(str, delim) +{ + println("-") + + tok = tokenize(str, delim) + while (tok != "") { + println(tok) + tok = tokenize("", delim) + } +} + probe begin { teststr1 = "one|two|three|four|five|six|seven|eight|nine|ten" @@ -5,42 +16,15 @@ probe begin teststr3 = "1,,2,3, ,4" teststr4 = "" teststr5 = "this is a string with no delimiters" + teststr6 = "this is a string, which has two delimiters" - tok = tokenize(teststr1, "|") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", "|") - } - - tok = tokenize(teststr1, ",") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", "|") - } - - tok = tokenize(teststr2, ",") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", ",") - } - - tok = tokenize(teststr3, ",") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", ",") - } - - tok = tokenize(teststr4, ",") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", ",") - } - - tok = tokenize(teststr5, ",") - while (tok != "") { - printf("%s\n", tok) - tok = tokenize("", ",") - } + tokprint(teststr1, "|") + tokprint(teststr1, ",") + tokprint(teststr2, ",") + tokprint(teststr3, ",") + tokprint(teststr4, ",") + tokprint(teststr5, ",") + tokprint(teststr6, ", ") exit() } |