← Back to Tech Radar
Hacker News tech

How Do I Profile eBPF Code?

Trending on Hacker News: How Do I Profile eBPF Code? (99 points / 6 comments, via naveensrinivasan.com)

In one line

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.

Opening excerpt

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 ); …

(Excerpted from the original; full article via the source link below.)

This story hit the Hacker News front page today (99 points / 6 comments, via naveensrinivasan.com). Our Tech Radar aggregates daily signals on AI engineering, backend architecture and DevOps — browse the related services and further reading below, or get in touch with our team.

Source: Hacker News

Related Services

Related Reading