Open Fomalhauthmj opened 1 year ago
I guess it's simply because this program runs too fast, and no sample has been caught...
fn main() {
let guard = pprof::ProfilerGuardBuilder::default()
.frequency(1000)
.blocklist(&["libc", "libgcc", "pthread", "vdso"])
.build()
.unwrap();
let mut sum = 0;
for i in 1..1_000_000_000 {
for j in 1..i {
for k in 1..10 {
sum += i*j*k;
}
}
}
println!("{:?}", sum);
if let Ok(report) = guard.report().build() {
println!("report: {:?}", &report);
let file = std::fs::File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
}
}
Will give you one backtrace through cargo run --release
(all sample hits main
, so there is only a single backtrace). This example has to run with --release
, or it will panic because plus overflow.
Thx, I have solved this problem.
By the way,what's the background of frequency in the builder?
Because my real workload take time nearly 3ms(walltime), so l set frequency to 1000.However it's output is the same with above example,which made me confused.
I check the source code of pprof
:
impl Timer {
pub fn new(frequency: c_int) -> Timer {
let interval = 1e6 as i64 / i64::from(frequency);
let it_interval = Timeval {
tv_sec: interval / 1e6 as i64,
tv_usec: interval % 1e6 as i64,
};
......
}
It looks like that frequency should less than 1e6.
Not sure if this is the case but it could be related to issue #177
I found following test code can't collect any data during execution, and the flamegraph is blank.
cargo run
's output:My test environment: