Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
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
bpftrace
Commits
bd253e51
Commit
bd253e51
authored
Dec 30, 2018
by
Brendan Gregg
Committed by
GitHub
Dec 30, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #303 from danobi/path_lookup
Search PATH for executables when running commands
parents
9e608df7
a07be2c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
man/man8/bpftrace.8
man/man8/bpftrace.8
+1
-1
src/bpftrace.cpp
src/bpftrace.cpp
+23
-0
src/bpftrace.h
src/bpftrace.h
+1
-0
No files found.
man/man8/bpftrace.8
View file @
bd253e51
...
...
@@ -65,7 +65,7 @@ Enable USDT probes on PID. Will terminate bpftrace on PID termination. Note this
.TP
\fB\-c CMD\fR
Helper to run CMD. Equivalent to manually running CMD and then giving passing the PID to -p. This is useful to ensure
you've traced at least the duration CMD's execution.
You must provide an absolute path for the executable.
you've traced at least the duration CMD's execution.
.
.TP
\fB\-v\fR
...
...
src/bpftrace.cpp
View file @
bd253e51
...
...
@@ -448,6 +448,7 @@ int BPFtrace::run(std::unique_ptr<BpfOrc> bpforc)
if
(
cmd_
.
size
())
{
auto
args
=
split_string
(
cmd_
,
' '
);
args
[
0
]
=
resolve_binary_path
(
args
[
0
]);
// does path lookup on executable
int
pid
=
spawn_child
(
args
);
if
(
pid
<
0
)
{
...
...
@@ -1111,6 +1112,28 @@ int BPFtrace::print_lhist(const std::vector<uint64_t> &values, int min, int max,
return
0
;
}
std
::
string
BPFtrace
::
resolve_binary_path
(
const
std
::
string
&
cmd
)
{
std
::
string
query
;
query
+=
"command -pv "
;
query
+=
cmd
;
std
::
string
result
=
exec_system
(
query
.
c_str
());
if
(
result
.
size
())
{
// Remove newline at the end
auto
it
=
result
.
rfind
(
'\n'
);
if
(
it
!=
std
::
string
::
npos
)
result
.
erase
(
it
);
return
result
;
}
else
{
return
cmd
;
}
}
int
BPFtrace
::
spawn_child
(
const
std
::
vector
<
std
::
string
>&
args
)
{
static
const
int
maxargs
=
256
;
...
...
src/bpftrace.h
View file @
bd253e51
...
...
@@ -120,6 +120,7 @@ private:
static
std
::
string
lhist_index_label
(
int
number
);
static
std
::
vector
<
std
::
string
>
split_string
(
std
::
string
&
str
,
char
split_by
);
std
::
vector
<
uint8_t
>
find_empty_key
(
IMap
&
map
,
size_t
size
)
const
;
static
std
::
string
resolve_binary_path
(
const
std
::
string
&
cmd
);
static
int
spawn_child
(
const
std
::
vector
<
std
::
string
>&
args
);
static
bool
is_pid_alive
(
int
pid
);
};
...
...
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