| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e0b35a1 commit 0a75682
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -479,6 +479,7 @@ impl CliRunner { | |||
| 479 | 479 | .with_silent(misc_options.silent) | |
| 480 | 480 | .with_fix_kind(fix_options.fix_kind()) | |
| 481 | 481 | .with_type_check_only(type_check_only) | |
| 482 | + .with_timings(debug_timings) | ||
| 482 | 483 | .build() | |
| 483 | 484 | { | |
| 484 | 485 | Ok(runner) => runner, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -495,9 +495,16 @@ impl Linter { | |||
| 495 | 495 | ||
| 496 | 496 | let result = (diagnostics, disable_directives); | |
| 497 | 497 | if TIMINGS { | |
| 498 | - rule_timing_store | ||
| 499 | - .expect("missing rule timing store") | ||
| 500 | - .merge(timing_recorder.expect("missing rule timing recorder")); | ||
| 498 | + let timing_recorder = timing_recorder.expect("missing rule timing recorder"); | ||
| 499 | + rule_timing_store.expect("missing rule timing store").merge( | ||
| 500 | + timing_recorder.into_timings().into_iter().map(|(key, stat)| RuleTimingRecord { | ||
| 501 | + source: key.source, | ||
| 502 | + plugin_name: key.plugin_name.into_owned(), | ||
| 503 | + rule_name: key.rule_name.into_owned(), | ||
| 504 | + duration: stat.duration, | ||
| 505 | + calls: stat.calls, | ||
| 506 | + }), | ||
| 507 | + ); | ||
| 501 | 508 | } | |
| 502 | 509 | result | |
| 503 | 510 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -144,6 +144,7 @@ pub struct LintRunnerBuilder { | |||
| 144 | 144 | silent: bool, | |
| 145 | 145 | fix_kind: FixKind, | |
| 146 | 146 | type_check_only: bool, | |
| 147 | + timings: bool, | ||
| 147 | 148 | } | |
| 148 | 149 | ||
| 149 | 150 | impl LintRunnerBuilder { | |
@@ -156,6 +157,7 @@ impl LintRunnerBuilder { | |||
| 156 | 157 | silent: false, | |
| 157 | 158 | fix_kind: FixKind::None, | |
| 158 | 159 | type_check_only: false, | |
| 160 | + timings: false, | ||
| 159 | 161 | } | |
| 160 | 162 | } | |
| 161 | 163 | ||
@@ -189,6 +191,12 @@ impl LintRunnerBuilder { | |||
| 189 | 191 | self | |
| 190 | 192 | } | |
| 191 | 193 | ||
| 194 | + #[must_use] | ||
| 195 | + pub fn with_timings(mut self, timings: bool) -> Self { | ||
| 196 | + self.timings = timings; | ||
| 197 | + self | ||
| 198 | + } | ||
| 199 | + | ||
| 192 | 200 | /// # Errors | |
| 193 | 201 | /// Returns an error if the type-aware linter fails to initialize. | |
| 194 | 202 | pub fn build(self) -> Result<LintRunner, String> { | |
@@ -200,7 +208,12 @@ impl LintRunnerBuilder { | |||
| 200 | 208 | self.regular_linter.config.clone(), | |
| 201 | 209 | self.fix_kind, | |
| 202 | 210 | ) { | |
| 203 | - Ok(state) => Some(state.with_silent(self.silent).with_type_check(self.type_check)), | ||
| 211 | + Ok(state) => Some( | ||
| 212 | + state | ||
| 213 | + .with_silent(self.silent) | ||
| 214 | + .with_type_check(self.type_check) | ||
| 215 | + .with_timings(self.timings), | ||
| 216 | + ), | ||
| 204 | 217 | Err(e) => return Err(e), | |
| 205 | 218 | } | |
| 206 | 219 | } else { | |
@@ -258,6 +271,7 @@ impl LintRunner { | |||
| 258 | 271 | tx_error, | |
| 259 | 272 | fs, | |
| 260 | 273 | diff_manager, | |
| 274 | + rule_timing_store, | ||
| 261 | 275 | )?; | |
| 262 | 276 | } else { | |
| 263 | 277 | drop(tx_error); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,10 +24,10 @@ impl RuleTimingSource { | |||
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | |
| 27 | - struct RuleTimingKey { | ||
| 28 | - source: RuleTimingSource, | ||
| 29 | - plugin_name: Cow<'static, str>, | ||
| 30 | - rule_name: Cow<'static, str>, | ||
| 27 | + pub struct RuleTimingKey { | ||
| 28 | + pub source: RuleTimingSource, | ||
| 29 | + pub plugin_name: Cow<'static, str>, | ||
| 30 | + pub rule_name: Cow<'static, str>, | ||
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | 33 | impl RuleTimingKey { | |
@@ -38,6 +38,17 @@ impl RuleTimingKey { | |||
| 38 | 38 | rule_name: Cow::Borrowed(rule_name), | |
| 39 | 39 | } | |
| 40 | 40 | } | |
| 41 | + | ||
| 42 | + fn from_record(record: RuleTimingRecord) -> (Self, RuleTimingStat) { | ||
| 43 | + ( | ||
| 44 | + Self { | ||
| 45 | + source: record.source, | ||
| 46 | + plugin_name: Cow::Owned(record.plugin_name), | ||
| 47 | + rule_name: Cow::Owned(record.rule_name), | ||
| 48 | + }, | ||
| 49 | + RuleTimingStat { duration: record.duration, calls: record.calls }, | ||
| 50 | + ) | ||
| 51 | + } | ||
| 41 | 52 | } | |
| 42 | 53 | ||
| 43 | 54 | #[derive(Debug, Clone, Copy, Default)] | |
@@ -97,7 +108,7 @@ impl RuleTimingRecorder { | |||
| 97 | 108 | self.timings.entry(RuleTimingKey::native(plugin_name, rule_name)).or_default().add(stat); | |
| 98 | 109 | } | |
| 99 | 110 | ||
| 100 | - fn into_timings(self) -> FxHashMap<RuleTimingKey, RuleTimingStat> { | ||
| 111 | + pub(crate) fn into_timings(self) -> FxHashMap<RuleTimingKey, RuleTimingStat> { | ||
| 101 | 112 | self.timings | |
| 102 | 113 | } | |
| 103 | 114 | } | |
@@ -112,15 +123,19 @@ impl RuleTimingStore { | |||
| 112 | 123 | Self::default() | |
| 113 | 124 | } | |
| 114 | 125 | ||
| 115 | - pub(crate) fn merge(&self, recorder: RuleTimingRecorder) { | ||
| 116 | - let local_timings = recorder.into_timings(); | ||
| 117 | - if local_timings.is_empty() { | ||
| 126 | + pub(crate) fn merge<I>(&self, local_timings: I) | ||
| 127 | + where | ||
| 128 | + I: IntoIterator<Item = RuleTimingRecord>, | ||
| 129 | + { | ||
| 130 | + let mut local_timings = local_timings.into_iter().peekable(); | ||
| 131 | + if local_timings.peek().is_none() { | ||
| 118 | 132 | return; | |
| 119 | 133 | } | |
| 120 | 134 | ||
| 121 | 135 | let mut timings = self.timings.lock().expect("rule timing store mutex poisoned"); | |
| 122 | - timings.reserve(local_timings.len()); | ||
| 123 | - for (key, stat) in local_timings { | ||
| 136 | + timings.reserve(local_timings.size_hint().0); | ||
| 137 | + for record in local_timings { | ||
| 138 | + let (key, stat) = RuleTimingKey::from_record(record); | ||
| 124 | 139 | timings.entry(key).or_default().add(stat); | |
| 125 | 140 | } | |
| 126 | 141 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments