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
5b7c6783
Commit
5b7c6783
authored
Mar 09, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add perf event attaching interface with raw perf_event_attr argument
parent
1393ec48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
19 deletions
+27
-19
src/cc/libbpf.c
src/cc/libbpf.c
+23
-19
src/cc/libbpf.h
src/cc/libbpf.h
+4
-0
No files found.
src/cc/libbpf.c
View file @
5b7c6783
...
...
@@ -1278,6 +1278,28 @@ cleanup:
return
ret
;
}
int
bpf_attach_perf_event_raw
(
int
progfd
,
void
*
perf_event_attr
,
pid_t
pid
,
int
cpu
,
int
group_fd
)
{
int
fd
=
syscall
(
__NR_perf_event_open
,
perf_event_attr
,
pid
,
cpu
,
group_fd
,
PERF_FLAG_FD_CLOEXEC
);
if
(
fd
<
0
)
{
perror
(
"perf_event_open failed"
);
return
-
1
;
}
if
(
ioctl
(
fd
,
PERF_EVENT_IOC_SET_BPF
,
progfd
)
!=
0
)
{
perror
(
"ioctl(PERF_EVENT_IOC_SET_BPF) failed"
);
close
(
fd
);
return
-
1
;
}
if
(
ioctl
(
fd
,
PERF_EVENT_IOC_ENABLE
,
0
)
!=
0
)
{
perror
(
"ioctl(PERF_EVENT_IOC_ENABLE) failed"
);
close
(
fd
);
return
-
1
;
}
return
fd
;
}
int
bpf_attach_perf_event
(
int
progfd
,
uint32_t
ev_type
,
uint32_t
ev_config
,
uint64_t
sample_period
,
uint64_t
sample_freq
,
pid_t
pid
,
int
cpu
,
int
group_fd
)
{
...
...
@@ -1303,25 +1325,7 @@ int bpf_attach_perf_event(int progfd, uint32_t ev_type, uint32_t ev_config,
attr
.
sample_period
=
sample_period
;
}
int
fd
=
syscall
(
__NR_perf_event_open
,
&
attr
,
pid
,
cpu
,
group_fd
,
PERF_FLAG_FD_CLOEXEC
);
if
(
fd
<
0
)
{
perror
(
"perf_event_open failed"
);
return
-
1
;
}
if
(
ioctl
(
fd
,
PERF_EVENT_IOC_SET_BPF
,
progfd
)
!=
0
)
{
perror
(
"ioctl(PERF_EVENT_IOC_SET_BPF) failed"
);
close
(
fd
);
return
-
1
;
}
if
(
ioctl
(
fd
,
PERF_EVENT_IOC_ENABLE
,
0
)
!=
0
)
{
perror
(
"ioctl(PERF_EVENT_IOC_ENABLE) failed"
);
close
(
fd
);
return
-
1
;
}
return
fd
;
return
bpf_attach_perf_event_raw
(
progfd
,
&
attr
,
pid
,
cpu
,
group_fd
);
}
int
bpf_close_perf_event_fd
(
int
fd
)
{
...
...
src/cc/libbpf.h
View file @
5b7c6783
...
...
@@ -88,6 +88,10 @@ void * bpf_open_perf_buffer(perf_reader_raw_cb raw_cb,
/* attached a prog expressed by progfd to the device specified in dev_name */
int
bpf_attach_xdp
(
const
char
*
dev_name
,
int
progfd
,
uint32_t
flags
);
// attach a prog expressed by progfd to run on a specific perf event. The perf
// event will be created using the perf_event_attr pointer provided.
int
bpf_attach_perf_event_raw
(
int
progfd
,
void
*
perf_event_attr
,
pid_t
pid
,
int
cpu
,
int
group_fd
);
// attach a prog expressed by progfd to run on a specific perf event, with
// certain sample period or sample frequency
int
bpf_attach_perf_event
(
int
progfd
,
uint32_t
ev_type
,
uint32_t
ev_config
,
...
...
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