← 返回技术雷达
Hacker News tech

How Do I Profile eBPF Code?

Hacker News 热议:How Do I Profile eBPF Code?(99 赞 / 6 评论,来源 naveensrinivasan.com)

一句话概要

If we are running any eBPF workload or writing eBPF code, we want to measure its performance impact, and in this post we will demonstrate an example of how to do it. In this example, our goal is to measure the performance of file open operations, one of the most critical functions in the OS.

原文开头节选

In this example, our goal is to measure the performance of file open operations, one of the most critical functions in the OS. Our code used file open hooks in eBPF, we wanted to measure the performance overhead introduced by adding this hook.

To identify likely bottlenecks, we need a simple C test harness with the fewest dependencies, designed to measure file open performance.

#define _GNU_SOURCE #include <fcntl.h> #include <stdio.h> #include <time.h> #include <stdint.h> #include <stdlib.h> #include <unistd.h> #include <sched.h> #include <sys/mman.h> #include <sys/syscall.h> static inline uint64_t now_ns ( void ) { struct timespec ts; clock_gettime (CLOCK_MONOTONIC, & ts); /* VDSO, no syscall / return ( uint64_t )ts.tv_sec * 1000000000ull + ts.tv_nsec; } int main ( int argc, char ** argv) { const char * path = argv[ 1 ]; uint64_t n = strtoull (argv[ 2 ], NULL, 10 ); uint64_t warm = n / 10 ; / preallocate + prefault + lock: no page faults in the loop */ uint32_t * d = mmap (NULL, n * sizeof ( uint32_t ), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, - 1 , 0 ); …

(以上为原文节选,完整内容见下方”原文来源”)

这条动态今日登上 Hacker News 首页(99 赞 / 6 评论,来源 naveensrinivasan.com)。技术雷达每日自动聚合 AI 工程、后端架构、DevOps 方向的前沿动态;相关工程落地可浏览下方的相关服务与延伸阅读,或直接与我们团队交流。

原文来源: Hacker News

相关服务