Comments (2)
Have a look at the softirqs
example. https://github.com/jvns/rust-bcc/blob/master/examples/softirqs.rs
from rust-bcc.
Hey @brayniac
I'm trying perf output with tracepoint, I'm getting the output as todo: oh no
my code :
#include <uapi/linux/ptrace.h>
BPF_PERF_OUTPUT(events);
struct kmalloc_data
{
u32 pid;
u64 byte_alloc;
};
int kmalloc_collector(struct tracepoint__kmem__kmalloc *args)
{
u32 pid = bpf_get_current_pid_tgid();
u64 alloc = args->bytes_alloc;
struct kmalloc_data data = {};
data.pid = pid;
data.byte_alloc = alloc;
events.perf_submit(args, &data, sizeof(data));
return 0;
}
extern crate bcc;
extern crate failure;
use bcc::core::BPF;
use bcc::perf::init_perf_map;
use failure::Error;
use std::{mem, ptr, thread, time};
fn do_main() -> Result<(), Error> {
let code = include_str!("kmalloc.c");
let mut module = match BPF::new(code) {
Ok(x) => x,
Err(x) => return Err(x),
};
let kmalloc_collector = module.load_tracepoint("kmalloc_collector")?;
module.attach_tracepoint("kmem", "kmalloc", kmalloc_collector)?;
let table = module.table("events");
let mut perfmap = init_perf_map(table, perf_callback)?;
loop {
perfmap.poll(200);
}
Ok(())
}
fn perf_callback() -> Box<FnMut(&[u8]) + Send> {
Box::new(|x| {
let data = parse_struct(x);
println!("pid {} bytes allocated {}", data.pid, data.byte_alloc);
})
}
#[repr(C)]
struct kmalloc_data {
pid: u32,
byte_alloc: u64,
}
fn parse_struct(x: &[u8]) -> kmalloc_data {
unsafe { ptr::read(x.as_ptr() as *const kmalloc_data) }
}
fn main() {
match do_main() {
Ok(()) => println!("{}", "sup?"),
Err(x) => eprintln!("{}", x),
}
}
But it is working for HASH
PS: I just started rust so, my code may not be idiomatic
from rust-bcc.
Related Issues (20)
- Iterating over an empty table returns an empty entry. HOT 1
- add support for bcc 0.16.0 HOT 1
- deprecate `init_perf_map()`
- release 0.0.27 HOT 1
- BPF ring buffer support HOT 20
- Release for bcc 0.17.0 Support HOT 4
- Segfault for examples when running in docker apline:3.12 image HOT 6
- USDT probe support
- ptr::read on possible misaligned ptr HOT 1
- support for armhf (32 bit) HOT 1
- Can't probe netif_receive_skb HOT 3
- how about using template for replacing code in c file? HOT 3
- IP reads in reverse order in some examples HOT 2
- `Table::new()` should be private or unsafe HOT 1
- unresolved imports `bcc::trace_parse`, `bcc::trace_read` no `trace_parse` in the root HOT 1
- Infinite loops when iterating over BPF tables HOT 3
- support bcc 0.12.0 HOT 1
- Would it be okay to submit a partial implementation of tcpconnect.py ? HOT 8
- Support for pre-compiled .elf BPF binaries? HOT 3
- Possibility to support `get_syscall_fnname` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-bcc.