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
9dc87fa7
Commit
9dc87fa7
authored
May 01, 2016
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lua: Implement an USDT helper
parent
eca4783e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
4 deletions
+108
-4
src/lua/bcc/bpf.lua
src/lua/bcc/bpf.lua
+9
-2
src/lua/bcc/libbcc.lua
src/lua/bcc/libbcc.lua
+12
-0
src/lua/bcc/run.lua
src/lua/bcc/run.lua
+5
-2
src/lua/bcc/usdt.lua
src/lua/bcc/usdt.lua
+81
-0
src/lua/squishy
src/lua/squishy
+1
-0
No files found.
src/lua/bcc/bpf.lua
View file @
9dc87fa7
...
@@ -37,7 +37,7 @@ function Bpf.static.check_probe_quota(n)
...
@@ -37,7 +37,7 @@ function Bpf.static.check_probe_quota(n)
assert
(
cur
+
n
<=
Bpf
.
static
.
KPROBE_LIMIT
,
"number of open probes would exceed quota"
)
assert
(
cur
+
n
<=
Bpf
.
static
.
KPROBE_LIMIT
,
"number of open probes would exceed quota"
)
end
end
function
Bpf
.
static
.
cleanup
_probes
()
function
Bpf
.
static
.
cleanup
()
local
function
detach_all
(
probe_type
,
all_probes
)
local
function
detach_all
(
probe_type
,
all_probes
)
for
key
,
probe
in
pairs
(
all_probes
)
do
for
key
,
probe
in
pairs
(
all_probes
)
do
libbcc
.
perf_reader_free
(
probe
)
libbcc
.
perf_reader_free
(
probe
)
...
@@ -102,10 +102,13 @@ local function _find_file(script_root, filename)
...
@@ -102,10 +102,13 @@ local function _find_file(script_root, filename)
end
end
function
Bpf
:
initialize
(
args
)
function
Bpf
:
initialize
(
args
)
self
.
do_debug
=
args
.
debug
or
false
self
.
funcs
=
{}
self
.
funcs
=
{}
self
.
tables
=
{}
self
.
tables
=
{}
if
args
.
usdt
and
args
.
text
then
args
.
text
=
args
.
usdt
:
_get_text
()
..
args
.
text
end
local
cflags
=
table
.
join
(
Bpf
.
DEFAULT_CFLAGS
,
args
.
cflags
)
local
cflags
=
table
.
join
(
Bpf
.
DEFAULT_CFLAGS
,
args
.
cflags
)
local
cflags_ary
=
ffi
.
new
(
"const char *[?]"
,
#
cflags
,
cflags
)
local
cflags_ary
=
ffi
.
new
(
"const char *[?]"
,
#
cflags
,
cflags
)
...
@@ -127,6 +130,10 @@ function Bpf:initialize(args)
...
@@ -127,6 +130,10 @@ function Bpf:initialize(args)
end
end
assert
(
self
.
module
~=
nil
,
"failed to compile BPF module"
)
assert
(
self
.
module
~=
nil
,
"failed to compile BPF module"
)
if
args
.
usdt
then
args
.
usdt
:
_attach_uprobes
(
self
)
end
end
end
function
Bpf
:
load_funcs
(
prog_type
)
function
Bpf
:
load_funcs
(
prog_type
)
...
...
src/lua/bcc/libbcc.lua
View file @
9dc87fa7
...
@@ -112,6 +112,18 @@ int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
...
@@ -112,6 +112,18 @@ int bcc_symcache_resolve(void *symcache, uint64_t addr, struct bcc_symbol *sym);
void bcc_symcache_refresh(void *resolver);
void bcc_symcache_refresh(void *resolver);
]]
]]
ffi
.
cdef
[[
void *bcc_usdt_new_frompid(int pid);
void *bcc_usdt_new_frompath(const char *path);
void bcc_usdt_close(void *usdt);
int bcc_usdt_enable_probe(void *, const char *, const char *);
char *bcc_usdt_genargs(void *);
typedef void (*bcc_usdt_uprobe_cb)(const char *, const char *, uint64_t, int);
void bcc_usdt_foreach_uprobe(void *usdt, bcc_usdt_uprobe_cb callback);
]]
if
rawget
(
_G
,
"BCC_STANDALONE"
)
then
if
rawget
(
_G
,
"BCC_STANDALONE"
)
then
return
ffi
.
C
return
ffi
.
C
else
else
...
...
src/lua/bcc/run.lua
View file @
9dc87fa7
...
@@ -57,18 +57,21 @@ return function()
...
@@ -57,18 +57,21 @@ return function()
local
BPF
=
require
(
"bcc.bpf"
)
local
BPF
=
require
(
"bcc.bpf"
)
BPF
.
script_root
(
tracefile
)
BPF
.
script_root
(
tracefile
)
local
USDT
=
require
(
"bcc.usdt"
)
local
utils
=
{
local
utils
=
{
argparse
=
require
(
"bcc.vendor.argparse"
),
argparse
=
require
(
"bcc.vendor.argparse"
),
posix
=
require
(
"bcc.vendor.posix"
),
posix
=
require
(
"bcc.vendor.posix"
),
USDT
=
USDT
,
}
}
local
command
=
dofile
(
tracefile
)
local
command
=
dofile
(
tracefile
)
local
res
,
err
=
xpcall
(
command
,
debug.traceback
,
BPF
,
utils
)
local
res
,
err
=
xpcall
(
command
,
debug.traceback
,
BPF
,
utils
)
if
not
res
then
if
not
res
and
err
~=
"interrupted!"
then
io.stderr
:
write
(
"[ERROR] "
..
err
..
"
\n
"
)
io.stderr
:
write
(
"[ERROR] "
..
err
..
"
\n
"
)
end
end
BPF
.
cleanup_probes
()
BPF
.
cleanup
()
USDT
.
cleanup
()
return
res
,
err
return
res
,
err
end
end
src/lua/bcc/usdt.lua
0 → 100644
View file @
9dc87fa7
--[[
Copyright 2016 GitHub, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local
ffi
=
require
(
"ffi"
)
ffi
.
cdef
"void free(void *ptr);"
local
libbcc
=
require
(
"bcc.libbcc"
)
local
Usdt
=
class
(
"USDT"
)
Usdt
.
static
.
open_contexts
=
{}
function
Usdt
.
static
.
cleanup
()
for
_
,
context
in
ipairs
(
Usdt
.
static
.
open_contexts
)
do
context
:
_cleanup
()
end
end
function
Usdt
:
initialize
(
args
)
assert
(
args
.
pid
or
args
.
path
)
if
args
.
pid
then
self
.
pid
=
args
.
pid
self
.
context
=
libbcc
.
bcc_usdt_new_frompid
(
args
.
pid
)
elseif
args
.
path
then
self
.
path
=
args
.
path
self
.
context
=
libbcc
.
bcc_usdt_new_frompath
(
args
.
path
)
end
assert
(
self
.
context
~=
nil
,
"failed to create USDT context"
)
table.insert
(
Usdt
.
open_contexts
,
self
)
end
function
Usdt
:
enable_probe
(
args
)
assert
(
args
.
probe
and
args
.
fn_name
)
assert
(
libbcc
.
bcc_usdt_enable_probe
(
self
.
context
,
args
.
probe
,
args
.
fn_name
)
==
0
)
end
function
Usdt
:
_cleanup
()
libbcc
.
bcc_usdt_close
(
self
.
context
)
self
.
context
=
nil
end
function
Usdt
:
_get_text
()
local
argc
=
libbcc
.
bcc_usdt_genargs
(
self
.
context
)
assert
(
argc
~=
nil
)
local
text
=
ffi
.
string
(
argc
)
ffi
.
C
.
free
(
argc
)
return
text
end
function
Usdt
:
_attach_uprobes
(
bpf
)
local
uprobes
=
{}
local
cb
=
ffi
.
cast
(
"bcc_usdt_uprobe_cb"
,
function
(
binpath
,
fn_name
,
addr
,
pid
)
table.insert
(
uprobes
,
{
name
=
ffi
.
string
(
binpath
),
addr
=
addr
,
fn_name
=
ffi
.
string
(
fn_name
),
pid
=
pid
})
end
)
libbcc
.
bcc_usdt_foreach_uprobe
(
self
.
context
,
cb
)
cb
:
free
()
for
_
,
args
in
ipairs
(
uprobes
)
do
bpf
:
attach_uprobe
(
args
)
end
end
return
Usdt
src/lua/squishy
View file @
9dc87fa7
...
@@ -11,6 +11,7 @@ Module "bcc.sym" "bcc/sym.lua"
...
@@ -11,6 +11,7 @@ Module "bcc.sym" "bcc/sym.lua"
Module "bcc.libbcc" "bcc/libbcc.lua"
Module "bcc.libbcc" "bcc/libbcc.lua"
Module "bcc.tracerpipe" "bcc/tracerpipe.lua"
Module "bcc.tracerpipe" "bcc/tracerpipe.lua"
Module "bcc.table" "bcc/table.lua"
Module "bcc.table" "bcc/table.lua"
Module "bcc.usdt" "bcc/usdt.lua"
Main "bcc/run.lua"
Main "bcc/run.lua"
Output "bcc.lua"
Output "bcc.lua"
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