• Kalesh Singh's avatar
    tracing: Add division and multiplication support for hist triggers · bcef0441
    Kalesh Singh authored
    Adds basic support for division and multiplication operations for
    hist trigger variable expressions.
    
    For simplicity this patch only supports, division and multiplication
    for a single operation expression (e.g. x=$a/$b), as currently
    expressions are always evaluated right to left. This can lead to some
    incorrect results:
    
    	e.g. echo 'hist:keys=common_pid:x=8-4-2' >> event/trigger
    
    	     8-4-2 should evaluate to 2 i.e. (8-4)-2
    	     but currently x evaluate to  6 i.e. 8-(4-2)
    
    Multiplication and division in sub-expressions will work correctly, once
    correct operator precedence support is added (See next patch in this
    series).
    
    For the undefined case of division by 0, the histogram expression
    evaluates to (u64)(-1). Since this cannot be detected when the
    expression is created, it is the responsibility of the user to be
    aware and account for this possibility.
    
    Examples:
    	echo 'hist:keys=common_pid:a=8,b=4,x=$a/$b' \
                       >> event/trigger
    
    	echo 'hist:keys=common_pid:y=5*$b' \
                       >> event/trigger
    
    Link: https://lkml.kernel.org/r/20211025200852.3002369-3-kaleshsingh@google.comSigned-off-by: default avatarKalesh Singh <kaleshsingh@google.com>
    Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
    bcef0441
trace_events_hist.c 150 KB