ebpf: Add example

This ensures that macro expansion works properly and that expanded code
compiles

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
pull/350/head
Dave Tucker 2 years ago
parent 5d82d9a73e
commit 5789585994

@ -1,2 +1,12 @@
[workspace] [workspace]
members = ["aya-log-ebpf", "aya-log-ebpf-macros"] members = ["aya-log-ebpf", "aya-log-ebpf-macros", "example"]
[profile.dev]
panic = "abort"
debug = 1
opt-level = 2
overflow-checks = false
[profile.release]
panic = "abort"

@ -10,12 +10,3 @@ aya-log-ebpf-macros = { path = "../aya-log-ebpf-macros" }
[lib] [lib]
path = "src/lib.rs" path = "src/lib.rs"
[profile.dev]
panic = "abort"
debug = 1
opt-level = 2
overflow-checks = false
[profile.release]
panic = "abort"

@ -1,9 +1,11 @@
#![no_std] #![no_std]
use aya_bpf::{ use aya_bpf::{
macros::map, macros::map,
maps::{PerCpuArray, PerfEventByteArray} maps::{PerCpuArray, PerfEventByteArray},
};
pub use aya_log_common::{
write_record_header, write_record_message, Level, WriteToBuf, LOG_BUF_CAPACITY,
}; };
pub use aya_log_common::{Level, LOG_BUF_CAPACITY, write_record_header, write_record_message, WriteToBuf};
pub use aya_log_ebpf_macros::{debug, error, info, log, trace, warn}; pub use aya_log_ebpf_macros::{debug, error, info, log, trace, warn};
#[doc(hidden)] #[doc(hidden)]

@ -0,0 +1,13 @@
[package]
name = "example"
version = "0.1.0"
edition = "2018"
publish = false
[dependencies]
aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
aya-log-ebpf = { path = "../aya-log-ebpf" }
[[bin]]
name = "example"
path = "src/main.rs"

@ -0,0 +1,22 @@
#![no_std]
#![no_main]
use aya_bpf::{macros::tracepoint, programs::TracePointContext, BpfContext};
use aya_log_ebpf::{debug, error, info, trace, warn};
#[tracepoint]
pub fn example(ctx: TracePointContext) -> u32 {
error!(&ctx, "this is an error message 🚨");
warn!(&ctx, "this is a warning message ⚠️");
info!(&ctx, "this is an info message ");
debug!(&ctx, "this is a debug message ️🐝");
trace!(&ctx, "this is a trace message 🔍");
let pid = ctx.pid();
info!(&ctx, "a message with args PID: {}", pid);
0
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
}
Loading…
Cancel
Save