-
Notifications
You must be signed in to change notification settings - Fork 3
ci: use async-profiler from upstream, fix integration test errors #86
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,14 @@ enum Commands { | |
#[arg(long, default_value = "5")] | ||
stack_depth: usize, | ||
}, | ||
/// Print the total duration (in seconds) of the JFR recording. Used in the integration tests. | ||
Duration { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we made this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is intended for use by a very specific shell script |
||
/// JFR file to read from | ||
jfr_file: OsString, | ||
/// If true, unzip first | ||
#[arg(long)] | ||
zip: bool, | ||
}, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
|
@@ -78,6 +86,24 @@ fn extract_async_profiler_jfr_from_zip(file: File) -> anyhow::Result<Option<Vec< | |
Ok(None) | ||
} | ||
|
||
// doing this as a macro because functions are not higher-order enough | ||
// extract events from $jfr_file, $zip decides if it's a zip, then run $f($FILE, input) | ||
macro_rules! extract_events_from_path { | ||
($jfr_file:expr, $zip:expr, $f:expr, $input:expr) => {{ | ||
let mut jfr_file = std::fs::File::open($jfr_file)?; | ||
match $zip { | ||
false => $f(&mut jfr_file, $input), | ||
true => { | ||
if let Some(data) = extract_async_profiler_jfr_from_zip(jfr_file)? { | ||
$f(&mut Cursor::new(&data), $input) | ||
} else { | ||
anyhow::bail!("no async_profiler_dump_0.jfr file found"); | ||
} | ||
} | ||
} | ||
}}; | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
let cli = Cli::parse(); | ||
tracing_subscriber::fmt::init(); | ||
|
@@ -89,21 +115,11 @@ fn main() -> anyhow::Result<()> { | |
zip, | ||
include_non_pollcatch, | ||
} => { | ||
let mut jfr_file = std::fs::File::open(jfr_file)?; | ||
let config = LongPollConfig { | ||
min_length, | ||
include_non_pollcatch, | ||
}; | ||
let samples = match zip { | ||
false => jfr_samples(&mut jfr_file, &config)?, | ||
true => { | ||
if let Some(data) = extract_async_profiler_jfr_from_zip(jfr_file)? { | ||
jfr_samples(&mut Cursor::new(&data), &config)? | ||
} else { | ||
anyhow::bail!("no async_profiler_dump_0.jfr file found"); | ||
} | ||
} | ||
}; | ||
let samples = extract_events_from_path!(jfr_file, zip, jfr_samples, &config)?; | ||
print_samples(&mut io::stdout(), samples, stack_depth).ok(); | ||
Ok(()) | ||
} | ||
|
@@ -113,20 +129,15 @@ fn main() -> anyhow::Result<()> { | |
zip, | ||
stack_depth, | ||
} => { | ||
let mut jfr_file = std::fs::File::open(jfr_file)?; | ||
let events = match zip { | ||
false => jfr_native_mem_events(&mut jfr_file, &type_)?, | ||
true => { | ||
if let Some(data) = extract_async_profiler_jfr_from_zip(jfr_file)? { | ||
jfr_native_mem_events(&mut Cursor::new(&data), &type_)? | ||
} else { | ||
anyhow::bail!("no async_profiler_dump_0.jfr file found"); | ||
} | ||
} | ||
}; | ||
let events = extract_events_from_path!(jfr_file, zip, jfr_native_mem_events, &type_)?; | ||
print_native_mem_events(&mut io::stdout(), events, &type_, stack_depth).ok(); | ||
Ok(()) | ||
} | ||
Commands::Duration { jfr_file, zip } => { | ||
let duration = extract_events_from_path!(jfr_file, zip, jfr_duration, ())?; | ||
println!("{}", duration.as_secs_f64()); | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -659,6 +670,19 @@ where | |
Ok(samples) | ||
} | ||
|
||
fn jfr_duration<T>(reader: &mut T, _config: ()) -> anyhow::Result<Duration> | ||
where | ||
T: Read + Seek, | ||
{ | ||
let mut jfr_reader = JfrReader::new(reader); | ||
|
||
let total_nanos = jfr_reader | ||
.chunks() | ||
.map(|i| i.map(|i| i.1.header.duration_nanos)) | ||
.sum::<Result<i64, _>>()?; | ||
Ok(Duration::from_nanos(total_nanos as u64)) | ||
} | ||
|
||
#[derive(Debug)] | ||
struct NativeMemEvent { | ||
start_time: Duration, | ||
|
@@ -934,6 +958,9 @@ mod test { | |
} | ||
print_samples(&mut to, samples, 4).unwrap(); | ||
assert_eq!(String::from_utf8(to).unwrap(), result); | ||
|
||
let duration = crate::jfr_duration(&mut io::Cursor::new(jfr), ()).unwrap(); | ||
assert_eq!(duration.as_nanos(), 15003104000); | ||
} | ||
|
||
#[test] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need some kind of recurring task to keep this up to date? Or is there a way to get the URL for the latest release? Alternatively I guess we could vend this version somehow?
I just want to avoid the case where we're testing on a different version than our customers are using, especially since pollcatch is using those unstable APIs