ebpf-lab

example code from Learning eBPF by Liz Rice, https://github.com/lizrice/learning-ebpf
git clone https://git.in0rdr.ch/ebpf-lab.git
Log | Files | Refs | Pull requests |Archive | README

commit 227a769d8b187183bc7f598c06697ffe76cf988d
parent e22526890f50a487ba922ae795fa57c6513fd970
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Mon, 15 May 2023 16:59:35 +0200

feat: bpftrace uprobe example

Diffstat:
M.gitignore | 1+
Asamples/demo-app/Makefile | 4++++
Asamples/demo-app/demo.c | 20++++++++++++++++++++
3 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,3 +2,4 @@ **manifest.json **.swp packer/output +samples/demo-app/demo diff --git a/samples/demo-app/Makefile b/samples/demo-app/Makefile @@ -0,0 +1,4 @@ +default: demo + gcc demo.c -o demo +clean: + rm demo diff --git a/samples/demo-app/demo.c b/samples/demo-app/demo.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <time.h> + +int output(int hour, int min, int sec) { + printf("Current time: %d:%d:%d \n", hour, min, sec); +} + +int main(int argc, char** argv) { + struct timespec timer = { 0, 700000000 }; + time_t datetime; + // see /usr/include/bits/types/struct_tm.h + struct tm i; + + for (;;) { + datetime = time(NULL); + localtime_r(&datetime, &i); + output(i.tm_hour, i.tm_min, i.tm_sec); + nanosleep(&timer, &timer); + } +}