我尝试使用此代码跟踪开放系统调用。
#include <stdio.h>
#include <fcntl.h>
int main()
{
char *path = "/home/[my account]/text.txt";
int fd;
fd = open(path, O_RDWR);
return 0;
}
我用它编译了它
gcc -o open open.c
并开始Ftrace。
echo SyS_open > set_graph_function
echo SyS_read >> set_graph_function
sh -c 'echo $$ > set_ftrace_pid; echo 1 > tracing_on;
exec /home/[my account]/open'
而我得到cat trace
的只是关于..与..SyS_read
没有任何关系SyS_open
(我用 cat set_graph_function 检查如下:
root@[server name]:/sys/kernel/debug/tracing# cat set_graph_function
SyS_read
SyS_open
并确认SyS_open
没有错过。)
# CPU DURATION FUNCTION CALLS
# | | | | | | |
17) | SyS_read() {
17) | __fdget_pos() {
17) 0.137 us | __fget_light();
17) 1.285 us | }
17) | vfs_read() {
17) | rw_verify_area() {
17) | security_file_permission() {
17) | apparmor_file_permission() {
17) | common_file_perm() {
17) 0.041 us | aa_file_perm();
17) 0.493 us | }
17) 0.934 us | }
17) 0.040 us | __fsnotify_parent();
17) 0.042 us | fsnotify();
17) 2.843 us | }
17) 3.194 us | }
17) | __vfs_read() {
17) | new_sync_read() {
17) | ext4_file_read_iter() {
17) | generic_file_read_iter() {
17) | _cond_resched() {
17) 0.040 us | rcu_all_qs();
17) 0.387 us | }
17) | pagecache_get_page() {
17) 0.225 us | find_get_entry();
17) 0.573 us | }
17) 0.046 us | mark_page_accessed();
17) | _cond_resched() {
17) 0.040 us | rcu_all_qs();
17) 0.393 us | }
17) | touch_atime() {
17) | __atime_needs_update() {
17) | current_time() {
17) 0.042 us | current_kernel_time64();
17) 0.039 us | timespec_trunc();
17) 0.972 us | }
17) 1.321 us | }
17) 1.692 us | }
17) 4.990 us | }
17) 5.351 us | }
17) 5.766 us | }
17) 6.161 us | }
17) 0.039 us | __fsnotify_parent();
17) 0.045 us | fsnotify();
17) + 10.735 us | }
17) + 13.187 us | }
为什么SyS_read
即使我用 编写代码也只有open()
?
我试图删除缓存并再次执行此操作,但结果完全相同。
而且我也知道为什么会SyS_read
出现,尽管我只使用了open()
.