libtracefs synthetic: Handle hashed name variables

When running:

 sqlhist -m delta -n 'wakeup' 'select start.pid, (end.TIMESTAMP_USECS - start.TIMESTAMP_USECS) as delta from sched_waking as start join sched_switch as end on start.pid = end.next_pid'

The '-m delta' is supposed to set the "onmax()" to the "delta" variable. But
this fails because the output would be:

  echo 'hist:keys=next_pid:__pid_17298_1=$__arg_17298_2,__delta_17298_4=common_timestamp.usecs-$__arg_17298_3:onmax($delta).trace(wakeup,$__pid_17298_1,$__delta_17298_4)'

As the "delta" was hashed to __delta_17298_4 and the "onmax()" has "$delta"
unhashed. In actuality, it wouldn't even get that far as the "test_max_var()"
will flag it as the variable does not exist (because it's not "delta" but
"__delta_17298_4").

Modify test_max_var() to check for hashed variables and return the one it
found.

Link: https://lore.kernel.org/linux-trace-devel/20240105052141.228999-3-rostedt@goodmis.org

Fixe: 00c6b5f6 ("libtracefs: Use unique names for sql field variables")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 file changed