diff --git "a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/docs/\346\265\213\350\257\225\344\270\216\346\225\260\346\215\256\345\205\263\350\201\224.md" "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/docs/\346\265\213\350\257\225\344\270\216\346\225\260\346\215\256\345\205\263\350\201\224.md" index 6f4cf945f..d0fe06640 100644 --- "a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/docs/\346\265\213\350\257\225\344\270\216\346\225\260\346\215\256\345\205\263\350\201\224.md" +++ "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/docs/\346\265\213\350\257\225\344\270\216\346\225\260\346\215\256\345\205\263\350\201\224.md" @@ -933,11 +933,6 @@ lttng监测到的结果: 通过lttng以及syscall_image的对比,可以证明我们的syscall_image工具在逻辑上是正确无误的; -其中还有很多细节没有展示,可以在以下几个原始数据中进行对比: - -- -- - #### 4.2.2 数据正确性 前面我们已经对syscall-image工具进行了逻辑真确性验证,接下来我们通过对比一些数据来验证数据正确性,这些数据包括: @@ -973,10 +968,6 @@ TIME TGID PID 1st/num 2nd/num 3nd/num | P_AV 通过以上数据的对比,我们可以得出结论,syscall_image在数据层面是真实可靠的,他与lttng之间存在0.0000255%的误差,是可以忽略的。 -详细的原始数据可在这里查看: - -- -- ### 4.3 关键数据点的关联关系 diff --git a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.h b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.h new file mode 100644 index 000000000..60b2e438e --- /dev/null +++ b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.h @@ -0,0 +1,257 @@ + +#undef LTTNG_UST_TRACEPOINT_PROVIDER +#define LTTNG_UST_TRACEPOINT_PROVIDER lock_monitor + +#undef LTTNG_UST_TRACEPOINT_INCLUDE +#define LTTNG_UST_TRACEPOINT_INCLUDE "/home/xhb/ospp/lock_tracepoint.h" + +#if !defined(LOCK_TRACEPOINT_H) || defined(LTTNG_UST_TRACEPOINT_HEADER_MULTI_READ) +#define LOCK_TRACEPOINT_H + +#include + +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_hex(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_failed, TRACE_DEBUG) + +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_failed, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_failed, TRACE_DEBUG) + +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_failed, TRACE_DEBUG) + + +#endif /* LOCK_TRACEPOINT_H */ + +#include diff --git a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.tp b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.tp new file mode 100644 index 000000000..40363378e --- /dev/null +++ b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/lock_tracepoint.tp @@ -0,0 +1,241 @@ +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_lock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + mutex_trylock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) +TRACEPOINT_EVENT( + lock_monitor, + rwlock_rdlock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + rwlock_wrlock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_lock_released, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_start, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_acquired, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) + +TRACEPOINT_EVENT( + lock_monitor, + spinlock_trylock_failed, + TP_ARGS(int, thread_id, void*, lock_ptr, long long unsigned int, time), + TP_FIELDS( + ctf_integer(int, thread_id, thread_id) + ctf_integer_dec(void*, lock_ptr, lock_ptr) + ctf_integer(long long unsigned int, time, time) + ) +) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_lock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, mutex_trylock_failed, TRACE_DEBUG) + +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_rdlock_failed, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, rwlock_wrlock_failed, TRACE_DEBUG) + +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_lock_released, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_start, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_acquired, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(lock_monitor, spinlock_trylock_failed, TRACE_DEBUG) + diff --git "a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/ebpf_test.sh" "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/ebpf_test.sh" new file mode 100755 index 000000000..db7a97b50 --- /dev/null +++ "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/ebpf_test.sh" @@ -0,0 +1,27 @@ +#!/bin/bash +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +OUTPUT_DIR="$SCRIPT_DIR/lttng-traces" +# 获取目标进程的 PID +TARGET_PID=$(pidof test_proc_image) + +if [ -z "$TARGET_PID" ]; then + echo "目标进程未运行,请先启动目标进程。" + exit 1 +fi +echo "测试程序 PID: $TARGET_PID" +# 运行 eBPF 程序并将输出重定向到文件 + +cd /home/xhb/lmp2/lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/ +sudo ./proc_image -k > $OUTPUT_DIR/output.log & +PROC_IMAGE_PID=$! +sleep 1 +sudo ./controller -k 0 -p $TARGET_PID -a +# echo "eBPF 程序已在后台运行,输出将保存到 $OUTPUT_DIR/output.log 中 请在数据收集完后 Ctrl+C。" +read +sudo ./controller -k 0 -p $TARGET_PID -d +# 捕捉 Ctrl + C 信号 +# trap "echo '捕捉到 Ctrl + C 信号,停止进程...'; kill -SIGINT $PROC_IMAGE_PID; exit 0" SIGINT +# kill -SIGINT $PROC_IMAGE_PID +sudo ./controller -k 0 -f +echo "eBPF 程序已在后台运行,输出将保存到`$OUTPUT_DIR/output.log` 中" + diff --git "a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_keytime.sh" "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_keytime.sh" new file mode 100755 index 000000000..0bea3f2aa --- /dev/null +++ "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_keytime.sh" @@ -0,0 +1,66 @@ +#!/bin/bash + +# 获取脚本所在目录的绝对路径 +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +# 指定输出目录 +OUTPUT_DIR="$SCRIPT_DIR/lttng-traces/keytime_test_$(date +'%Y%m%d_%H:%M:%S')" +CSV_FILE="$OUTPUT_DIR/keytime_test_data.csv" +mkdir -p "$SCRIPT_DIR/ebpf/ebpf_output_$(date +'%Y%m%d_%H:%M:%S')" +EBPF_OUTPUT_DIR="$SCRIPT_DIR/ebpf/ebpf_output_$(date +'%Y%m%d_%H:%M:%S')" + +# 获取目标进程的 PID +TARGET_PID=$(pidof test_proc_image) + +if [ -z "$TARGET_PID" ]; then + echo "目标进程未运行,请先启动目标进程。" + exit 1 +fi +echo "测试程序 PID: $TARGET_PID" + +# 创建会话并指定输出目录 +sudo lttng create xhb_keytime --output=$OUTPUT_DIR + +# 启用内核事件,仅针对特定 PID +sudo lttng enable-event --kernel sched_switch,sched_process_fork,sched_process_exec,clone + +# 添加上下文信息 +sudo lttng add-context --kernel --type pid + +sudo lttng track --kernel --pid $TARGET_PID + +# 运行proc_image监测工具 +cd /home/xhb/lmp2/lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/ +sudo ./proc_image -k > $EBPF_OUTPUT_DIR/output.log & +PROC_IMAGE_PID=$! +sleep 1 +sudo ./controller -k 1 -P $TARGET_PID -a +# 启动会话 +sudo lttng start +read + +sudo lttng stop +sudo lttng destroy +echo "追踪数据已保存到 $OUTPUT_DIR 目录中" +# 将 LTTng 跟踪数据转换为文本格式 +babeltrace2 $OUTPUT_DIR > $OUTPUT_DIR/trace_data.txt + +# 解析文本格式并导出为 CSV 文件 +echo "timestamp, event, pid, cpu, details" > $CSV_FILE +awk ' +BEGIN { + FS=" " +} +{ + timestamp = $1 + event = $3 + pid = $6 + cpu = $8 + details = $0 + gsub(/,/, " ", details) # 替换 details 中的逗号以避免 CSV 格式问题 + printf "%s, %s, %s, %s, \"%s\"\n", timestamp, event, pid, cpu, details >> "'"$CSV_FILE"'" +} +' $OUTPUT_DIR/trace_data.txt +echo "lttng、eBPF 程序数据收集完毕,请 Ctrl+C 结束" +read +echo "数据已导出到 $CSV_FILE" \ No newline at end of file diff --git "a/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_lock.sh" "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_lock.sh" new file mode 100755 index 000000000..2a408c58a --- /dev/null +++ "b/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/test/shell\350\204\232\346\234\254/test_lock.sh" @@ -0,0 +1,67 @@ +#!/bin/bash + +# 获取脚本所在目录的绝对路径 +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +# 指定输出目录 +OUTPUT_DIR="$SCRIPT_DIR/lttng-traces/lock_test_$(date +'%Y%m%d_%H:%M:%S')" +CSV_FILE="$OUTPUT_DIR/lock_test_data.csv" +mkdir -p "$SCRIPT_DIR/ebpf/ebpf_output_$(date +'%Y%m%d_%H:%M:%S')" +EBPF_OUTPUT_DIR="$SCRIPT_DIR/ebpf/ebpf_output_$(date +'%Y%m%d_%H:%M:%S')" + +# 获取目标进程的 PID +TARGET_PID=$(pidof test_proc_image) + +if [ -z "$TARGET_PID" ]; then + echo "目标进程未运行,请先启动目标进程。" + exit 1 +fi +echo "测试程序 PID: $TARGET_PID" + +# 创建会话并指定输出目录 +sudo lttng create xhb_lock --output=$OUTPUT_DIR + +# 启用内核事件,仅针对特定 PID +sudo lttng enable-event -u 'lock_monitor:*' + +# 添加上下文信息 +sudo lttng add-context --kernel --type pid + +sudo lttng track --kernel --pid $TARGET_PID + +# 运行proc_image监测工具 +cd /home/xhb/lmp2/lmp/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image/ +sudo ./proc_image -l > $EBPF_OUTPUT_DIR/lock_output.log & +PROC_IMAGE_PID=$! +sleep 1 +sudo ./controller -l -P $TARGET_PID -a +# 启动会话 +sudo lttng start +read + +sudo lttng stop +sudo lttng view +sudo lttng destroy +echo "追踪数据已保存到 $OUTPUT_DIR 目录中" +# 将 LTTng 跟踪数据转换为文本格式 +babeltrace2 $OUTPUT_DIR > $OUTPUT_DIR/trace_data.txt + +# 解析文本格式并导出为 CSV 文件 +echo "timestamp, event, pid, cpu, details" > $CSV_FILE +awk ' +BEGIN { + FS=" " +} +{ + timestamp = $1 + event = $3 + pid = $6 + cpu = $8 + details = $0 + gsub(/,/, " ", details) # 替换 details 中的逗号以避免 CSV 格式问题 + printf "%s, %s, %s, %s, \"%s\"\n", timestamp, event, pid, cpu, details >> "'"$CSV_FILE"'" +} +' $OUTPUT_DIR/trace_data.txt +echo "lttng、eBPF 程序数据收集完毕,请 Ctrl+C 结束" +read +echo "数据已导出到 $CSV_FILE" \ No newline at end of file