Commit 7601b4b3 authored by Vicent Marti's avatar Vicent Marti

bcc: Allow the runner to parse some arguments

parent 8f412d28
......@@ -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")
......@@ -14,11 +14,51 @@ 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"),
......@@ -26,7 +66,6 @@ return function()
sym = BCC.sym
}
local tracefile = table.remove(arg, 1)
local command = dofile(tracefile)
local res, err = pcall(command, BPF, utils)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment