-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a Rust example for measuring latency #158
Comments
It appears that if your progress points or scopes are not triggered enough times, then coz won't necessarily catch them. I'm still just trying out coz and figuring it out, but it seems like coz runs your program and picks lines to slow down ( and speed up ? ) and measure the impact that changing that line has on performance. If, in the course of running your program, it doesn't run into any of your progress/latency points while it is tweaking the speed of different lines throughout your codebase, it won't have any data to go off of. In the example you've provided, scope A and scope B will only be entered and exited once when each thread is started/exited. That means it coz can't collect any samples of how speeding up/slowing down lines in the program will effect how often scope A and scope B are entered and exited. No matter what coz tweaks, it will have no effect on how often/how long it takes scope A or scope B to finish. This example works: const A: usize = 2_000_000_000;
const B: usize = (A as f64 * 1.2) as usize;
fn main() {
coz::thread_init();
let a = std::thread::spawn(move || {
coz::thread_init();
let mut counter = 0;
for i in 0..A {
coz::scope!("A");
counter += i;
}
});
let b = std::thread::spawn(move || {
coz::thread_init();
let mut counter = 0;
for i in 0..B {
coz::scope!("B");
counter += i;
}
});
a.join().unwrap();
b.join().unwrap();
} By sticking the scope inside the scope of the operation we're measuring we can measure how long it takes to do I tested this with your JPEG decoder and I got it to work by running According to this report, Here's the modified code: use coz;
use jpeg_decoder as jpeg;
use std::env;
use std::fs::File;
use std::io::{self, BufReader, Read, Write};
fn usage() -> ! {
write!(io::stderr(), "usage: jpeg-coz image.jpg").unwrap();
std::process::exit(1)
}
fn main() {
coz::thread_init();
let mut args = env::args().skip(1);
let input_path = args.next().unwrap_or_else(|| usage());
let mut input_file = File::open(input_path).expect("The specified input file could not be opened");
let mut bytes: Vec<u8> = vec![];
input_file.read_to_end(&mut bytes);
// Decode the image 100,000 times to give `coz` some time to analyze the effect of changes
for _ in 0..100_000 {
let mut decoder = jpeg::Decoder::new(bytes.as_slice());
coz::begin!("decode");
let data = decoder.decode().expect("Decoding failed. If other software can successfully decode the specified JPEG image, then it's likely that there is a bug in jpeg-decoder");
coz::end!("decode");
}
} I'm still kind of having the same issue where I get empty reports for my program, but testing out your example helped me to get a better idea of how this works. Maybe now I'll be able to fix mine. 😄 Coz seems pretty cool. I can't wait to see if it actually helps me find a place to optimize my program and get some extra performance! |
OK, so I just realized that I'm supposed to restrict the source files that coz experiments with to my own source files so that the results are actually useful to me as a developer!
So @Shnatsel, when profiling your jpeg-decoder now, I get much more useful stats, showing where in your code there might be potential for optimizations: Profile.coz:
|
I am also getting empty profile files no matter what I do. My steps:
Resulting file contains only two lines:
I tried replacing toy.rs with version provided by @zicklag above, but results are the same. After each run only more startup and runtime lines get added, no data points. Am I doing something wrong? Are the examples just out of date? I'm running Linux Mint 20. |
Same here. Even when I run coz with the -s parameter I still end up with a two-lines profile.coz file. Any help will be appreciated. Edit: turns out that it works after replacing debug=true by debug=1 in the profile.release section of Cargo.toml. |
I'm able to reproduce the toy example (for throughput profiling) but when I'm trying to do simple latency profiling using
my code is structurally similar to the single-thread example for the jpeg decoder by @zicklag in #158 (comment). I'm not sure where it got stuck in, sadly |
I'm not sure, but sounds like problem that can be solved usin method from this PR: #191 Can you try to compile and run with |
The naive adaptation of the provided Rust sample to measure latency instead of throughput produces a completely empty page when plotted:
Please provide an example that shows correct use of coz for latency measurement in Rust.
FWIW I am struggling with this exact issue on a larger project as well: https://github.com/Shnatsel/jpeg-decoder/tree/coz
The text was updated successfully, but these errors were encountered: