1#!/usr/bin/env bcc-lua 2--[[ 3Copyright 2016 GitHub, Inc 4 5Licensed under the Apache License, Version 2.0 (the "License"); 6you may not use this file except in compliance with the License. 7You may obtain a copy of the License at 8 9http://www.apache.org/licenses/LICENSE-2.0 10 11Unless required by applicable law or agreed to in writing, software 12distributed under the License is distributed on an "AS IS" BASIS, 13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14See the License for the specific language governing permissions and 15limitations under the License. 16]] 17 18assert(arg[1], "usage: strlen_count PID") 19 20local program = string.gsub([[ 21#include <uapi/linux/ptrace.h> 22int printarg(struct pt_regs *ctx) { 23 if (!PT_REGS_PARM1(ctx)) 24 return 0; 25 u32 pid = bpf_get_current_pid_tgid(); 26 if (pid != PID) 27 return 0; 28 char str[128] = {}; 29 bpf_probe_read(&str, sizeof(str), (void *)PT_REGS_PARM1(ctx)); 30 bpf_trace_printk("strlen(\"%s\")\n", &str); 31 return 0; 32}; 33]], "PID", arg[1]) 34 35return function(BPF) 36 local b = BPF:new{text=program, debug=0} 37 b:attach_uprobe{name="c", sym="strlen", fn_name="printarg"} 38 39 local pipe = b:pipe() 40 while true do 41 local task, pid, cpu, flags, ts, msg = pipe:trace_fields() 42 print("%-18.9f %-16s %-6d %s" % {ts, task, pid, msg}) 43 end 44end 45