Skip to content

Commit

Permalink
bcc: Allow the runner to parse some arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmg committed Apr 1, 2016
1 parent 8f412d2 commit 7601b4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lua/bcc/libbcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ int perf_reader_fd(struct perf_reader *reader);
void perf_reader_set_fd(struct perf_reader *reader, int fd);
]]

return ffi.load(rawget(_G, "LIBBCC_SO_PATH") or "bcc")
return ffi.load(os.getenv("LIBBCC_SO_PATH") or rawget(_G, "LIBBCC_SO_PATH") or "bcc")
43 changes: 41 additions & 2 deletions src/lua/bcc/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,58 @@ See the License for the specific language governing permissions and
limitations under the License.
]]

local function print_usage()
io.stderr:write(
"usage: bcc-probe [[--so-path=PATH|--version|--quiet] --] path_to_script.lua [...]\n")
os.exit(1)
end

local function has_prefix(s,p)
return string.sub(s,1,string.len(p))==p
end

local function strip_prefix(s,p)
return string.sub(s, string.len(p) + 1)
end

return function()
local logging = true

while arg[1] and has_prefix(arg[1], "-") do
local k = table.remove(arg, 1)

if k == "--" then
break
elseif has_prefix(k, "--so-path=") then
rawset(_G, "LIBBCC_SO_PATH", strip_prefix(k, "--so-path="))
elseif k == "-q" or k == "--quiet" then
logging = false
elseif k == "-v" or k == "--version" then
local jit = require("jit")
print(string.format("bcc-probe %s -- Running on %s (%s/%s)",
rawget(_G, "BCC_VERSION") or "HEAD",
jit.version, jit.os, jit.arch))
return true
else
print_usage()
end
end

local tracefile = table.remove(arg, 1)
if not tracefile then print_usage() end

local BCC = require("bcc.init")
local BPF = BCC.BPF

BPF.script_root(arg[1])
BPF.script_root(tracefile)
log.enabled = logging

local utils = {
argparse = require("bcc.vendor.argparse"),
posix = require("bcc.vendor.posix"),
sym = BCC.sym
}

local tracefile = table.remove(arg, 1)
local command = dofile(tracefile)
local res, err = pcall(command, BPF, utils)

Expand Down

0 comments on commit 7601b4b

Please sign in to comment.