From 551f7950b6aecf2c21c87094014aed3097c3ee13 Mon Sep 17 00:00:00 2001 From: Himanshu Pandey <24816726+hp77-creator@users.noreply.github.com> Date: Sat, 25 May 2024 13:31:58 +0530 Subject: [PATCH] Fix example --- example/libbpftime_example/Makefile | 7 +------ example/libbpftime_example/README.md | 6 ------ example/libbpftime_example/ebpf.json | 12 ++++++++++++ example/libbpftime_example/main.cpp | 8 +++++++- example/libbpftime_example/spdlog_exam.cpp | 5 ----- 5 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 example/libbpftime_example/ebpf.json delete mode 100644 example/libbpftime_example/spdlog_exam.cpp diff --git a/example/libbpftime_example/Makefile b/example/libbpftime_example/Makefile index 638bf3c5..700317f9 100644 --- a/example/libbpftime_example/Makefile +++ b/example/libbpftime_example/Makefile @@ -11,10 +11,8 @@ LDFLAGS = -L$(HOME)/.bpftime LDLIBS = -lbpftime -lboost_system -lrt -lbpf SHM_SRC = main.cpp -SPDLOG_SRC = spdlog_exam.cpp SHM_TARGET = shm_example -SPDLOG_TARGET = spdlog_exam help: @echo "Available targets:" @@ -24,9 +22,6 @@ help: shm_example: $(SHM_SRC) ## build shared memory example $(CXX) -o $(SHM_TARGET) $(SHM_SRC) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) -sdplog_exam: $(SPDLOG_SRC) ## build spdlog example - $(CXX) -o $(SPDLOG_TARGET) $(SPDLOG_SRC) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) - .PHONY: clean clean: ## clean the build - rm -f $(SHM_TARGET) $(SPDLOG_TARGET) + rm -f $(SHM_TARGET) example_shm.json diff --git a/example/libbpftime_example/README.md b/example/libbpftime_example/README.md index e879698e..a28466fc 100644 --- a/example/libbpftime_example/README.md +++ b/example/libbpftime_example/README.md @@ -29,7 +29,6 @@ run `make` and you will see the following output ```shell Available targets: shm_example build shared memory example - sdplog_exam build spdlog example clean clean the build ``` @@ -37,9 +36,4 @@ command to execute the code: when not using llvm-jit ```shell g++ -o example main.cpp -I../../runtime/include -I../../vm/compat/include/ -I../../third_party/spdlog/include -I../../vm/vm-core/include -L~/.bpftime -lbpftime -lboost_system -lrt -lbpf -``` - -for `spdlog_exam.cpp` -```shell -g++ -o example spdlog_exam.cpp -I../../runtime/include -I../../vm/vm-core/compat/include -I../../vm/compat/include/ -I../../third_party/spdlog/include -L~/.bpftime -lbpftime -lboost_system -lrt -lbpf ``` \ No newline at end of file diff --git a/example/libbpftime_example/ebpf.json b/example/libbpftime_example/ebpf.json new file mode 100644 index 00000000..c9f1ff27 --- /dev/null +++ b/example/libbpftime_example/ebpf.json @@ -0,0 +1,12 @@ +{ + "1": { + "type": "bpf_prog_handler", + "name": "example_prog", + "attr": { + "insns": "abcd1234ef567890", + "type": 1, + "cnt": 1, + "attach_fds": [2, 3] + } + } +} \ No newline at end of file diff --git a/example/libbpftime_example/main.cpp b/example/libbpftime_example/main.cpp index bba1cc4b..df44e7ef 100644 --- a/example/libbpftime_example/main.cpp +++ b/example/libbpftime_example/main.cpp @@ -4,7 +4,13 @@ int main() { bpftime_initialize_global_shm(bpftime::shm_open_type::SHM_CREATE_OR_OPEN); const char* jsonFileName = "example_shm.json"; + const char* importJsonName = "ebpf.json"; SPDLOG_INFO("GLOBAL memory initialized "); + // load json program to shm + bpftime_import_global_shm_from_json(importJsonName); + // export it to another json file bpftime_export_global_shm_to_json(jsonFileName); + // remove content from global shm + bpftime_remove_global_shm(); return 0; -} +} \ No newline at end of file diff --git a/example/libbpftime_example/spdlog_exam.cpp b/example/libbpftime_example/spdlog_exam.cpp deleted file mode 100644 index e5f6f3fa..00000000 --- a/example/libbpftime_example/spdlog_exam.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "spdlog/spdlog.h" - -int main() { - SPDLOG_INFO("Welcome to the tests"); -} \ No newline at end of file