This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: problem in tuning mysql code use systemtap
On Sat, Mar 24, 2012 at 03:01:59PM +0800, ch huang wrote:
> function __get_sql:string (thd:long){
> my_sql = thd
> ? (@defined(@cast(thd, "THD")->query_string)
> ? @cast(thd, "THD")->query_string
> : "NOTHING")
> : "NO Thread"
> return my_sql
> }
>
> probe process("/usr/sbin/mysqld").function("mysql_execute_command").return {
> myh = __get_sql($thd)
> printf(" %p : %s \n",$thd,myh)
> }
>
> compile is fine,but output is not expected ,why?
>
> 0x1537a460 : NOTHING
This is because @cast defaults to the "kernel" for none probe contexts.
function __get_sql isn't a probe context and so @cast doesn't know
where you want the cast from. You can try telling it explicitly, with
@cast(thd, "THD", "/usr/sbin/mysqld")->query_string
See http://sourceware.org/systemtap/langref/Language_elements.html#SECTION000661100000000000000
Cheers,
Mark