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
18local program = [[
19#include <uapi/linux/ptrace.h>
20int trace_method(struct pt_regs *ctx) {
21  uint64_t addr;
22  bpf_usdt_readarg(2, ctx, &addr);
23
24  char fn_name[128] = {};
25  bpf_probe_read(&fn_name, sizeof(fn_name), (void *)addr);
26
27  bpf_trace_printk("%s(...)\n", fn_name);
28  return 0;
29};
30]]
31
32return function(BPF, util)
33  if not arg[1] then
34    print("usage: rubysyms.lua PID")
35    return
36  end
37
38  local u = util.USDT:new{pid=tonumber(arg[1])}
39  u:enable_probe{probe="method__entry", fn_name="trace_method"}
40
41  local b = BPF:new{text=program, usdt=u}
42  local pipe = b:pipe()
43  while true do
44    print(pipe:trace_fields())
45  end
46end
47