bpftrace
bpftrace copied to clipboard
floats
Ticket to suggest adding floats (doubles).
Eg, this should work:
# bpftrace -e 'kprobe:sys_nanosleep { printf("%.2f: sleep by %d\n", nsecs / 1000000000, tid); }'
printf: Too many arguments for format string (2 supplied, 1 expected)
@ajor / @brendangregg : Would I be correct in postulating that the only way to do this is to reimplement soft-float functions in LLVM's IRBuilder?
The logic being that BPF doesn't support floats natively, so LLVM attempts to start calling its soft-float functions (e.g. "__divdf3(...)"). That doesn't work because BPF doesn't support the calling of arbitary external functions (i.e. those not in BCC's/Linux's "helpers.h"). For much the same reason, trying to define a C/C++ function and having BPF call into it won't work either. Thus, the only option is to implement the soft-float functions in LLVM's IRBuilder. I'm given to understand that this is why "createLog2Function()" and "createStrcmpFunction()" in "bpftrace/src/ast/codegen_llvm.cpp" create their functions in the aforementioned way.
BCC has the same issue if one tries to use floats in the compiled C BPF code, so they use Python (or similar) to work with floats once the BPF code has executed. BPFtrace has no such recourse.