Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
28981655
Commit
28981655
authored
Apr 01, 2016
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bcc: Move all `argv` parsing to Lua code
parent
7601b4b3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
66 deletions
+49
-66
src/lua/bcc-probe
src/lua/bcc-probe
+1
-1
src/lua/bcc/run.lua
src/lua/bcc/run.lua
+26
-30
src/lua/bcc/vendor/helpers.lua
src/lua/bcc/vendor/helpers.lua
+8
-4
src/lua/src/main.c
src/lua/src/main.c
+14
-31
No files found.
src/lua/bcc-probe
View file @
28981655
...
...
@@ -17,5 +17,5 @@ limitations under the License.
local str = require("debug").getinfo(1, "S").source:sub(2)
local script_path = str:match("(.*/)").."/?.lua;"
package.path = script_path..package.path
rawset(_G, "BCC_STANDALONE
", false
)
rawset(_G, "BCC_STANDALONE
_NAME", "bcc-probe"
)
require("bcc.run")()
src/lua/bcc/run.lua
View file @
28981655
...
...
@@ -14,38 +14,37 @@ 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
require
(
"bcc.vendor.helpers"
)
local
progname
=
rawget
(
_G
,
"BCC_STANDALONE_NAME"
)
or
"bcc-lua"
local
function
print_usage
()
io.stderr
:
write
(
string.format
(
"usage: %s [[--so-path=PATH|--version|--quiet] --] path_to_script.lua [...]\n"
,
progname
))
os.exit
(
1
)
end
while
arg
[
1
]
and
has_prefix
(
arg
[
1
],
"-"
)
do
local
k
=
table.remove
(
arg
,
1
)
local
function
print_version
()
local
jit
=
require
(
"jit"
)
print
(
string.format
(
"%s %s -- Running on %s (%s/%s)"
,
progname
,
rawget
(
_G
,
"BCC_VERSION"
)
or
"HEAD"
,
jit
.
version
,
jit
.
os
,
jit
.
arch
))
os.exit
(
0
)
end
while
arg
[
1
]
and
string
.
starts
(
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
string
.
starts
(
k
,
"--so-path="
)
then
rawset
(
_G
,
"LIBBCC_SO_PATH"
,
string
.
lstrip
(
k
,
"--so-path="
))
elseif
k
==
"--llvm-debug"
then
rawset
(
_G
,
"LIBBCC_LLVM_DEBUG"
,
1
)
elseif
k
==
"-q"
or
k
==
"--quiet"
then
log
ging
=
false
log
.
enabled
=
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
print_version
()
else
print_usage
()
end
...
...
@@ -54,16 +53,13 @@ return function()
local
tracefile
=
table.remove
(
arg
,
1
)
if
not
tracefile
then
print_usage
()
end
local
BCC
=
require
(
"bcc.init"
)
local
BPF
=
BCC
.
BPF
local
BPF
=
require
(
"bcc.bpf"
)
BPF
.
script_root
(
tracefile
)
log
.
enabled
=
logging
local
utils
=
{
argparse
=
require
(
"bcc.vendor.argparse"
),
posix
=
require
(
"bcc.vendor.posix"
),
sym
=
BCC
.
sym
sym
=
require
(
"bcc.sym"
),
}
local
command
=
dofile
(
tracefile
)
...
...
src/lua/bcc/vendor/helpers.lua
View file @
28981655
function
string
.
starts
(
String
,
Start
)
return
string.sub
(
String
,
1
,
string.len
(
Start
))
==
Start
function
string
.
starts
(
s
,
p
)
return
string.sub
(
s
,
1
,
string.len
(
p
))
==
p
end
function
string
.
ends
(
String
,
End
)
return
End
==
''
or
string.sub
(
String
,
-
string.len
(
End
))
==
End
function
string
.
lstrip
(
s
,
p
)
return
string.sub
(
s
,
string.len
(
p
)
+
1
)
end
function
string
.
ends
(
s
,
e
)
return
e
==
''
or
string.sub
(
s
,
-
string.len
(
e
))
==
e
end
function
string
.
escape
(
s
)
...
...
src/lua/src/main.c
View file @
28981655
...
...
@@ -125,31 +125,25 @@ static void pushargv(lua_State *L, char **argv, int argc, int offset)
}
}
static
int
find
_libbcc
(
lua_State
*
L
)
static
void
find_local
_libbcc
(
lua_State
*
L
)
{
const
char
*
libbcc
=
getenv
(
"LIBBCC_SO_PATH"
);
char
buffer
[
4096
];
char
*
dirname
;
if
(
libbcc
==
NULL
)
{
char
*
dirname
;
if
(
readlink
(
"/proc/self/exe"
,
buffer
,
sizeof
(
buffer
))
<
0
)
return
;
if
(
readlink
(
"/proc/self/exe"
,
buffer
,
sizeof
(
buffer
))
<
0
)
return
-
1
;
dirname
=
strrchr
(
buffer
,
'/'
);
if
(
dirname
==
NULL
)
return
;
dirname
=
strrchr
(
buffer
,
'/'
);
if
(
dirname
==
NULL
)
return
-
1
;
strcpy
(
dirname
+
1
,
"libbcc.so"
);
strcpy
(
dirname
+
1
,
"libbcc.so"
);
libbcc
=
buffer
;
}
if
(
access
(
libbcc
,
F_OK
|
R_OK
|
X_OK
)
!=
0
)
return
-
1
;
if
(
access
(
buffer
,
F_OK
|
R_OK
|
X_OK
)
!=
0
)
return
;
lua_pushstring
(
L
,
libbcc
);
lua_pushstring
(
L
,
buffer
);
lua_setglobal
(
L
,
"LIBBCC_SO_PATH"
);
return
0
;
}
static
int
pmain
(
lua_State
*
L
)
...
...
@@ -160,19 +154,14 @@ static int pmain(lua_State *L)
lua_gc
(
L
,
LUA_GCSTOP
,
0
);
luaL_openlibs
(
L
);
lua_gc
(
L
,
LUA_GCRESTART
,
0
);
if
(
find_libbcc
(
L
)
<
0
)
{
s
->
status
=
1
;
l_message
(
progname
,
"failed to find libbcc.so"
);
return
0
;
}
find_local_libbcc
(
L
);
s
->
status
=
dolibrary
(
L
,
"bcc"
,
0
);
if
(
s
->
status
)
return
0
;
lua_push
boolean
(
L
,
1
);
lua_setglobal
(
L
,
"BCC_STANDALONE"
);
lua_push
string
(
L
,
progname
);
lua_setglobal
(
L
,
"BCC_STANDALONE
_NAME
"
);
pushargv
(
L
,
s
->
argv
,
s
->
argc
,
1
);
lua_setglobal
(
L
,
"arg"
);
...
...
@@ -192,13 +181,7 @@ int main(int argc, char **argv)
return
EXIT_FAILURE
;
}
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"usage: %s path_to_probe.lua [...]
\n
"
,
argv
[
0
]);
return
EXIT_FAILURE
;
}
progname
=
argv
[
0
];
s
.
argc
=
argc
;
s
.
argv
=
argv
;
s
.
status
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment