Skip to content

Commit

Permalink
asprof flamegraphs saved in tmp folder, duplicate jvm arg fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelui-amzn committed Jul 23, 2024
1 parent 820288a commit bff901d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 10 deletions.
83 changes: 81 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ inferno = "0.11.19"
indexmap = "2.1.0"
cfg-if = "1.0"
tempfile = "3"
serial_test = "3.1.1"
30 changes: 22 additions & 8 deletions src/data/java_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ impl JavaProfileRaw {
}

fn launch_asprof(&self, jids: Vec<String>, params: CollectorParams) -> Result<()> {
let data_dir = PathBuf::from(params.data_dir.clone());
for jid in &jids {
let mut html_loc = data_dir.clone();
html_loc.push(format!("{}-java-flamegraph-{}.html", params.run_name, jid));

match Command::new("asprof")
.args([
"-d",
&(params.collection_time - params.elapsed_time).to_string(),
"-f",
html_loc.to_str().unwrap(),
format!(
"/tmp/aperf_tmp/{}-java-flamegraph-{}.html",
params.run_name, jid
)
.as_str(),
jid.as_str(),
])
.spawn()
Expand Down Expand Up @@ -79,7 +79,7 @@ impl JavaProfileRaw {
fn get_jids(&mut self, arg: &str) -> Vec<String> {
let mut jids: Vec<String> = Vec::new();
for (key, value) in self.process_map.clone().into_iter() {
if arg == value[0] {
if arg == value[0] || arg == key {
jids.push(key);
}
}
Expand Down Expand Up @@ -163,12 +163,13 @@ impl CollectData for JavaProfileRaw {
error!("No JVM with name/PID '{}'.", arg);
continue;
}
jids = self.get_jids(arg);
jids.append(&mut self.get_jids(arg));
}
}
}
}

jids.sort();
jids.dedup();
self.launch_asprof(jids, params.clone())
}

Expand Down Expand Up @@ -211,6 +212,19 @@ impl CollectData for JavaProfileRaw {
}

let data_dir = PathBuf::from(params.data_dir.clone());
for key in self.process_map.keys() {
let mut html_path = data_dir.clone();
html_path.push(format!("{}-java-flamegraph-{}.html", params.run_name, key));

let html_loc = html_path.to_str().unwrap();
let tmp_loc = format!(
"/tmp/aperf_tmp/{}-java-flamegraph-{}.html",
params.run_name, key
);

fs::copy(tmp_loc.clone(), html_loc).ok();
}

let mut jps_map = File::create(
data_dir
.clone()
Expand Down
12 changes: 12 additions & 0 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use crate::{data, InitParams, PERFORMANCE_DATA};
use anyhow::Result;
use clap::Args;
use log::{debug, error, info};
use std::fs;
use std::os::unix::fs::PermissionsExt;

pub static APERF_TMP: &str = "/tmp/aperf_tmp";

#[derive(Args, Debug)]
pub struct Record {
Expand Down Expand Up @@ -82,12 +86,20 @@ pub fn record(record: &Record) -> Result<()> {
);
}

fs::remove_dir_all(APERF_TMP).ok();
fs::create_dir(APERF_TMP)?;
let mut perms: fs::Permissions = fs::metadata(APERF_TMP)?.permissions();
perms.set_mode(0o777);
fs::set_permissions(APERF_TMP, perms)?;

PERFORMANCE_DATA.lock().unwrap().set_params(params);
PERFORMANCE_DATA.lock().unwrap().init_collectors()?;
info!("Starting Data collection...");
prepare_data_collectors()?;
collect_static_data()?;
start_collection_serial()?;
info!("Data collection complete.");

fs::remove_dir_all(APERF_TMP)?;
Ok(())
}
3 changes: 3 additions & 0 deletions tests/test_aperf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use aperf_lib::record::{record, Record};
use aperf_lib::report::{report, Report};
use flate2::read::GzDecoder;
use serial_test::serial;
use std::path::{Path, PathBuf};
use std::{fs, panic};
use tar::Archive;
Expand All @@ -20,6 +21,7 @@ where
}

#[test]
#[serial]
fn test_record() {
run_test(|tempdir| {
let run_name = tempdir
Expand All @@ -46,6 +48,7 @@ fn test_record() {
}

#[test]
#[serial]
fn test_report() {
run_test(|tempdir| {
let run_name = tempdir
Expand Down

0 comments on commit bff901d

Please sign in to comment.