public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* How to use tokenize
@ 2012-10-05 17:27 domenico.dileo
  2012-10-06  2:20 ` Frank Ch. Eigler
  0 siblings, 1 reply; 2+ messages in thread
From: domenico.dileo @ 2012-10-05 17:27 UTC (permalink / raw)
  To: systemtap

Hello,
I want to split the string returned by backtrace with tokenize.
Thus, I wrote the following code

function print_stacktrace(subsystem, when){
		#stacktrace is invoked either function
		# (probe) is called or when it is returning
		# when can assume 2 values:
		# c, call (stacktrace when function is called)
		# r, return (stacktrace when function returns)
		trace = backtrace()
		printf("%s \n", probefunc())
		while(strlen(address = tokenize(trace," ")) != 0){
		     printf("%s  \n", address)
		}
}
probe kernel.function("*@mm/*.c").call{
	print_stacktrace("MM", "c")
}
probe kernel.function("*@mm/*.c").return{
	print_stacktrace("MM", "r")
}

The output is something like
dnotify
0xc011698
0xc011698
0xc011698

...
0xc011698

It seems that the script gets stuck in the while loop.
in other words, at the first iterations tokenize returns
0xc011698 this value is assigned to address.
To the second iteration tokenize doesn't return a value
and address is still equal to the previous value.

I know that in stap there are function like "print_stack",
I don't need them because I have to submit the stack
trace to other elaborations.



Domenico Di Leo, PhD student, Universit? degli Studi di Napoli Federico II
Ph:     +39 081 676770
Fax:    +39 081 676574
Web: http://wpage.unina.it/domenico.dileo

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to use tokenize
  2012-10-05 17:27 How to use tokenize domenico.dileo
@ 2012-10-06  2:20 ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2012-10-06  2:20 UTC (permalink / raw)
  To: domenico.dileo; +Cc: systemtap


Hi -

domenico.dileo@unina.it writes:

> [...]
> 		printf("%s \n", probefunc())
> 		while(strlen(address = tokenize(trace," ")) != 0){
> 		     printf("%s  \n", address)
> [...]
> The output is something like
> dnotify
> 0xc011698
> 0xc011698
> [...]
> It seems that the script gets stuck in the while loop.

Yes.  This would work better:

> 		address = tokenize(trace," ")
> 		while(address != "") {
> 		     printf("%s  \n", address)
> 		     address = tokenize(""," ")
> 		}

Note how, within the loop, the first parameter of tokenize() is empty,
so as to resume the previously started tokenization.  (This is hack to
work around the systemtap language's inability to treat an entire
array as a function return value.)



> I know that in stap there are function like "print_stack",
> I don't need them because I have to submit the stack
> trace to other elaborations.

You may like the new backtrace-enumeration functions smakarov 
added in time for systemtap 2.0.  They should make this tokenize
business purely historical.

- FChE

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-06  2:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-05 17:27 How to use tokenize domenico.dileo
2012-10-06  2:20 ` Frank Ch. Eigler

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).