Skip to content

Commit 54c4125

Browse files
committed
Auto merge of rust-lang#15461 - lnicola:analysis-stats-memory, r=Veykril
internal: Always collect memory usage info in analysis-stats
2 parents d548146 + 4c67bec commit 54c4125

File tree

4 files changed

+11
-24
lines changed

4 files changed

+11
-24
lines changed

crates/profile/src/stop_watch.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ pub struct StopWatch {
1010
time: Instant,
1111
#[cfg(target_os = "linux")]
1212
counter: Option<perf_event::Counter>,
13-
memory: Option<MemoryUsage>,
13+
memory: MemoryUsage,
1414
}
1515

1616
pub struct StopWatchSpan {
1717
pub time: Duration,
1818
pub instructions: Option<u64>,
19-
pub memory: Option<MemoryUsage>,
19+
pub memory: MemoryUsage,
2020
}
2121

2222
impl StopWatch {
@@ -45,20 +45,16 @@ impl StopWatch {
4545
None
4646
}
4747
};
48+
let memory = MemoryUsage::now();
4849
let time = Instant::now();
4950
StopWatch {
5051
time,
5152
#[cfg(target_os = "linux")]
5253
counter,
53-
memory: None,
54+
memory,
5455
}
5556
}
56-
pub fn memory(mut self, yes: bool) -> StopWatch {
57-
if yes {
58-
self.memory = Some(MemoryUsage::now());
59-
}
60-
self
61-
}
57+
6258
pub fn elapsed(&mut self) -> StopWatchSpan {
6359
let time = self.time.elapsed();
6460

@@ -69,7 +65,7 @@ impl StopWatch {
6965
#[cfg(not(target_os = "linux"))]
7066
let instructions = None;
7167

72-
let memory = self.memory.map(|it| MemoryUsage::now() - it);
68+
let memory = MemoryUsage::now() - self.memory;
7369
StopWatchSpan { time, instructions, memory }
7470
}
7571
}
@@ -93,9 +89,7 @@ impl fmt::Display for StopWatchSpan {
9389
}
9490
write!(f, ", {instructions}{prefix}instr")?;
9591
}
96-
if let Some(memory) = self.memory {
97-
write!(f, ", {memory}")?;
98-
}
92+
write!(f, ", {}", self.memory)?;
9993
Ok(())
10094
}
10195
}

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ impl flags::AnalysisStats {
235235
if let Some(instructions) = total_span.instructions {
236236
report_metric("total instructions", instructions, "#instr");
237237
}
238-
if let Some(memory) = total_span.memory {
239-
report_metric("total memory", memory.allocated.megabytes() as u64, "MB");
240-
}
238+
report_metric("total memory", total_span.memory.allocated.megabytes() as u64, "MB");
241239

242240
if env::var("RA_COUNT").is_ok() {
243241
eprintln!("{}", profile::countme::get_all());
@@ -257,7 +255,7 @@ impl flags::AnalysisStats {
257255
eprintln!("source files: {total_file_size}, macro files: {total_macro_file_size}");
258256
}
259257

260-
if self.memory_usage && verbosity.is_verbose() {
258+
if verbosity.is_verbose() {
261259
print_memory_usage(host, vfs);
262260
}
263261

@@ -814,7 +812,7 @@ impl flags::AnalysisStats {
814812
}
815813

816814
fn stop_watch(&self) -> StopWatch {
817-
StopWatch::start().memory(self.memory_usage)
815+
StopWatch::start()
818816
}
819817
}
820818

crates/rust-analyzer/src/cli/flags.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ xflags::xflags! {
6262
optional --randomize
6363
/// Run type inference in parallel.
6464
optional --parallel
65-
/// Collect memory usage statistics.
66-
optional --memory-usage
6765
/// Print the total length of all source and macro files (whitespace is not counted).
6866
optional --source-stats
6967

@@ -191,7 +189,6 @@ pub struct AnalysisStats {
191189
pub output: Option<OutputFormat>,
192190
pub randomize: bool,
193191
pub parallel: bool,
194-
pub memory_usage: bool,
195192
pub source_stats: bool,
196193
pub only: Option<String>,
197194
pub with_deps: bool,

xtask/src/metrics.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ impl Metrics {
103103
path: &str,
104104
) -> anyhow::Result<()> {
105105
eprintln!("\nMeasuring analysis-stats/{name}");
106-
let output =
107-
cmd!(sh, "./target/release/rust-analyzer -q analysis-stats --memory-usage {path}")
108-
.read()?;
106+
let output = cmd!(sh, "./target/release/rust-analyzer -q analysis-stats {path}").read()?;
109107
for (metric, value, unit) in parse_metrics(&output) {
110108
self.report(&format!("analysis-stats/{name}/{metric}"), value, unit.into());
111109
}

0 commit comments

Comments
 (0)