Skip to content
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

Migrate to newer dependencies #109

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,466 changes: 1,008 additions & 1,458 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
[workspace]
members = ["common", "lz4-compress", "jemallocator/jemalloc-sys", "preload", "cli-core", "cli", "server-core", "gather", "integration-tests", "mimalloc_rust", "fast_range_map"]
members = [
"common",
"lz4-compress",
"jemallocator/jemalloc-sys",
"preload",
"cli-core",
"cli",
"server-core",
"gather",
"integration-tests",
"mimalloc_rust",
"fast_range_map",
]
resolver = "2"

[profile.dev]
opt-level = 2
opt-level = 0
incremental = true
debug = true

[profile.release]
opt-level = 3
Expand Down
14 changes: 7 additions & 7 deletions cli-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ edition = "2018"
smallvec = "1"
byteorder = "1"
ctrlc = "3"
goblin = "0.0.24"
goblin = "0.6.1"
string-interner = { version = "0.7", default-features = false }
cpp_demangle = "0.2"
cpp_demangle = "0.4"
chrono = "0.4"
libc = "0.2"
log = "0.4"
lru = "0.6"
bitflags = "1"
inferno = { version = "0.9", default-features = false }
lru = "0.10"
bitflags = "2"
inferno = { version = "0.11", default-features = false }
lazy_static = "1"
ahash = "0.7"
ahash = "0.8"
parking_lot = "0.12"
crossbeam-channel = "0.5"
rayon = "1"
regex = "1"
rhai = { version = "1", features = ["unchecked"] }
plotters = { version = "0.3", default-features = false, features = ["svg_backend", "all_series"] }
colorgrad = "0.4"
colorgrad = "0.6"
serde_json = "1"
derive_more = "0.99"

Expand Down
95 changes: 50 additions & 45 deletions cli-core/src/cmd_analyze_size.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::io::{self, Read};
use crate::reader::parse_events;
use ahash::AHashMap as HashMap;
use common::event::Event;
use common::Timestamp;
use crate::reader::parse_events;
use std::io::{self, Read};

fn format_count( count: usize ) -> String {
fn format_count(count: usize) -> String {
if count < 1000 {
format!( "{}", count )
format!("{}", count)
} else if count < 1000 * 1000 {
format!( "{}K", count / 1000 )
format!("{}K", count / 1000)
} else {
format!( "{}M", count / (1000 * 1000) )
format!("{}M", count / (1000 * 1000))
}
}

pub fn analyze_size( fp: impl Read + Send + 'static ) -> Result< (), io::Error > {
let (_, event_stream) = parse_events( fp )?;
pub fn analyze_size(fp: impl Read + Send + 'static) -> Result<(), io::Error> {
let (_, event_stream) = parse_events(fp)?;

const S_OTHER: usize = 0;
const S_ALLOC: usize = 1;
Expand Down Expand Up @@ -43,16 +43,16 @@ pub fn analyze_size( fp: impl Read + Send + 'static ) -> Result< (), io::Error >
#[derive(Default)]
struct Stats {
size: usize,
count: usize
count: usize,
}

let mut stats = Vec::new();
stats.resize_with( S_MAX, Stats::default );
stats.resize_with(S_MAX, Stats::default);

let mut allocation_buckets = Vec::new();
allocation_buckets.resize( 10, 0 );
allocation_buckets.resize(10, 0);

fn elapsed_to_bucket( elapsed: Timestamp ) -> usize {
fn elapsed_to_bucket(elapsed: Timestamp) -> usize {
let s = elapsed.as_secs();
if s < 1 {
0
Expand All @@ -78,56 +78,61 @@ pub fn analyze_size( fp: impl Read + Send + 'static ) -> Result< (), io::Error >
let mut allocations = HashMap::new();
for event in event_stream {
let event = match event {
Ok( event ) => event,
Err( _ ) => break
Ok(event) => event,
Err(_) => break,
};

let size = common::speedy::Writable::< common::speedy::LittleEndian >::bytes_needed( &event ).unwrap();
let size =
common::speedy::Writable::<common::speedy::LittleEndian>::bytes_needed(&event).unwrap();
let kind = match event {
| Event::Alloc { .. } => S_ALLOC,
| Event::AllocEx { id, timestamp, .. } => {
allocations.insert( id, timestamp );
Event::Alloc { .. } => S_ALLOC,
Event::AllocEx { id, timestamp, .. } => {
allocations.insert(id, timestamp);
S_ALLOC
},
| Event::Realloc { .. }
| Event::ReallocEx { .. } => S_REALLOC,
| Event::Free { .. } => S_FREE,
| Event::FreeEx { id, timestamp, .. } => {
if let Some( allocated_timestamp ) = allocations.remove( &id ) {
}
Event::Realloc { .. } | Event::ReallocEx { .. } => S_REALLOC,
Event::Free { .. } => S_FREE,
Event::FreeEx { id, timestamp, .. } => {
if let Some(allocated_timestamp) = allocations.remove(&id) {
let elapsed = timestamp - allocated_timestamp;
allocation_buckets[ elapsed_to_bucket( elapsed ) ] += 1;
allocation_buckets[elapsed_to_bucket(elapsed)] += 1;
}
S_FREE
},
| Event::Backtrace { .. }
}
Event::Backtrace { .. }
| Event::PartialBacktrace { .. }
| Event::PartialBacktrace32 { .. }
| Event::Backtrace32 { .. } => S_BACKTRACE,
| Event::File { .. } => S_FILE,
| Event::File64 { .. } => S_FILE,
| Event::GroupStatistics { .. } => S_STATS,
| Event::AddRegion { .. }
| Event::RemoveRegion { .. }
| Event::MemoryMapEx { .. } => S_MAPS,
| Event::UpdateRegionUsage { .. } => S_MAPS_USAGE,
_ => S_OTHER
Event::File { .. } => S_FILE,
Event::File64 { .. } => S_FILE,
Event::GroupStatistics { .. } => S_STATS,
Event::AddRegion { .. } | Event::RemoveRegion { .. } | Event::MemoryMapEx { .. } => {
S_MAPS
}
Event::UpdateRegionUsage { .. } => S_MAPS_USAGE,
_ => S_OTHER,
};

stats[ kind ].size += size;
stats[ kind ].count += 1;
stats[kind].size += size;
stats[kind].count += 1;
}

*allocation_buckets.last_mut().unwrap() += allocations.len();

let mut stats: Vec< _ > = stats.into_iter().enumerate().collect();
stats.sort_by_key( |(_, stats)| !stats.size );
let mut stats: Vec<_> = stats.into_iter().enumerate().collect();
stats.sort_by_key(|(_, stats)| !stats.size);

println!( "Total event sizes:" );
println!("Total event sizes:");
for (index, stats) in stats {
println!( " {}: {}MB ({} events)", SIZE_TO_NAME[ index ], stats.size / (1024 * 1024), format_count( stats.count ) );
println!(
" {}: {}MB ({} events)",
SIZE_TO_NAME[index],
stats.size / (1024 * 1024),
format_count(stats.count)
);
}

println!( "\nAllocation lifetime buckets:" );
println!("\nAllocation lifetime buckets:");
for (index, count) in allocation_buckets.into_iter().enumerate() {
let label = match index {
0 => "< 1s",
Expand All @@ -140,11 +145,11 @@ pub fn analyze_size( fp: impl Read + Send + 'static ) -> Result< (), io::Error >
7 => "< 1h",
8 => ">= 1h",
9 => "Leaked",
_ => unreachable!()
_ => unreachable!(),
};

println!( " {}: {}", label, format_count( count ) );
println!(" {}: {}", label, format_count(count));
}

Ok(())
}
}
60 changes: 30 additions & 30 deletions cli-core/src/cmd_extract.rs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
use std::path::PathBuf;
use std::fs::File;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use common::event::Event;
use crate::reader::parse_events;
use common::event::Event;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fs::File;
use std::path::PathBuf;

pub fn extract( input: PathBuf, output: PathBuf ) -> Result< (), std::io::Error > {
info!( "Opening {:?}...", input );
let fp = File::open( input )?;
let (_, event_stream) = parse_events( fp )?;
pub fn extract(input: PathBuf, output: PathBuf) -> Result<(), std::io::Error> {
info!("Opening {:?}...", input);
let fp = File::open(input)?;
let (_, event_stream) = parse_events(fp)?;

info!( "Creating {:?} if it doesn't exist...", output );
std::fs::create_dir_all( &output )?;
info!("Creating {:?} if it doesn't exist...", output);
std::fs::create_dir_all(&output)?;

let mut counter = HashMap::new();
for event in event_stream {
let event = match event {
Ok( event ) => event,
Err( _ ) => break
Ok(event) => event,
Err(_) => break,
};

match event {
Event::File { path, contents, .. } | Event::File64 { path, contents, .. } => {
let mut relative_path = &*path;
if relative_path.starts_with( "/" ) {
relative_path = &relative_path[ 1.. ];
if relative_path.starts_with("/") {
relative_path = &relative_path[1..];
}

let mut target_path = output.join( relative_path );
let mut target_path = output.join(relative_path);

info!( "Extracting {:?} into {:?}...", path, target_path );
if let Some( parent ) = target_path.parent() {
std::fs::create_dir_all( parent )?;
info!("Extracting {:?} into {:?}...", path, target_path);
if let Some(parent) = target_path.parent() {
std::fs::create_dir_all(parent)?;
}

match counter.entry( target_path.clone() ) {
Entry::Vacant( bucket ) => {
bucket.insert( 0 );
},
Entry::Occupied( mut bucket ) => {
match counter.entry(target_path.clone()) {
Entry::Vacant(bucket) => {
bucket.insert(0);
}
Entry::Occupied(mut bucket) => {
let parent = target_path.parent().unwrap();
let mut filename = target_path.file_name().unwrap().to_os_string();

if *bucket.get() == 0 {
let mut filename = filename.clone();
filename.push( ".000" );
std::fs::rename( &target_path, parent.join( filename ) )?;
filename.push(".000");
std::fs::rename(&target_path, parent.join(filename))?;
}

filename.push( format!( ".{:03}", bucket.get() ) );
target_path = parent.join( filename );
filename.push(format!(".{:03}", bucket.get()));
target_path = parent.join(filename);

*bucket.get_mut() += 1;
}
}

std::fs::write( target_path, contents )?;
},
std::fs::write(target_path, contents)?;
}
_ => {}
}
}
Expand Down
Loading