mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Always collect memory usage info in analysis-stats
This commit is contained in:
parent
d548146c30
commit
4c67becd44
4 changed files with 11 additions and 24 deletions
|
@ -10,13 +10,13 @@ pub struct StopWatch {
|
||||||
time: Instant,
|
time: Instant,
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
counter: Option<perf_event::Counter>,
|
counter: Option<perf_event::Counter>,
|
||||||
memory: Option<MemoryUsage>,
|
memory: MemoryUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StopWatchSpan {
|
pub struct StopWatchSpan {
|
||||||
pub time: Duration,
|
pub time: Duration,
|
||||||
pub instructions: Option<u64>,
|
pub instructions: Option<u64>,
|
||||||
pub memory: Option<MemoryUsage>,
|
pub memory: MemoryUsage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StopWatch {
|
impl StopWatch {
|
||||||
|
@ -45,20 +45,16 @@ impl StopWatch {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let memory = MemoryUsage::now();
|
||||||
let time = Instant::now();
|
let time = Instant::now();
|
||||||
StopWatch {
|
StopWatch {
|
||||||
time,
|
time,
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
counter,
|
counter,
|
||||||
memory: None,
|
memory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn memory(mut self, yes: bool) -> StopWatch {
|
|
||||||
if yes {
|
|
||||||
self.memory = Some(MemoryUsage::now());
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn elapsed(&mut self) -> StopWatchSpan {
|
pub fn elapsed(&mut self) -> StopWatchSpan {
|
||||||
let time = self.time.elapsed();
|
let time = self.time.elapsed();
|
||||||
|
|
||||||
|
@ -69,7 +65,7 @@ impl StopWatch {
|
||||||
#[cfg(not(target_os = "linux"))]
|
#[cfg(not(target_os = "linux"))]
|
||||||
let instructions = None;
|
let instructions = None;
|
||||||
|
|
||||||
let memory = self.memory.map(|it| MemoryUsage::now() - it);
|
let memory = MemoryUsage::now() - self.memory;
|
||||||
StopWatchSpan { time, instructions, memory }
|
StopWatchSpan { time, instructions, memory }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,9 +89,7 @@ impl fmt::Display for StopWatchSpan {
|
||||||
}
|
}
|
||||||
write!(f, ", {instructions}{prefix}instr")?;
|
write!(f, ", {instructions}{prefix}instr")?;
|
||||||
}
|
}
|
||||||
if let Some(memory) = self.memory {
|
write!(f, ", {}", self.memory)?;
|
||||||
write!(f, ", {memory}")?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,9 +235,7 @@ impl flags::AnalysisStats {
|
||||||
if let Some(instructions) = total_span.instructions {
|
if let Some(instructions) = total_span.instructions {
|
||||||
report_metric("total instructions", instructions, "#instr");
|
report_metric("total instructions", instructions, "#instr");
|
||||||
}
|
}
|
||||||
if let Some(memory) = total_span.memory {
|
report_metric("total memory", total_span.memory.allocated.megabytes() as u64, "MB");
|
||||||
report_metric("total memory", memory.allocated.megabytes() as u64, "MB");
|
|
||||||
}
|
|
||||||
|
|
||||||
if env::var("RA_COUNT").is_ok() {
|
if env::var("RA_COUNT").is_ok() {
|
||||||
eprintln!("{}", profile::countme::get_all());
|
eprintln!("{}", profile::countme::get_all());
|
||||||
|
@ -257,7 +255,7 @@ impl flags::AnalysisStats {
|
||||||
eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
|
eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.memory_usage && verbosity.is_verbose() {
|
if verbosity.is_verbose() {
|
||||||
print_memory_usage(host, vfs);
|
print_memory_usage(host, vfs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,7 +812,7 @@ impl flags::AnalysisStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop_watch(&self) -> StopWatch {
|
fn stop_watch(&self) -> StopWatch {
|
||||||
StopWatch::start().memory(self.memory_usage)
|
StopWatch::start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,6 @@ xflags::xflags! {
|
||||||
optional --randomize
|
optional --randomize
|
||||||
/// Run type inference in parallel.
|
/// Run type inference in parallel.
|
||||||
optional --parallel
|
optional --parallel
|
||||||
/// Collect memory usage statistics.
|
|
||||||
optional --memory-usage
|
|
||||||
/// Print the total length of all source and macro files (whitespace is not counted).
|
/// Print the total length of all source and macro files (whitespace is not counted).
|
||||||
optional --source-stats
|
optional --source-stats
|
||||||
|
|
||||||
|
@ -191,7 +189,6 @@ pub struct AnalysisStats {
|
||||||
pub output: Option<OutputFormat>,
|
pub output: Option<OutputFormat>,
|
||||||
pub randomize: bool,
|
pub randomize: bool,
|
||||||
pub parallel: bool,
|
pub parallel: bool,
|
||||||
pub memory_usage: bool,
|
|
||||||
pub source_stats: bool,
|
pub source_stats: bool,
|
||||||
pub only: Option<String>,
|
pub only: Option<String>,
|
||||||
pub with_deps: bool,
|
pub with_deps: bool,
|
||||||
|
|
|
@ -103,9 +103,7 @@ impl Metrics {
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
eprintln!("\nMeasuring analysis-stats/{name}");
|
eprintln!("\nMeasuring analysis-stats/{name}");
|
||||||
let output =
|
let output = cmd!(sh, "./target/release/rust-analyzer -q analysis-stats {path}").read()?;
|
||||||
cmd!(sh, "./target/release/rust-analyzer -q analysis-stats --memory-usage {path}")
|
|
||||||
.read()?;
|
|
||||||
for (metric, value, unit) in parse_metrics(&output) {
|
for (metric, value, unit) in parse_metrics(&output) {
|
||||||
self.report(&format!("analysis-stats/{name}/{metric}"), value, unit.into());
|
self.report(&format!("analysis-stats/{name}/{metric}"), value, unit.into());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue